Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Deploy PR docs to GitHub Pages #168

Deploy PR docs to GitHub Pages

Deploy PR docs to GitHub Pages #168

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@891cccee4b25d3306cf5edafa174ddc1d969871f
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@891cccee4b25d3306cf5edafa174ddc1d969871f
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@bbdfb200618d235585ad98e965f4aafc39b4c501
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@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
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 }}/'
});