Skip to content

ci: set up GitHub Actions to publish NPM package and API docs (#2) #1

ci: set up GitHub Actions to publish NPM package and API docs (#2)

ci: set up GitHub Actions to publish NPM package and API docs (#2) #1

Workflow file for this run

# This workflow will publish API docs to GitHub Pages when a new release tag is added to the main branch
name: Publish API docs to GitHub Pages
on:
push:
branches:
- main
tags:
- 'v*.*.*'
jobs:
deploy:
runs-on: ubuntu-22.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install
run: npm ci
- 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
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
tag_name: ${{ steps.prepare_tag.outputs.DEPLOY_TAG_NAME }}
tag_message: 'Deployment ${{ github.ref_name }}'