Skip to content

Commit

Permalink
Updated workflow for publishing documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cowwoc committed Jan 1, 2025
1 parent baaf4d1 commit 83b49fc
Showing 1 changed file with 46 additions and 21 deletions.
67 changes: 46 additions & 21 deletions .github/workflows/deploy_to_npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ concurrency:
cancel-in-progress: true
permissions:
contents: write
pages: write
id-token: write

jobs:
open-release:
name: Open release
runs-on: ubuntu-latest
outputs:
INITIAL_MASTER_POSITION: ${{ steps.create-tag.outputs.INITIAL_MASTER_POSITION }}
INITIAL_GH_PAGES_POSITION: ${{ steps.create-tag.outputs.INITIAL_GH_PAGES_POSITION }}
INITIAL_MAIN_POSITION: ${{ steps.create-tag.outputs.INITIAL_MAIN_POSITION }}
TAG: ${{ steps.create-tag.outputs.TAG }}
VERSION: ${{ steps.create-tag.outputs.VERSION }}
steps:
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Create tag
id: create-tag
run: |
echo "INITIAL_MASTER_POSITION=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "INITIAL_MAIN_POSITION=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
VERSION=${{ steps.parse-version.outputs.current-version }}
TAG=release-${VERSION}
echo "TAG=${TAG}" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -91,6 +91,43 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Generate documentation
run: |
VERSION=${{ needs.open-release.outputs.VERSION }}
rm -rf "docs/api/${VERSION}"
mkdir --parents "docs/api/${VERSION}"
mv target/apidocs/* "docs/api/${VERSION}"
- name: Commit documentation
run: |
git checkout ${{ github.ref_name }} -f
git add "docs/api/${{ needs.open-release.outputs.VERSION }}"
git commit -m "Committing documentation for version ${{ needs.open-release.outputs.VERSION }}"
git push
document:
name: Document
needs: deploy
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: "docs/api"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4


- name: Publish documentation
run: |
git checkout gh-pages -f
Expand All @@ -104,7 +141,7 @@ jobs:
# Cleanup on failure: https://stackoverflow.com/a/74562058/14731
on-failure:
name: On failure
needs: [ open-release, deploy ]
needs: [ open-release, deploy, document ]
runs-on: ubuntu-latest
if: ${{ failure() || cancelled() }}
steps:
Expand All @@ -130,12 +167,12 @@ jobs:
with:
cache: pnpm

- name: Restore the master ref to its original position
if: needs.open-release.outputs.INITIAL_MASTER_POSITION != ''
- name: Restore the main ref to its original position
if: needs.open-release.outputs.INITIAL_MAIN_POSITION != ''
run: |
CURRENT_REF_POSITION=$(git rev-parse HEAD)
if [ "${CURRENT_REF_POSITION}" != "${{ needs.open-release.outputs.INITIAL_MASTER_POSITION }}" ]; then
git reset --hard ${{ needs.open-release.outputs.INITIAL_MASTER_POSITION }}
if [ "${CURRENT_REF_POSITION}" != "${{ needs.open-release.outputs.INITIAL_MAIN_POSITION }}" ]; then
git reset --hard ${{ needs.open-release.outputs.INITIAL_MAIN_POSITION }}
if [ "${{ github.ref_type }}" == "tag" ]; then
git ${{ github.ref_type }} -f ${{ github.ref_name }}
fi
Expand All @@ -145,16 +182,4 @@ jobs:
- name: Delete tag
if: needs.open-release.outputs.TAG != ''
run: |
git push --delete origin ${{ needs.open-release.outputs.TAG }}
- name: Restore the gh-pages ref to its original position
if: needs.open-release.outputs.INITIAL_GH_PAGES_POSITION != ''
run: |
CURRENT_REF_POSITION=$(git rev-parse HEAD)
if [ "${CURRENT_REF_POSITION}" != "${{ needs.open-release.outputs.INITIAL_GH_PAGES_POSITION }}" ]; then
git reset --hard ${{ needs.open-release.outputs.INITIAL_GH_PAGES_POSITION }}
if [ "${{ github.ref_type }}" == "tag" ]; then
git ${{ github.ref_type }} -f ${{ github.ref_name }}
fi
git push -f origin ${{ github.ref_name }}
fi
git push --delete origin ${{ needs.open-release.outputs.TAG }}

0 comments on commit 83b49fc

Please sign in to comment.