generated from greenelab/lab-website-template
-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (94 loc) · 3.58 KB
/
first-time-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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: first-time-setup
run-name: first time setup of repo
on:
# run if user manually requests it
workflow_dispatch:
permissions:
contents: write
jobs:
first-time-setup:
runs-on: ubuntu-latest
steps:
# for debugging
- name: Print contexts
uses: crazy-max/ghaction-dump-context@v1
- name: Create Pages branch
uses: peterjgrainger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: "gh-pages"
- name: Checkout Pages branch
uses: actions/checkout@v3
with:
ref: gh-pages
# clean slate, as if starting from orphan branch
- name: Clear Pages branch
run: rm -rf * .github .docker .gitignore
# prevent GitHub from running Jekyll a second time after build
- name: Make .nojekyll file
run: touch .nojekyll
- name: Make placeholder homepage
run: echo "Placeholder homepage" > index.html
- name: Commit changes to Pages branch
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: gh-pages
commit_message: "Clear branch"
- name: Checkout main branch
uses: actions/checkout@v3
- name: Remove files user doesn't need
run: |
rm -rf \
CHANGELOG.md \
testbed.md \
.github/ISSUE_TEMPLATE \
.github/workflows/versioning.yaml \
.github/pull_request_template.md \
- name: Rename files
run: |
mv .github/user_pull_request_template.md .github/pull_request_template.md
- name: Set vars for personalization
run: |
user="${{ github.repository_owner }}"
description="."
echo "USER=${user}" >> $GITHUB_ENV
echo "DESCRIPTION=${description}" >> $GITHUB_ENV
- name: Personalize readme for user
run: |
echo "
# ${{ env.USER }}'s Website
Visit **[website url](#)** 🚀
_Built with [Lab Website Template](https://greene-lab.gitbook.io/lab-website-template-docs)_
" > README.md
- name: Personalize Jekyll config for user
uses: actions/github-script@v6
with:
script: |
const { readFileSync, writeFileSync } = require("fs");
const file = "_config.yaml";
const contents = readFileSync(file)
.toString()
.replace(/(^title: ).*$/m, "$1${{ env.USER }}")
.replace(/(^subtitle: ).*$/m, "$1")
.replace(/(^description: ).*$/m, "$1${{ env.DESCRIPTION }}")
.replace(/(^ email: ).*$/m, "$1contact@${{ env.USER }}.com")
.replace(/(^ github: ).*$/m, "$1${{ env.USER }}")
.replace(/(^ twitter: ).*$/m, "$1${{ env.USER }}")
.replace(/(^ youtube: ).*$/m, "$1${{ env.USER }}");
writeFileSync(file, contents);
- name: Personalize homepage for user
uses: actions/github-script@v6
with:
script: |
const { readFileSync, writeFileSync } = require("fs");
const file = "index.md";
let contents = readFileSync(file).toString();
const find = /\# Lab Website Template[\s\S]+({% include section\.html)/;
const replace = `# ${{ env.USER }}'s Website\n\n${{ env.DESCRIPTION }}\n\n$1`;
contents = contents.replace(find, replace);
writeFileSync(file, contents);
- name: Commit changed files
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Setup repo"