Skip to content

Commit 9bf3c87

Browse files
authored
CI for tags and versions (#315)
1 parent a53b52f commit 9bf3c87

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

.github/workflows/deploy-tags.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Deploy tag → gh-pages/tag
2+
3+
on:
4+
push:
5+
tags:
6+
- '*' # Trigger on any tag push
7+
workflow_dispatch: # Manual trigger
8+
9+
permissions: write-all
10+
11+
concurrency:
12+
group: pages
13+
cancel-in-progress: false
14+
15+
jobs:
16+
build-and-deploy:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout source
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Setup repo 🔧
25+
uses: ./.github/actions
26+
27+
- name: Build site
28+
env:
29+
BASE_PATH: ""
30+
TARGET_FOLDER: ${{ github.ref_name }}
31+
run: pnpm buildRepo
32+
33+
- name: Deploying release 🚀
34+
uses: JamesIves/github-pages-deploy-action@v4
35+
with:
36+
branch: gh-pages
37+
folder: out
38+
target-folder: ${{ github.ref_name }}
39+
clean: false
40+
41+
- name: Publish release 🚀
42+
uses: softprops/action-gh-release@v2
43+
with:
44+
tag_name: ${{ github.ref_name }}
45+
name: ${{ github.ref_name }}
46+
draft: false
47+
prerelease: false
48+
generate_release_notes: true
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/versions.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Generate versions.json
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Deploy tag → gh-pages/tag"] # This workflow will run after "Deploy Tags" completes
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
generate:
14+
if: github.event.workflow_run.conclusion == 'success'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout gh-pages branch
18+
uses: actions/checkout@v4
19+
with:
20+
ref: gh-pages
21+
22+
- name: Generate versions.json
23+
id: generate
24+
run: |
25+
set -euo pipefail
26+
27+
# List top-level directories, excluding dotfiles.
28+
DIRS=$(find . -maxdepth 1 -mindepth 1 -type d ! -name '.*' -printf '%f\n' || true)
29+
30+
# Extract semver-style directories (e.g., v1.2.3) and detect "latest"
31+
TAGS=$(echo "$DIRS" | grep -E '^v[0-9]+(\.[0-9]+)*$' || true)
32+
HAS_LATEST=$(echo "$DIRS" | grep -x 'latest' || true)
33+
34+
# Sort semantic versions descending
35+
VERSIONS_ARRAY='[]'
36+
if [ -n "$TAGS" ]; then
37+
SORTED=$(echo "$TAGS" | sort -V -r)
38+
VERSIONS_ARRAY=$(printf '%s\n' "$SORTED" | jq -R -s -c 'split("\n")[:-1]')
39+
fi
40+
41+
# Prepend 'latest' to the array if it exists
42+
if [ -n "$HAS_LATEST" ]; then
43+
VERSIONS_JSON=$(echo "$VERSIONS_ARRAY" | jq -c '["latest"] + .')
44+
else
45+
VERSIONS_JSON=$VERSIONS_ARRAY
46+
fi
47+
48+
# Create the versions.json file
49+
echo "$VERSIONS_JSON" > versions.json
50+
51+
echo "Generated versions.json:"
52+
cat versions.json
53+
54+
- name: Commit & push if changed
55+
run: |
56+
git config user.name "github-actions[bot]"
57+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
58+
59+
git add versions.json
60+
61+
# Only commit if there are changes
62+
if git diff --staged --quiet; then
63+
echo "No changes in versions.json, skipping commit."
64+
exit 0
65+
fi
66+
67+
git commit -m "Update versions.json"
68+
git push origin gh-pages

0 commit comments

Comments
 (0)