generated from fastai/fastpages
-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·99 lines (87 loc) · 4.17 KB
/
setup.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
name: Setup
on: push
jobs:
setup:
if: (github.event.commits[0].message == 'Initial commit') && (github.run_number == 1)
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Copy Repository Contents
uses: actions/checkout@v2
- name: modify files
run: |
import re, os
from pathlib import Path
from configparser import ConfigParser
config = ConfigParser()
nwo = os.getenv('GITHUB_REPOSITORY')
username, repo_name = nwo.split('/')
readme_template_path = Path('_fastpages_docs/README_TEMPLATE.md')
readme_path = Path('README.md')
config_path = Path('_config.yml')
pr_msg_path = Path('_fastpages_docs/_setup_pr_template.md')
settings = Path('_action_files/settings.ini')
assert readme_template_path.exists(), 'Did not find _fastpages_docs/README_TEMPLATE.md in the current directory!'
assert readme_path.exists(), 'Did not find README.md in the current directory!'
assert config_path.exists(), 'Did not find _config.yml in the current directory!'
assert pr_msg_path.exists(), 'Did not find _fastpages_docs/_setup_pr_template.md in the current directory!'
assert settings.exists(), 'Did not find _action_files/settings.ini in the current directory!'
# edit settings.ini file to inject baseurl
config.read(settings)
config['DEFAULT']['baseurl'] = f'/{repo_name}'
with open('_action_files/settings.ini', 'w') as configfile:
config.write(configfile)
# replace content of README with template
readme = readme_template_path.read_text().replace('{_username_}', username).replace('{_repo_name_}', repo_name)
readme_path.write_text(readme)
# update _config.yml
cfg = config_path.read_text()
cfg = re.sub(r'^(github_username: )(fastai)', fr'\g<1>{username}', cfg, flags=re.MULTILINE)
cfg = re.sub(r'^(baseurl: )("")', r'\1"/{}"'.format(repo_name), cfg, flags=re.MULTILINE)
cfg = re.sub(r'^(github_repo: ")(fastpages)', r'\1{}'.format(repo_name), cfg, flags=re.MULTILINE)
cfg = re.sub(r'^(url: "https://)(fastpages.fast.ai)(")', fr'\g<1>{username}.github.io\3', cfg, flags=re.MULTILINE)
cfg = re.sub('UA-57531313-5', '', cfg, flags=re.MULTILINE)
config_path.write_text(cfg)
# prepare the pr message
pr = pr_msg_path.read_text().replace('{_username_}', username).replace('{_repo_name_}', repo_name)
pr_msg_path.write_text(pr)
shell: python
- name: commit changes
run: |
git config --global user.email "${GH_EMAIL}"
git config --global user.name "${GH_USERNAME}"
git checkout -B fastpages-automated-setup
git rm CNAME action.yml
git rm _notebooks/2020-02-21-introducing-fastpages.ipynb
git rm _posts/2020-03-06-fastpages-actions.md
git rm -rf images/fastpages_posts
git rm .github/workflows/chatops.yaml
git rm .github/workflows/docker.yaml
git rm .github/workflows/docker-nbdev.yaml
git rm .github/ISSUE_TEMPLATE/bug.md
git rm .github/ISSUE_TEMPLATE/feature_request.md
git rm _word/*.docx
git add _config.yml README.md _fastpages_docs/ _action_files/settings.ini
git commit -m'setup repo'
git push -f --set-upstream origin fastpages-automated-setup
env:
GH_EMAIL: ${{ github.event.commits[0].author.email }}
GH_USERNAME: ${{ github.event.commits[0].author.username }}
- name: Open a PR
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
var fs = require('fs');
var contents = fs.readFileSync('_fastpages_docs/_setup_pr_template.md', 'utf8');
github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Initial Setup',
head: 'fastpages-automated-setup',
base: 'master',
body: `${contents}`
})