-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (116 loc) · 4.78 KB
/
bootstrap.yml
File metadata and controls
134 lines (116 loc) · 4.78 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
name: Bootstrap new repo
on:
push:
branches: ["main"]
workflow_dispatch:
permissions:
contents: write
issues: write
pages: write
id-token: write
jobs:
bootstrap:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- name: Derive names
id: names
shell: bash
run: |
set -euo pipefail
REPO="${{ github.event.repository.name }}"
OWNER="${{ github.repository_owner }}"
# Humanize repo name -> Title Case
TITLE="$(python -c 'import os,re; n=os.environ["REPO"]; n=re.sub(r"__", " ", n); n=re.sub(r"[-_]+", " ", n); print(" ".join(w.capitalize() for w in n.split()))')"
# Extract group id (…__N or trailing digits)
GROUP_ID=""
if [[ "$REPO" =~ __([0-9]+)$ ]]; then
GROUP_ID="${BASH_REMATCH[1]}"
elif [[ "$REPO" =~ ([0-9]+)$ ]]; then
GROUP_ID="${BASH_REMATCH[1]}"
fi
{
echo "repo=$REPO"
echo "owner=$OWNER"
echo "title=$TITLE"
echo "group_id=$GROUP_ID"
echo "site_url=https://${OWNER}.github.io/${REPO}/"
} >> "$GITHUB_OUTPUT"
- name: Inject storage link (optional)
id: storage
shell: bash
run: |
set -euo pipefail
GROUP_ID="${{ steps.names.outputs.group_id }}"
BASE="${{ secrets.COMMUNITY_STORAGE_BASE }}"
if [[ -n "${BASE:-}" && -n "${GROUP_ID:-}" ]]; then
mkdir -p docs/resources
printf "# Shared Storage\n\n- Group folder: %s/%s\n" "$BASE" "$GROUP_ID" > docs/resources/storage.md
echo "has_storage=true" >> "$GITHUB_OUTPUT"
else
echo "has_storage=false" >> "$GITHUB_OUTPUT"
fi
- name: Replace placeholders in mkdocs.yml and docs
shell: bash
run: |
set -euo pipefail
TITLE='${{ steps.names.outputs.title }}'
SITE_URL='${{ steps.names.outputs.site_url }}'
REPO_URL="https://github.com/${{ github.repository }}"
# mkdocs.yml
if [[ -f mkdocs.yml ]]; then
if grep -qE '^site_name:' mkdocs.yml; then
sed -i.bak "s|^site_name:.*|site_name: \"${TITLE}\"|g" mkdocs.yml
else
printf "\nsite_name: \"%s\"\n" "$TITLE" >> mkdocs.yml
fi
if grep -qE '^site_url:' mkdocs.yml; then
sed -i.bak "s|^site_url:.*|site_url: \"${SITE_URL}\"|g" mkdocs.yml
else
printf "site_url: \"%s\"\n" "$SITE_URL" >> mkdocs.yml
fi
fi
# docs/index.md
if [[ -f docs/index.md ]]; then
awk 'NR==1{ if ($0 ~ /^# /) {$0="# '"${TITLE}"'"} else {print "# '"${TITLE}"'"; print} }1' docs/index.md > docs/index.md.tmp
mv docs/index.md.tmp docs/index.md
STORAGE_FLAG='${{ steps.storage.outputs.has_storage }}'
if [[ "$STORAGE_FLAG" == "true" ]]; then
perl -0777 -pe 's|<!--RESOURCES_START-->.*?<!--RESOURCES_END-->|<!--RESOURCES_START-->\n\n**Repo:** '"${REPO_URL}"' \\n**Shared storage:** See [resources/storage.md](resources/storage.md)\n\n<!--RESOURCES_END-->|s' -i docs/index.md \
|| printf "\n\n<!--RESOURCES_START-->\n\n**Repo:** %s \\n**Shared storage:** See [resources/storage.md](resources/storage.md)\n\n<!--RESOURCES_END-->\n" "$REPO_URL" >> docs/index.md
else
perl -0777 -pe 's|<!--RESOURCES_START-->.*?<!--RESOURCES_END-->|<!--RESOURCES_START-->\n\n**Repo:** '"${REPO_URL}"'\n\n<!--RESOURCES_END-->|s' -i docs/index.md \
|| printf "\n\n<!--RESOURCES_START-->\n\n**Repo:** %s\n\n<!--RESOURCES_END-->\n" "$REPO_URL" >> docs/index.md
fi
fi
- name: Commit bootstrap changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(bootstrap): set site title/urls and resources"
commit_user_name: "oasis-bot"
commit_user_email: "oasis-bot@users.noreply.github.com"
branch: main
- name: Configure Pages
uses: actions/configure-pages@v5
- name: Build site with MkDocs
shell: bash
run: |
set -euo pipefail
pipx install mkdocs-material
mkdocs build --strict --verbose
env:
PYTHONWARNINGS: ignore
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: site
- name: Deploy to Pages
uses: actions/deploy-pages@v4
- name: Open a “Setup complete” issue
if: always()
uses: peter-evans/create-issue-from-file@v5
with:
title: "✅ Repo bootstrap complete"
content-filepath: .github/ISSUE_TEMPLATE/SETUP_COMPLETE.md
labels: setup