-
Notifications
You must be signed in to change notification settings - Fork 20
180 lines (158 loc) · 5.86 KB
/
build.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: "Build and deploy"
on:
workflow_dispatch:
inputs:
directory:
description: 'Directory reference'
required: true
default: 'main'
orig_pr:
description: 'Originating PR'
pull_request:
push:
branches:
- main
schedule:
- cron: "45 */12 * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.inputs.directory }}
cancel-in-progress: true
env:
hugobd: public
jobs:
build:
name: Build site
runs-on: ubuntu-22.04
env:
RENV_PROFILE: "dev"
RENV_CONFIG_SANDBOX_ENABLED: FALSE
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set env parameters
run: |
echo "issue=${{ github.event.inputs.orig_pr || github.event.pull_request.number }}" >> $GITHUB_ENV
repo_name=${{ github.event.inputs.orig_pr && 'rladies/directory' || github.repository }}
echo "repo_name=$(basename ${repo_name})" >> $GITHUB_ENV
ver=$(cat .Rprofile | grep hugo.version | cut -d"=" -f2 | sed -e s.\"..g | sed -e s.\ ..g | sed -e s.,..g)
echo "hugovr=$ver" >> $GITHUB_ENV
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "directory=${{ github.event.inputs.directory }}" >> $GITHUB_ENV
echo "netalias=${{ github.event.inputs.directory }}" >> $GITHUB_ENV
echo "token=${{ secrets.GLOBAL_GHA_PAT }}" >> $GITHUB_ENV
else
echo "directory=main" >> $GITHUB_ENV
echo "netalias=${{ github.event.number }}" >> $GITHUB_ENV
echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
fi
- name: Install cURL Headers
run: |
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: '4.3.0'
- name: Populate untranslated pages
run: |
rm .Rprofile # avoid starting renv
Rscript scripts/missing_translations.R
- name: Site data - Clean folders
run: rm -r data/directory data/rblogs
- name: Site data - DIRECTORY - Get
uses: actions/checkout@v3
if: "${{ env.directory == 'main' }}"
with:
repository: rladies/directory
ssh-key: ${{ secrets.ssh_directoryy_repo }}
path: tmpd/dir
- name: Site data - DIRECTORY - Download artifact
uses: dawidd6/action-download-artifact@v2
if: "${{ env.directory != 'main' }}"
with:
name: entries
# Required, if the repo is private a Personal Access Token with
# `repo` scope is needed or GitHub token in a job
# where the permissions `action` scope set to `read`
github_token: ${{ secrets.GLOBAL_GHA_PAT }}
# Optional, will get head commit SHA
run_id: ${{ env.directory }}
# Optional, defaults to current repo
repo: rladies/directory
path: entries/
- name: Site data - DIRECTORY - Move
run: |
rm -rf data/directory/* assets/directory/*
if [ "${{ env.directory }}" = "main" ]; then
cp -r tmpd/dir/data/json data/directory
cp -r tmpd/dir/data/img/* assets/directory
else
mv entries/json data/directory
if [ -d "entries/img" ]; then
mv entries/img/* assets/directory
fi
fi
- name: Site data - Meetup
uses: actions/checkout@v3
with:
repository: rladies/meetup_archive
ssh-key: ${{ secrets.MEETUP_ARCHIVE_KEY}}
path: tmpd/mtp
- name: Site data - Get blogs list
uses: actions/checkout@v3
with:
repository: rladies/awesome-rladies-blogs
ssh-key: ${{ secrets.RLADIES_BLOGS_KEY}}
path: tmpd/rblogs
- name: Site data - clean cloned repos
run: |
cp -r tmpd/rblogs/blogs data/rblogs
cp -r tmpd/mtp/data/* data/meetup/
rm -rf tmpd
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: ${{ env.hugovr }}
extended: true
- name: Build
run: |
if [[ '${{github.ref}}' == 'refs/heads/main' ]]; then
hugo \
-e production \
-d ${{ env.hugobd }}
else
hugo \
-e development \
-d ${{ env.hugobd }} \
-b https://${{ env.netalias }}--rladies-dev.netlify.app/
fi
- name: Deploy production 🚀
if: github.ref == 'refs/heads/main' && github.event_name != 'workflow_dispatch'
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: ${{ env.hugobd }}
- name: Deploy Preview
if: github.ref != 'refs/heads/main' || github.event_name == 'workflow_dispatch'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: |
npm install netlify-cli -g
netlify deploy \
--alias ${{ env.netalias }} \
--dir=${{ env.hugobd }}
- uses: actions/github-script@v6
if: github.ref != 'refs/heads/main' || github.event_name == 'workflow_dispatch'
name: Notify PR about build
with:
github-token: ${{ env.token }}
script: |
await github.rest.issues.createComment({
issue_number: ${{ env.issue }},
owner: 'rladies',
repo: '${{ env.repo_name }}',
body: ':tada: The preview is built! [Check it out](https://${{ env.netalias }}--rladies-dev.netlify.app)'
})