|
| 1 | +name: Publish schemas to GitHub Pages |
| 2 | + |
| 3 | +# Triggered when a schema version tag is pushed (pattern: schemas-vX.Y.Z). |
| 4 | +# Checks out the repo at that tag, copies the `schemas/` tree into a versioned |
| 5 | +# directory on the `gh-pages` branch, and pushes. |
| 6 | +# |
| 7 | +# `gh-pages` is the source for GitHub Pages (configure once in Settings -> Pages |
| 8 | +# after the first run creates the branch). |
| 9 | +# |
| 10 | +# Each published tag results in a frozen URL such as: |
| 11 | +# https://intersectmbo.github.io/governance-actions/v1.0.0/schemas/info/common.jsonld |
| 12 | +# |
| 13 | +# A `/latest/` mirror is also refreshed on every publish, for human inspection. |
| 14 | +# Do NOT reference `/latest/` from on-chain anchored metadata documents — its |
| 15 | +# resolved content drifts as new tags are cut. Use a pinned `/v<version>/` URL. |
| 16 | + |
| 17 | +on: |
| 18 | + push: |
| 19 | + tags: |
| 20 | + - 'schemas-v*' |
| 21 | + workflow_dispatch: |
| 22 | + inputs: |
| 23 | + tag: |
| 24 | + description: 'Existing schemas-vX.Y.Z tag to (re)publish' |
| 25 | + required: true |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: write |
| 29 | + |
| 30 | +concurrency: |
| 31 | + group: gh-pages-publish |
| 32 | + cancel-in-progress: false |
| 33 | + |
| 34 | +jobs: |
| 35 | + publish: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + - name: Resolve tag and version |
| 39 | + id: ver |
| 40 | + run: | |
| 41 | + set -euo pipefail |
| 42 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 43 | + tag="${{ inputs.tag }}" |
| 44 | + else |
| 45 | + tag="${GITHUB_REF#refs/tags/}" |
| 46 | + fi |
| 47 | + # tag = schemas-v1.0.0 -> version = v1.0.0 |
| 48 | + version="${tag#schemas-}" |
| 49 | + if [[ "$version" != v* ]]; then |
| 50 | + echo "Tag '$tag' does not match the expected schemas-vX.Y.Z pattern." >&2 |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 54 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 55 | +
|
| 56 | + - name: Checkout source @ tag |
| 57 | + uses: actions/checkout@v4 |
| 58 | + with: |
| 59 | + ref: ${{ steps.ver.outputs.tag }} |
| 60 | + path: src |
| 61 | + |
| 62 | + - name: Checkout (or initialise) gh-pages |
| 63 | + env: |
| 64 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + run: | |
| 66 | + set -euo pipefail |
| 67 | + repo_url="https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" |
| 68 | + if git ls-remote --exit-code "$repo_url" gh-pages >/dev/null 2>&1; then |
| 69 | + git clone --depth 1 --branch gh-pages "$repo_url" site |
| 70 | + else |
| 71 | + mkdir site |
| 72 | + cd site |
| 73 | + git init -b gh-pages |
| 74 | + git remote add origin "$repo_url" |
| 75 | + fi |
| 76 | +
|
| 77 | + - name: Copy schemas into /<version>/ and /latest/ |
| 78 | + run: | |
| 79 | + set -euo pipefail |
| 80 | + version="${{ steps.ver.outputs.version }}" |
| 81 | + rm -rf "site/${version}/schemas" "site/latest/schemas" |
| 82 | + mkdir -p "site/${version}" "site/latest" |
| 83 | + cp -r src/schemas "site/${version}/schemas" |
| 84 | + cp -r src/schemas "site/latest/schemas" |
| 85 | + # Disable Jekyll so files (including dot-prefixed ones, if any) are |
| 86 | + # served as-is, and so .jsonld files keep their application/ld+json |
| 87 | + # MIME type from the GitHub Pages MIME table. |
| 88 | + touch site/.nojekyll |
| 89 | +
|
| 90 | + - name: Commit and push |
| 91 | + working-directory: site |
| 92 | + run: | |
| 93 | + set -euo pipefail |
| 94 | + git config user.name "github-actions[bot]" |
| 95 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 96 | + git add -A |
| 97 | + if git diff --cached --quiet; then |
| 98 | + echo "No changes to publish." |
| 99 | + exit 0 |
| 100 | + fi |
| 101 | + git commit -m "publish ${{ steps.ver.outputs.version }} schemas" |
| 102 | + git push origin gh-pages |
0 commit comments