Skip to content

Release

Release #16

Workflow file for this run

name: Release
on:
push:
tags:
- v*.*.*
workflow_dispatch:
inputs:
tag:
description: New or existing tag (e.g. v1.2.3)
required: true
type: string
permissions:
contents: write # needed to push tag and/or create release
env:
OPENAPI_ENTRY: specification/gridtariffapi.json
WORK_DIR: dist
BUNDLED_JSON: dist/openapi.json
REDOC_HTML: dist/redoc.html
REDOCLY_VERSION: 2.0.8
TAG: "${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}"
jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Validate tag format
id: validate
shell: bash
run: |
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: version must match vX.Y.Z (e.g., v1.2.3). Got: $TAG"
exit 1
fi
- if: ${{ github.event_name == 'workflow_dispatch' }}
name: Check out repository with full history
uses: actions/checkout@v4
with:
fetch-depth: 0 # we need full history to create/push a tag cleanly
- if: ${{ github.event_name == 'workflow_dispatch' }}
name: Create and push tag
env:
GH_TOKEN: ${{ github.token }}
run: |
if git ls-remote --tags origin | grep -q "refs/tags/${TAG}$"; then
echo "Tag ${TAG} already exists on origin. Using ${TAG} to create new release."
else
echo "Pushing tag ${TAG} to repo and using it to create new release."
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "${TAG}" -m "Release ${TAG}" "${GITHUB_SHA}"
git push "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" "refs/tags/${TAG}"
fi
build:
runs-on: ubuntu-latest
needs: tag
steps:
- name: Check out tag ref
uses: actions/checkout@v4
with:
ref: ${{ env.TAG }}
- name: Bundle OpenAPI
run: |
mkdir -p "$WORK_DIR"
npx --yes @redocly/cli@$REDOCLY_VERSION bundle "$OPENAPI_ENTRY" \
--output "$BUNDLED_JSON" \
--ext json
- name: Lint OpenAPI (bundled)
run: npx --yes @redocly/cli@$REDOCLY_VERSION lint "$BUNDLED_JSON"
- name: Build Redoc HTML
run: npx --yes @redocly/cli@$REDOCLY_VERSION build-docs "$BUNDLED_JSON" --output="$REDOC_HTML"
- name: Verify info.version matches tag
run: |
version_in_tag=${TAG#v}
version_in_file=$(jq -r '.info.version' $BUNDLED_JSON)
if [ "$version_in_file" != "$version_in_tag" ]; then
echo "info.version ($version_in_file) does not match input version ($version_in_tag)"
exit 1
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: openapi-release-${{ env.TAG }}
path: |
dist/openapi.json
dist/redoc.html
release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v4
with:
name: openapi-release-${{ env.TAG }}
path: dist
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
name: ${{ env.TAG }}
body: |
Automated release for ${{ env.TAG }}.
- Linted source OpenAPI (`${{ env.OPENAPI_ENTRY }}`)
- Bundled to `${{ env.BUNDLED_JSON }}`
- Generated Redoc `${{ env.REDOC_HTML }}`
files: |
dist/openapi.json
dist/redoc.html
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/download-artifact@v4
with:
name: openapi-release-${{ env.TAG }}
path: dist
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: site
- name: Copy versioned files
run: |
set -e
release_dir="site/releases/$TAG"
mkdir -p "$release_dir"
cp dist/openapi.json "$release_dir/openapi.json"
cp dist/redoc.html "$release_dir/redoc.html"
- name: Update versions.json
env:
COMMIT_DATE: ${{ steps.resolve.outputs.commit_date }}
run: |
set -e
cd site
test -f versions.json || echo "[]" > versions.json
# Remove previous entry for this tag (idempotent)
jq --arg tag "$TAG" 'map(select(.tag != $tag))' versions.json > .tmp.json && mv .tmp.json versions.json
jq --arg tag "$TAG" \
--arg date "$COMMIT_DATE" \
'. + [{tag:$tag, date:$date}]' versions.json > .tmp.json && mv .tmp.json versions.json
- name: Commit & push
run: |
cd site
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --staged --quiet; then
echo "No changes to commit."
else
git commit -m "Publish ${{ steps.resolve.outputs.tag }}"
git push origin gh-pages
fi