Deploy docs preview #2629
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use this starter workflow to deploy HTML generated by Antora to surge.sh | |
# Docs are published at <org>-<repo>-<deployid>.surge.sh | |
# | |
# By default, this workflow runs on completion of a workflow called "Verify docs PR" | |
# | |
# This workflow expects the triggering workflow to generate an artifact called "docs" | |
# - update the reference to "docs" and "docs.zip" in this workflow if your triggering workflow generates an artifact with a different name | |
# change to force workflow with no changelog | |
name: "Deploy docs preview" | |
on: | |
workflow_run: | |
workflows: ["Verify docs PR"] | |
types: | |
- completed | |
jobs: | |
publish-docs: | |
# Uncomment this if statement to deploy only when the PR builds cleanly | |
# if: github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Download built documentation" | |
uses: actions/github-script@v7 | |
env: | |
RUN_ID: ${{ github.event.workflow_run.id }} | |
WORKSPACE: ${{ github.workspace }} | |
with: | |
script: | | |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{ env.RUN_ID }}, | |
}); | |
var matchArtifactDocs = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "docs" | |
})[0]; | |
var downloadDocs = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifactDocs.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{ env.WORKSPACE }}/docs.zip', Buffer.from(downloadDocs.data)); | |
var matchArtifactChangelog = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "changelog" | |
})[0]; | |
var downloadChangelog = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifactChangelog.id, | |
archive_format: 'zip', | |
}); | |
fs.writeFileSync('${{ env.WORKSPACE }}/changelog.zip', Buffer.from(downloadChangelog.data)); | |
- id: unzip-docs | |
run: unzip docs.zip | |
- id: get-top-dir | |
run: | | |
root=$(ls -d */index.html | sed -r 's/(.*)\/index\.html/\1/') | |
echo "top-dir=$root" >> $GITHUB_OUTPUT | |
- id: unzip-changelog | |
if: ${{ hashFiles('changelog.zip') != '' }} | |
run: unzip changelog.zip | |
- id: get-deploy-id | |
run: | | |
deployid=$(<deployid) | |
case "$deployid" in ''|*[!0-9]*) echo "Provided PR number is not an integer"; exit 1 ;; esac | |
echo "deploy-id=$deployid" >> "$GITHUB_OUTPUT" | |
- id: get-deploy-url | |
env: | |
ORG: ${{ github.event.repository.owner.login }} | |
REPO: ${{ github.event.repository.name }} | |
DEPLOYID: ${{ steps.get-deploy-id.outputs.deploy-id }} | |
run: | | |
deployurl=$ORG-$REPO-$DEPLOYID.surge.sh | |
echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: lts/* | |
- name: Deploy docs to surge | |
shell: bash | |
env: | |
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }} | |
SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}" | |
SITE_DIR: ${{ steps.get-top-dir.outputs.top-dir }} | |
run: | | |
npm install -g surge | |
surge ./$SITE_DIR $DEPLOY_URL --token "$SURGE_TOKEN" | |
# If the PR artifacts include a changelog file, add it to the PR as a comment | |
# The changelog contains links to new and changed files in the deployed docs | |
- name: Comment on PR (changelog) | |
if: ${{ hashFiles('changelog') != '' }} | |
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0 | |
with: | |
number: ${{ steps.get-deploy-id.outputs.deploy-id }} | |
recreate: true | |
header: docs-pr-changes | |
path: changelog | |
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }} | |
# If there's no changelog, add a generic comment to the PR | |
- name: Comment on PR (no changelog) | |
if: ${{ hashFiles('changelog') == '' }} | |
env: | |
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }} | |
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0 | |
with: | |
number: ${{ steps.get-deploy-id.outputs.deploy-id }} | |
header: docs-pr-changes | |
message: | | |
Looks like you've updated the documentation! | |
Check out your changes at https://${{ env.DEPLOY_URL }} | |
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }} |