|  | 
|  | 1 | +# Use this starter workflow to deploy HTML generated by Antora to surge.sh | 
|  | 2 | +# Docs are published at <org>-<repo>-<deployid>.surge.sh | 
|  | 3 | +#  | 
|  | 4 | +# By default, this workflow runs on completion of a workflow called "Verify docs PR" | 
|  | 5 | +#  | 
|  | 6 | +# This workflow expects the triggering workflow to generate an artifact called "docs" | 
|  | 7 | +# - update the reference to "docs" and "docs.zip" in this workflow if your triggering workflow generates an artifact with a different name | 
|  | 8 | + | 
|  | 9 | +# change to force workflow with no changelog | 
|  | 10 | + | 
|  | 11 | +name: "Deploy docs preview" | 
|  | 12 | + | 
|  | 13 | +on: | 
|  | 14 | +  workflow_run: | 
|  | 15 | +    workflows: ["Verify docs PR"] | 
|  | 16 | +    types: | 
|  | 17 | +      - completed | 
|  | 18 | + | 
|  | 19 | +jobs: | 
|  | 20 | +  publish-docs: | 
|  | 21 | +    # Uncomment this if statement to deploy only when the PR builds cleanly | 
|  | 22 | +    # if: github.event.workflow_run.conclusion == 'success' | 
|  | 23 | + | 
|  | 24 | +    runs-on: ubuntu-latest | 
|  | 25 | + | 
|  | 26 | +    steps: | 
|  | 27 | +      - name: "Download built documentation" | 
|  | 28 | +        uses: actions/github-script@v7 | 
|  | 29 | +        env: | 
|  | 30 | +          RUN_ID: ${{ github.event.workflow_run.id }} | 
|  | 31 | +          WORKSPACE: ${{ github.workspace }} | 
|  | 32 | +        with: | 
|  | 33 | +          script: | | 
|  | 34 | +            var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | 
|  | 35 | +               owner: context.repo.owner, | 
|  | 36 | +               repo: context.repo.repo, | 
|  | 37 | +               run_id: ${{ env.RUN_ID }}, | 
|  | 38 | +            }); | 
|  | 39 | +
 | 
|  | 40 | +            var matchArtifactDocs = artifacts.data.artifacts.filter((artifact) => { | 
|  | 41 | +              return artifact.name == "docs" | 
|  | 42 | +            })[0]; | 
|  | 43 | +            var downloadDocs = await github.rest.actions.downloadArtifact({ | 
|  | 44 | +               owner: context.repo.owner, | 
|  | 45 | +               repo: context.repo.repo, | 
|  | 46 | +               artifact_id: matchArtifactDocs.id, | 
|  | 47 | +               archive_format: 'zip', | 
|  | 48 | +            }); | 
|  | 49 | +            var fs = require('fs'); | 
|  | 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 | 
|  | 74 | +       | 
|  | 75 | +      - id: get-deploy-id | 
|  | 76 | +        run: | | 
|  | 77 | +          deployid=$(<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 | 
|  | 89 | +       | 
|  | 90 | +      - uses: actions/setup-node@v4 | 
|  | 91 | +        with: | 
|  | 92 | +          node-version: lts/* | 
|  | 93 | +       | 
|  | 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 }} | 
|  | 100 | +        run: | | 
|  | 101 | +          npm install -g surge | 
|  | 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 }} | 
|  | 115 | + | 
|  | 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 | 
|  | 122 | +        with: | 
|  | 123 | +          number: ${{ steps.get-deploy-id.outputs.deploy-id }} | 
|  | 124 | +          header: docs-pr-changes | 
|  | 125 | +          message: | | 
|  | 126 | +            Looks like you've updated the documentation! | 
|  | 127 | +
 | 
|  | 128 | +            Check out your changes at https://${{ env.DEPLOY_URL }} | 
|  | 129 | +          GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }} | 
0 commit comments