Skip to content

Deploy PR docs to GitHub Pages #174

Deploy PR docs to GitHub Pages

Deploy PR docs to GitHub Pages #174

name: Deploy PR docs to GitHub Pages
on:
workflow_run:
workflows:
- 'Build docs from a pull request'
types:
- completed
jobs:
deploy-built-docs:
name: Deploy built docs to GitHub Pages
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download the docs artifact πŸ“₯
uses: dawidd6/action-download-artifact@a430ac5786b39ad5869da25a98130624d2ce340c
with:
workflow: build-pr-docs.yml
commit: ${{ github.event.workflow_run.head_sha }}
name: docs
path: ./docs
- name: Download the PR number artifact πŸ“₯
uses: dawidd6/action-download-artifact@a430ac5786b39ad5869da25a98130624d2ce340c
with:
workflow: build-pr-docs.yml
name: pr_number
- name: Add PR number to environment 🌎
run: echo "PR_NUMBER=$(cat pr_number.txt)" >> $GITHUB_ENV
- name: Publish πŸš€
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs
destination_dir: ${{ env.PR_NUMBER }}
keep_files: true
- name: Post the URL on the PR πŸ–Š
uses: actions/github-script@v7
with:
script:
| # yeah, I know it's weird how you get PR comments with `.issues`
const prComments = (await github.issues.listComments({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
})).data;
const docsURL = /Docs available on https:\/\/illright\.github\.io\/attractions\/\d+\//;
if (prComments.find(
comment => comment.user.login === 'github-actions[bot]' && docsURL.test(comment.body)
) != null) {
return;
}
await github.issues.createComment({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Docs available on https://illright.github.io/attractions/${{ env.PR_NUMBER }}/'
});