Skip to content

Commit

Permalink
ci: update GitHub Actions to publish API docs on release or on manual…
Browse files Browse the repository at this point in the history
… trigger (#5)

* ci: update GitHub Actions to publish API docs on release or on manual trigger

* ci: fix docs-publish workflow error by setting fetch-tags as true

* ci: replace fetch-tags with fetch-depth in docs-publish.yml
  • Loading branch information
Deyang-Dai authored Dec 23, 2024
1 parent b3e1f69 commit 8a0069f
Showing 1 changed file with 58 additions and 33 deletions.
91 changes: 58 additions & 33 deletions .github/workflows/docs-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,44 @@
name: Publish API docs to GitHub Pages

on:
push:
branches:
- main
tags:
- 'v*.*.*'
release:
types:
- published
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-22.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
check-tag:
runs-on: ubuntu-latest
steps:
- name: Fetch the latest release tag
id: fetch_latest_release_tag
run: |
LATEST_TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')
echo "LATEST_TAG=$LATEST_TAG" >> "$GITHUB_OUTPUT"
echo "The latest release tag is $LATEST_TAG"
- name: Check release tag on release event
if: ${{ github.event_name == 'release' }}
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
LATEST_TAG: ${{ steps.fetch_latest_release_tag.outputs.LATEST_TAG }}
run: |
if [[ "$RELEASE_TAG" != "$LATEST_TAG" ]]; then
echo "Release tag $RELEASE_TAG does not match the latest tag $LATEST_TAG."
exit 1
else
echo "Release tag $RELEASE_TAG matches the latest tag $LATEST_TAG."
fi
build:
needs: check-tag
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
ref: ${{ steps.fetch_latest_release_tag.outputs.LATEST_TAG }}

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -33,25 +53,30 @@ jobs:
- name: Build docs
run: npm run docs

- name: Prepare tag
id: prepare_tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
LATEST_TAG=$(git tag -l --sort=-v:refname | head -n 1)
echo "Latest tag is $LATEST_TAG"
echo "Current tag is $GITHUB_REF_NAME"
if [ "${GITHUB_REF_NAME}" != "${LATEST_TAG}" ]; then
echo "Not the latest tag, skipping deploy."
exit 0
else
echo "This is the latest tag, proceeding with deploy."
fi
echo "DEPLOY_TAG_NAME=deploy-${GITHUB_REF_NAME}" >> "${GITHUB_OUTPUT}"
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
- name: Upload static files as artifact
uses: actions/upload-pages-artifact@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
tag_name: ${{ steps.prepare_tag.outputs.DEPLOY_TAG_NAME }}
tag_message: 'Deployment ${{ github.ref_name }}'
path: docs/

deploy:
needs: build

concurrency:
group: docs-publish
cancel-in-progress: true

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

0 comments on commit 8a0069f

Please sign in to comment.