generated from fastai/fastpages
-
Notifications
You must be signed in to change notification settings - Fork 1
executable file
·276 lines (247 loc) · 10.6 KB
/
upgrade.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
name: Upgrade fastpages
on:
issues:
types: [opened]
jobs:
check_credentials:
if: |
(github.repository != 'fastai/fastpages') &&
(github.event.issue.title == '[fastpages] Automated Upgrade')
runs-on: ubuntu-latest
steps:
- name: see payload
run: |
echo "FULL PAYLOAD:\n${PAYLOAD}\n"
echo "PR_PAYLOAD PAYLOAD:\n${PR_PAYLOAD}"
env:
PAYLOAD: ${{ toJSON(github.event) }}
PR_PAYLOAD: ${{ github.event.pull_request }}
- name: Comment on issue if sufficient access does not exist
if: |
(github.event.issue.author_association != 'OWNER') &&
(github.event.issue.author_association != 'COLLABORATOR') &&
(github.event.issue.author_association != 'MEMBER')
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
var permission_level = process.env.permission_level;
var url = 'https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/permission-levels-for-a-user-account-repository#collaborator-access-on-a-repository-owned-by-a-user-account'
var msg = `You must have the [permission level](${url}) of either an **OWNER**, **COLLABORATOR** or **MEMBER** to instantiate an upgrade request. Your permission level is ${permission_level}`
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: msg
})
github.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed'
})
throw msg;
env:
permission_level: ${{ github.event.issue.author_association }}
upgrade:
needs: [check_credentials]
if: |
(github.repository != 'fastai/fastpages') &&
(github.event.issue.title == '[fastpages] Automated Upgrade') &&
(github.event.issue.author_association == 'OWNER' || github.event.issue.author_association == 'COLLABORATOR' || github.event.issue.author_association == 'MEMBER')
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: checkout latest fastpages
uses: actions/checkout@v2
with:
repository: 'fastai/fastpages'
path: 'new_files'
persist-credentials: false
- name: copy this repo's contents
uses: actions/checkout@v2
with:
path: 'current_files'
persist-credentials: false
- name: compare versions
id: check_version
run: |
from pathlib import Path
new_version = Path('new_files/_fastpages_docs/version.txt')
old_version = Path('current_files/_fastpages_docs/version.txt')
if old_version.exists():
old_num = old_version.read_text().strip()
new_num = new_version.read_text().strip()
print(f'Old version: {old_num}')
print(f'New version: {new_num}')
if old_num == new_num:
print('::set-output name=vbump::false')
else:
print('::set-output name=vbump::true')
else:
print('::set-output name=vbump::true')
shell: python
- name: copy new files
if: steps.check_version.outputs.vbump == 'true'
run: |
# remove files you don't want to copy from current version of fastpages
cd new_files
rm -rf _posts _notebooks _word images
rm *.md CNAME action.yml _config.yml index.html LICENSE
rm _pages/*.md
rm .github/workflows/chatops.yaml
rm .github/workflows/docker-nbdev.yaml
rm .github/workflows/docker.yaml
rm .github/ISSUE_TEMPLATE/bug.md .github/ISSUE_TEMPLATE/feature_request.md
# copy new files from fastpages into your repo
for file in $(ls | egrep -v "(assets|_sass)"); do
if [[ -f "$file" ]] || [[ -d "$file" ]]
then
echo "copying $file";
cp -r $file ../current_files;
fi
done
# copy custom-variables.scss if doesn't exist
if [ ! -f "../current_files/_sass/minima/custom-variables.scss" ]; then
cp _sass/minima/custom-variables.scss ../current_files/_sass/minima/
fi
# copy select files in assets and _sass
cp -r assets/js ../current_files/assets
cp -r assets/badges ../current_files/assets
cp _sass/minima/fastpages-styles.scss ../current_files/_sass/minima/
cp _sass/minima/fastpages-dracula-highlight.scss ../current_files/_sass/minima/
# copy action workflows
cp -r .github ../current_files
# install dependencies
pip3 install pyyaml
- name: sync baseurl
if: steps.check_version.outputs.vbump == 'true'
run: |
import re, os, yaml
from pathlib import Path
from configparser import ConfigParser
settings = ConfigParser()
# specify location of config files
nwo = os.getenv('GITHUB_REPOSITORY')
username, repo_name = nwo.split('/')
settings_path = Path('current_files/_action_files/settings.ini')
config_path = Path('current_files/_config.yml')
setup_pr_path = Path('current_files/_fastpages_docs/_setup_pr_template.md')
upgrade_pr_path = Path('current_files/_fastpages_docs/_upgrade_pr.md')
assert settings_path.exists(), 'Did not find _action_files/settings.ini in your repository!'
assert config_path.exists(), 'Did not find _config.yml in your repository!'
assert setup_pr_path.exists(), 'Did not find_fastpages_docs/_setup_pr_template.md in the current directory!'
assert upgrade_pr_path.exists(), 'Did not find _fastpages_docs/_upgrade_pr.md in your repository!'
# read data from config files
settings.read(settings_path)
with open(config_path, 'r') as cfg:
config = yaml.load(cfg)
# sync value for baseurl b/w config.yml and settings.ini
settings['DEFAULT']['baseurl'] = config['baseurl']
with open(settings_path, 'w') as stg:
settings.write(stg)
# update PR templates
setup_pr = setup_pr_path.read_text().replace('{_username_}', username).replace('{_repo_name_}', repo_name)
setup_pr_path.write_text(setup_pr)
upgrade_pr = upgrade_pr_path.read_text().replace('{_username_}', username).replace('{_repo_name_}', repo_name)
upgrade_pr_path.write_text(upgrade_pr)
shell: python
- uses: webfactory/[email protected]
if: steps.check_version.outputs.vbump == 'true'
with:
ssh-private-key: ${{ secrets.SSH_DEPLOY_KEY }}
- name: push changes to branch
if: steps.check_version.outputs.vbump == 'true'
run: |
# commit changes
cd current_files
git config --global user.email "${GH_USERNAME}@users.noreply.github.com"
git config --global user.name "${GH_USERNAME}"
git remote remove origin
git remote add origin "[email protected]:${GITHUB_REPOSITORY}.git"
git add _action_files/settings.ini
git checkout -b fastpages-automated-upgrade
git add -A
git commit -m'upgrade fastpages'
git push -f --set-upstream origin fastpages-automated-upgrade master
env:
GH_USERNAME: ${{ github.event.issue.user.login }}
- name: Open a PR
if: steps.check_version.outputs.vbump == 'true'
id: pr
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
var fs = require('fs');
var contents = fs.readFileSync('current_files/_fastpages_docs/_upgrade_pr.md', 'utf8');
github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '[fastpages] Update repo with changes from fastpages',
head: 'fastpages-automated-upgrade',
base: 'master',
body: `${contents}`
})
.then(result => console.log(`::set-output name=pr_num::${result.data.number}`))
- name: Comment on issue if failure
if: failure() && (steps.check_version.outputs.vbump == 'true')
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
var pr_num = process.env.PR_NUM;
var repo = process.env.REPO
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `An error occurred when attempting to open a PR to update fastpages. See the [Actions tab of your repo](https://github.com/${repo}/actions) for more details.`
})
env:
PR_NUM: ${{ steps.pr.outputs.pr_num }}
REPO: ${{ github.repository }}
- name: Comment on issue
if: steps.check_version.outputs.vbump == 'true'
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
var pr_num = process.env.PR_NUM;
var repo = process.env.REPO
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Opened PR https://github.com/${repo}/pull/${pr_num} to assist with updating fastpages.`
})
env:
PR_NUM: ${{ steps.pr.outputs.pr_num }}
REPO: ${{ github.repository }}
- name: Comment on issue if version has not changed
if: steps.check_version.outputs.vbump == 'false'
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Your version of fastpages is up to date. There is nothing to change.`
})
- name: Close Issue
if: always()
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed'
})