-
Notifications
You must be signed in to change notification settings - Fork 2
82 lines (72 loc) · 2.77 KB
/
Copy pathapi-map.yml
File metadata and controls
82 lines (72 loc) · 2.77 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
name: Generate API map
on:
schedule:
# Weekly refresh — API-map.yaml files change far less often than commits.
- cron: "20 4 * * 1"
workflow_dispatch: {}
permissions:
contents: write
# Two runs committing to the same branch would race on push.
concurrency:
group: api-map
cancel-in-progress: false
jobs:
generate:
runs-on: ubuntu-latest
timeout-minutes: 20
env:
HAS_MIRROR_PAT: ${{ secrets.MIRROR_PAT != '' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: true
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: web2/package-lock.json
# The generator parses API-map.yaml with js-yaml, a dependency of web2.
- name: Install dependencies
working-directory: web2
run: npm ci
# Shared with the monthly-updates generator, which also reads this repo.
- name: Cache physlib clone
uses: actions/cache@v4
with:
path: web2/.cache/physlib.git
key: physlib-clone-${{ github.run_id }}
restore-keys: physlib-clone-
- name: Run generator
working-directory: web2
run: node scripts/generate-api-map.js
- name: Commit & push updated API map
id: commit
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add web2/data/APIMap.json
if git diff --cached --quiet; then
echo "No API map changes to commit."
echo "committed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "chore(api-map): auto-generated update"
git pull --rebase --autostash origin "${GITHUB_REF_NAME}"
git push origin "HEAD:${GITHUB_REF_NAME}"
echo "committed=true" >> "$GITHUB_OUTPUT"
# See monthly-updates.yml for why this step exists: pushes made with the
# default GITHUB_TOKEN don't trigger mirror-to-personal.yml, so without
# this the API map would never reach the deployed (Vercel) site.
- name: Mirror to personal repo (Vercel)
if: steps.commit.outputs.committed == 'true' && env.HAS_MIRROR_PAT == 'true'
env:
MIRROR_PAT: ${{ secrets.MIRROR_PAT }}
run: |
git config --unset-all http.https://github.com/.extraheader || true
git config --global credential.helper store
echo "https://x-access-token:${MIRROR_PAT}@github.com" > ~/.git-credentials
git remote add mirror https://github.com/Gabrielebattimelli/Physlib-Website.git
git push mirror "HEAD:refs/heads/${GITHUB_REF_NAME}"