generated from fastai/fastpages
-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (169 loc) · 6.9 KB
/
upgrade.yaml
File metadata and controls
192 lines (169 loc) · 6.9 KB
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
name: Upgrade fastpages
on:
issues:
types: [opened]
jobs:
upgrade:
if: |
(github.repository != 'fastai/fastpages') &&
(github.event.issue.title == '[fastpages] Automated Upgrade') &&
(github.event.issue.author_association == 'OWNER')
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7
- 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: 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: copy new files
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 LICENSE
rm .github/workflows/chatops.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)"); do
if [[ -f "$file" ]] || [[ -d "$file" ]]
then
echo "copying $file";
cp -r $file ../current_files;
fi
done
# copy select files in assets
cp assets/main.scss ../current_files/assets
cp -r assets/js ../current_files/assets
cp -r assets/badges ../current_files/assets
# copy action workflows
cp -r .github ../current_files
# install dependencies
pip3 install pyyaml
- name: sync baseurl
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/ssh-agent@v0.2.0
with:
ssh-private-key: ${{ secrets.SSH_DEPLOY_KEY }}
- name: push changes to branch
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 "git@github.com:${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
id: pr
uses: actions/github-script@0.6.0
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()
uses: actions/github-script@0.6.0
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
uses: actions/github-script@0.6.0
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: Close Issue
if: always()
uses: actions/github-script@0.6.0
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'
})