|  | 
| 1 | 1 | # Use this starter workflow to deploy HTML generated by Antora to surge.sh | 
| 2 | 2 | # Docs are published at <org>-<repo>-<deployid>.surge.sh | 
| 3 |  | -# By default, this workflow runs on completion of a workflow called "Verify PR" | 
|  | 3 | +#  | 
|  | 4 | +# By default, this workflow runs on completion of a workflow called "Verify docs PR" | 
|  | 5 | +#  | 
| 4 | 6 | # This workflow expects the triggering workflow to generate an artifact called "docs" | 
| 5 |  | - | 
| 6 | 7 | # - update the reference to "docs" and "docs.zip" in this workflow if your triggering workflow generates an artifact with a different name | 
| 7 |  | -name: "Deploy to surge" | 
|  | 8 | + | 
|  | 9 | +# change to force workflow with no changelog | 
|  | 10 | + | 
|  | 11 | +name: "Deploy docs preview" | 
| 8 | 12 | 
 | 
| 9 | 13 | on: | 
| 10 | 14 |   workflow_run: | 
| 11 |  | -    workflows: ["Verify PR"] | 
|  | 15 | +    workflows: ["Verify docs PR"] | 
| 12 | 16 |     types: | 
| 13 | 17 |       - completed | 
| 14 | 18 | 
 | 
| 15 | 19 | jobs: | 
| 16 | 20 |   publish-docs: | 
|  | 21 | +    # Uncomment this if statement to deploy only when the PR builds cleanly | 
| 17 | 22 |     # if: github.event.workflow_run.conclusion == 'success' | 
| 18 | 23 | 
 | 
| 19 | 24 |     runs-on: ubuntu-latest | 
| 20 | 25 | 
 | 
| 21 | 26 |     steps: | 
| 22 | 27 |       - name: "Download built documentation" | 
| 23 |  | - | 
|  | 28 | +        uses: actions/github-script@v7 | 
|  | 29 | +        env: | 
|  | 30 | +          RUN_ID: ${{ github.event.workflow_run.id }} | 
|  | 31 | +          WORKSPACE: ${{ github.workspace }} | 
| 24 | 32 |         with: | 
| 25 | 33 |           script: | | 
| 26 | 34 |             var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | 
| 27 | 35 |                owner: context.repo.owner, | 
| 28 | 36 |                repo: context.repo.repo, | 
| 29 |  | -               run_id: ${{ github.event.workflow_run.id }}, | 
|  | 37 | +               run_id: ${{ env.RUN_ID }}, | 
| 30 | 38 |             }); | 
| 31 |  | -            var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | 
|  | 39 | +
 | 
|  | 40 | +            var matchArtifactDocs = artifacts.data.artifacts.filter((artifact) => { | 
| 32 | 41 |               return artifact.name == "docs" | 
| 33 | 42 |             })[0]; | 
| 34 |  | -            var download = await github.rest.actions.downloadArtifact({ | 
|  | 43 | +            var downloadDocs = await github.rest.actions.downloadArtifact({ | 
| 35 | 44 |                owner: context.repo.owner, | 
| 36 | 45 |                repo: context.repo.repo, | 
| 37 |  | -               artifact_id: matchArtifact.id, | 
|  | 46 | +               artifact_id: matchArtifactDocs.id, | 
| 38 | 47 |                archive_format: 'zip', | 
| 39 | 48 |             }); | 
| 40 | 49 |             var fs = require('fs'); | 
| 41 |  | -            fs.writeFileSync('${{ github.workspace }}/docs.zip', Buffer.from(download.data)); | 
| 42 |  | -       | 
| 43 |  | -      - run: unzip docs.zip | 
|  | 50 | +            fs.writeFileSync('${{ env.WORKSPACE }}/docs.zip', Buffer.from(downloadDocs.data)); | 
|  | 51 | +
 | 
|  | 52 | +            var matchArtifactChangelog = artifacts.data.artifacts.filter((artifact) => { | 
|  | 53 | +              return artifact.name == "changelog" | 
|  | 54 | +            })[0]; | 
|  | 55 | +            var downloadChangelog = await github.rest.actions.downloadArtifact({ | 
|  | 56 | +              owner: context.repo.owner, | 
|  | 57 | +              repo: context.repo.repo, | 
|  | 58 | +              artifact_id: matchArtifactChangelog.id, | 
|  | 59 | +              archive_format: 'zip', | 
|  | 60 | +            }); | 
|  | 61 | +            fs.writeFileSync('${{ env.WORKSPACE }}/changelog.zip', Buffer.from(downloadChangelog.data)); | 
|  | 62 | +
 | 
|  | 63 | +      - id: unzip-docs | 
|  | 64 | +        run: unzip docs.zip | 
|  | 65 | + | 
|  | 66 | +      - id: get-top-dir | 
|  | 67 | +        run: | | 
|  | 68 | +          root=$(ls -d */index.html | sed -r 's/(.*)\/index\.html/\1/') | 
|  | 69 | +          echo "top-dir=$root" >> $GITHUB_OUTPUT | 
|  | 70 | +
 | 
|  | 71 | +      - id: unzip-changelog | 
|  | 72 | +        if: ${{ hashFiles('changelog.zip') != '' }} | 
|  | 73 | +        run: unzip changelog.zip | 
| 44 | 74 | 
 | 
| 45 | 75 |       - id: get-deploy-id | 
| 46 | 76 |         run: | | 
| 47 | 77 |           deployid=$(<deployid) | 
| 48 |  | -          echo "::set-output name=deploy-id::$deployid" | 
|  | 78 | +          case "$deployid" in ''|*[!0-9]*) echo "Provided PR number is not an integer"; exit 1 ;; esac | 
|  | 79 | +          echo "deploy-id=$deployid" >> "$GITHUB_OUTPUT" | 
|  | 80 | +
 | 
|  | 81 | +      - id: get-deploy-url | 
|  | 82 | +        env: | 
|  | 83 | +          ORG: ${{ github.event.repository.owner.login }} | 
|  | 84 | +          REPO: ${{ github.event.repository.name }} | 
|  | 85 | +          DEPLOYID: ${{ steps.get-deploy-id.outputs.deploy-id }} | 
|  | 86 | +        run: | | 
|  | 87 | +          deployurl=$ORG-$REPO-$DEPLOYID.surge.sh | 
|  | 88 | +          echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT | 
| 49 | 89 |        | 
| 50 |  | -      - uses: actions/setup-node@v3 | 
|  | 90 | +      - uses: actions/setup-node@v4 | 
| 51 | 91 |         with: | 
| 52 | 92 |           node-version: lts/* | 
| 53 | 93 | 
 | 
| 54 | 94 |       - name: Deploy docs to surge | 
|  | 95 | +        shell: bash | 
|  | 96 | +        env: | 
|  | 97 | +          DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }} | 
|  | 98 | +          SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}" | 
|  | 99 | +          SITE_DIR: ${{ steps.get-top-dir.outputs.top-dir }} | 
| 55 | 100 |         run: | | 
| 56 | 101 |           npm install -g surge | 
| 57 |  | -          surge ./site ${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ steps.get-deploy-id.outputs.deploy-id }}.surge.sh --token ${{ secrets.SURGE_TOKEN }} | 
|  | 102 | +          surge ./$SITE_DIR $DEPLOY_URL --token "$SURGE_TOKEN" | 
|  | 103 | +
 | 
|  | 104 | +      # If the PR artifacts include a changelog file, add it to the PR as a comment | 
|  | 105 | +      # The changelog contains links to new and changed files in the deployed docs | 
|  | 106 | +      - name: Comment on PR (changelog) | 
|  | 107 | +        if: ${{ hashFiles('changelog') != '' }} | 
|  | 108 | +        uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0 | 
|  | 109 | +        with: | 
|  | 110 | +          number: ${{ steps.get-deploy-id.outputs.deploy-id }} | 
|  | 111 | +          recreate: true | 
|  | 112 | +          header: docs-pr-changes | 
|  | 113 | +          path: changelog | 
|  | 114 | +          GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }} | 
| 58 | 115 | 
 | 
| 59 |  | -      - name: Comment on PR | 
| 60 |  | -        uses: marocchino/sticky-pull-request-comment@v2 | 
|  | 116 | +      # If there's no changelog, add a generic comment to the PR | 
|  | 117 | +      - name: Comment on PR (no changelog) | 
|  | 118 | +        if: ${{ hashFiles('changelog') == '' }} | 
|  | 119 | +        env: | 
|  | 120 | +          DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }} | 
|  | 121 | +        uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0 | 
| 61 | 122 |         with: | 
| 62 | 123 |           number: ${{ steps.get-deploy-id.outputs.deploy-id }} | 
|  | 124 | +          header: docs-pr-changes | 
| 63 | 125 |           message: | | 
| 64 | 126 |             Looks like you've updated the documentation! | 
| 65 | 127 | 
 | 
| 66 |  | -            Check out your changes at https://${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ steps.get-deploy-id.outputs.deploy-id }}.surge.sh | 
|  | 128 | +            Check out your changes at https://${{ env.DEPLOY_URL }} | 
| 67 | 129 |           GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }} | 
0 commit comments