-
Notifications
You must be signed in to change notification settings - Fork 704
100 lines (87 loc) · 3.57 KB
/
Copy pathpostbuild-scripts.yml
File metadata and controls
100 lines (87 loc) · 3.57 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
name: postbuild-scripts
run-name: Build the site, update Algolia's search index, and regenerate the sitemap
on:
push:
branches:
- "main"
# Lets a maintainer run this by hand, e.g. to confirm a workflow fix without
# waiting for the next push to main.
workflow_dispatch:
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true
jobs:
build-search-index:
runs-on: ubuntu-latest
name: Build Algolia search index
environment: Build Search Index
steps:
- name: Checkout the repo
uses: actions/checkout@v7
- name: Setup node, build the site and search index afterwards
uses: actions/setup-node@v7
with:
node-version: "20"
- run: npm install
- run: npm run export
- name: Run build-search-index script
run: node ./scripts/build-search-index.js
env:
ALGOLIA_SECRET: ${{ secrets.ALGOLIA_SECRET }}
build-sitemap:
runs-on: ubuntu-latest
name: Build sitemap
# Needed to push the sitemap branch and open its pull request.
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout the repo
uses: actions/checkout@v7
with:
# Keep the token available so the sitemap branch can be pushed.
persist-credentials: true
- name: Setup node, build the site, and generate the sitemap
id: sitemap
uses: actions/setup-node@v7
with:
node-version: "20"
- run: npm install
- run: npm run export
- run: npm run sitemap
# Uses git plus the preinstalled gh CLI instead of a third-party action:
# the enterprise actions allowlist rejects peter-evans/create-pull-request,
# which failed this whole workflow at startup. streamlit/streamlit opens
# its automated PRs the same way (see autofix.yml).
- name: Open a pull request if the sitemap changed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Scope to the generated sitemap only. `npm install` above can modify
# the tracked package-lock.json, which would otherwise both trigger a
# PR when the sitemap is unchanged and sweep an unrelated lockfile
# change into it. Quote the pathspec so git, not the shell, expands it,
# so a removed sitemap file is detected too.
if [ -z "$(git status --porcelain -- 'public/sitemap*.xml')" ]; then
echo "Sitemap unchanged; nothing to open."
exit 0
fi
git config user.email "core+streamlitbot-github@streamlit.io"
git config user.name "Streamlit Bot"
branch="automated-sitemap-update"
git checkout -B "$branch"
git add -A -- 'public/sitemap*.xml'
git commit -m "Automated sitemap update"
# Reuse one long-lived branch so repeated runs update a single PR
# rather than opening a new one for every push to main.
git push --force --set-upstream origin "$branch"
if [ -n "$(gh pr list --head "$branch" --state open --json number --jq '.[].number')" ]; then
echo "A sitemap PR is already open for $branch; pushed the update to it."
exit 0
fi
gh pr create \
--head "$branch" \
--base main \
--title "Automated sitemap update" \
--body "Sitemap regenerated by \`npm run sitemap\` after a push to \`main\`."