11# Use this starter workflow to deploy HTML generated by Antora to surge.sh
22# 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+ #
46# This workflow expects the triggering workflow to generate an artifact called "docs"
5-
67# - 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+ name : " Deploy docs preview"
810
911on :
1012 workflow_run :
11- workflows : ["Verify PR"]
13+ workflows : ["Verify docs PR"]
1214 types :
1315 - completed
1416
1517jobs :
1618 publish-docs :
19+ # Uncomment this if statement to deploy only when the PR builds cleanly
1720 # if: github.event.workflow_run.conclusion == 'success'
1821
1922 runs-on : ubuntu-latest
2023
2124 steps :
2225 - name : " Download built documentation"
23- 26+ 27+ env :
28+ RUN_ID : ${{ github.event.workflow_run.id }}
29+ WORKSPACE : ${{ github.workspace }}
2430 with :
2531 script : |
2632 var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
2733 owner: context.repo.owner,
2834 repo: context.repo.repo,
29- run_id: ${{ github.event.workflow_run.id }},
35+ run_id: ${{ env.RUN_ID }},
3036 });
3137 var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
3238 return artifact.name == "docs"
3844 archive_format: 'zip',
3945 });
4046 var fs = require('fs');
41- fs.writeFileSync('${{ github.workspace }}/docs.zip', Buffer.from(download.data));
47+ fs.writeFileSync('${{ env.WORKSPACE }}/docs.zip', Buffer.from(download.data));
4248
4349 - run : unzip docs.zip
4450
4753 deployid=$(<deployid)
4854 case "$deployid" in ''|*[!0-9]*) echo "Provided PR number is not an integer"; exit 1 ;; esac
4955 echo "deploy-id=$deployid" >> "$GITHUB_OUTPUT"
56+
57+ - id : get-deploy-url
58+ env :
59+ ORG : ${{ github.event.repository.owner.login }}
60+ REPO : ${{ github.event.repository.name }}
61+ DEPLOYID : ${{ steps.get-deploy-id.outputs.deploy-id }}
62+ run : |
63+ deployurl=$ORG-$REPO-$DEPLOYID.surge.sh
64+ echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT
5065
5166 - uses : actions/setup-node@v3
5267 with :
@@ -55,17 +70,35 @@ jobs:
5570 - name : Deploy docs to surge
5671 shell : bash
5772 env :
73+ DEPLOY_URL : ${{ steps.get-deploy-url.outputs.deploy-url }}
5874 SURGE_TOKEN : " ${{ secrets.DOCS_SURGE_TOKEN }}"
5975 run : |
6076 npm install -g surge
61- surge ./site ${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ steps.get-deploy-id.outputs.deploy-id }}.surge.sh --token "$SURGE_TOKEN"
77+ surge ./site $DEPLOY_URL --token "$SURGE_TOKEN"
6278
63- - name : Comment on PR
79+ # If the PR artifacts include a changelog file, add it to the PR as a comment
80+ # The changelog contains links to new and changed files in the deployed docs
81+ - name : Comment on PR (changelog)
82+ if : ${{ hashFiles('changelog') != '' }}
83+ uses : marocchino/sticky-pull-request-comment@v2
84+ with :
85+ number : ${{ steps.get-deploy-id.outputs.deploy-id }}
86+ recreate : true
87+ header : docs-pr-changes
88+ path : changelog
89+ GITHUB_TOKEN : ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
90+
91+ # If there's no changelog, add a generic comment to the PR
92+ - name : Comment on PR (no changelog)
93+ if : ${{ hashFiles('changelog') == '' }}
94+ env :
95+ DEPLOY_URL : ${{ steps.get-deploy-url.outputs.deploy-url }}
6496 uses : marocchino/sticky-pull-request-comment@v2
6597 with :
6698 number : ${{ steps.get-deploy-id.outputs.deploy-id }}
99+ header : docs-pr-changes
67100 message : |
68- This PR includes documentation updates.
101+ Looks like you've updated the documentation!
69102
70- You can view the updated docs at https://${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ steps.get-deploy-id.outputs.deploy-id }}.surge.sh
103+ Check out your changes at https://${{ env.DEPLOY_URL }}
71104 GITHUB_TOKEN : ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
0 commit comments