Skip to content

Preview doc in PRs #134

Preview doc in PRs

Preview doc in PRs #134

name: Preview doc in PRs
on:
workflow_run:
workflows: ["Build documentation"]
types:
- completed
jobs:
pr_doc_preview:
runs-on: ubuntu-latest
if: ${{github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'}}
steps:
- name: 'Commit Status: Set Workflow Status as Pending'
uses: myrotvorets/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
sha: ${{ github.event.workflow_run.head_sha }}
context: 'Doc preview'
- uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: push_doc.yml
run_id: ${{ github.event.workflow_run.id }}
name: doc-preview
- name: Get pull request number
id: pull-request-number
run: |
export PULL_REQUEST_NUMBER=`cat pull_request_number`
echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER"
echo "result=${PULL_REQUEST_NUMBER}" >> $GITHUB_OUTPUT
- uses: actions/setup-node@v3
with:
node-version: '16'
- run: npm install --global netlify-cli@6
- name: Deploy to Netlify
# The github secrets hold a Personal Access Token (PAT) managed by
# ogrisel on Netlify. I should allow to programmatically upload doc
# previews under the hazardous-doc.netlify.app domain.
#
# The netlify site id can be inspected from the CLI using:
# netlify sites:list
env:
NETLIFY_SITE_ID: ${{secrets.NETLIFY_SITE_ID}}
NETLIFY_AUTH_TOKEN: ${{secrets.NETLIFY_AUTH_TOKEN}}
run: |
echo "Deploying PR ${{steps.pull-request-number.outputs.result}} to Netlify"
netlify deploy --dir=build --alias=pull-request-${{steps.pull-request-number.outputs.result}}
- name: 'Commit Status: Update deployment status'
uses: myrotvorets/[email protected]
# Always run this step regardless of job failing early
if: always()
env:
DEPLOY_SUCCESS: Successfully deployed preview.
DEPLOY_FAILURE: Failed to deploy preview.
TARGET_URL_SUCCESS: https://pull-request-${{steps.pull-request-number.outputs.result}}--hazardous-doc.netlify.app/
TARGET_URL_FAILURE: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status == 'success' && 'success' || 'failure' }}
sha: ${{ github.event.workflow_run.head_sha }}
context: 'Doc preview'
description: ${{ job.status == 'success' && env.DEPLOY_SUCCESS || env.DEPLOY_FAILURE }}
targetUrl: ${{ job.status == 'success' && env.TARGET_URL_SUCCESS || env.TARGET_URL_FAILURE }}