From 83b49fc3831f8ec40ca893c4416c98a8cbd18b33 Mon Sep 17 00:00:00 2001 From: Gili Tzabari Date: Wed, 1 Jan 2025 08:56:10 -0500 Subject: [PATCH] Updated workflow for publishing documentation --- .github/workflows/deploy_to_npm.yml | 67 ++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/.github/workflows/deploy_to_npm.yml b/.github/workflows/deploy_to_npm.yml index ddb7c81..34c3242 100644 --- a/.github/workflows/deploy_to_npm.yml +++ b/.github/workflows/deploy_to_npm.yml @@ -6,6 +6,7 @@ concurrency: cancel-in-progress: true permissions: contents: write + pages: write id-token: write jobs: @@ -13,8 +14,7 @@ jobs: 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: @@ -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" @@ -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 @@ -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: @@ -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 @@ -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 \ No newline at end of file + git push --delete origin ${{ needs.open-release.outputs.TAG }} \ No newline at end of file