👀 PR Preview #48
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
name: "👀 PR Preview" | |
# Inspired from: https://github.com/docker-mailserver/docker-mailserver/blob/master/.github/workflows/docs-preview-deploy.yml | |
on: | |
workflow_run: | |
workflows: | |
- "Pull Request Checker 🛃" | |
types: | |
- completed | |
jobs: | |
preview-netlify: | |
name: "⌛ Site temporaire sur Netlify" | |
runs-on: ubuntu-latest | |
if: "${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}" | |
steps: | |
# =============================== # | |
# Restore parent workflow context # | |
# =============================== # | |
- name: Download artifact from build workflow | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
name: pr-build-website | |
run_id: ${{ github.event.workflow_run.id }} | |
workflow: pr_checker_build.yml | |
- name: "Extract build artifact" | |
run: tar -xf artifact.tar.zst | |
- name: "Restore preserved ENV" | |
run: cat pr.env >> "${GITHUB_ENV}" | |
# ==================== # | |
# Deploy preview build # | |
# ==================== # | |
# Manage workflow deployment status. `enable-commit-status` from `nwtgck/actions-netlify` would handle this, | |
# but presently does not work correctly via split workflow. It is useful in a split workflow as the 1st stage | |
# no longer indicates if the entire workflow/deployment was successful. | |
- name: "Commit Status: Set Workflow Status as Pending" | |
uses: myrotvorets/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: pending | |
# Should match `env.PR_HEADSHA` when triggered by `pull_request` event workflow, | |
# Avoids failure of ENV being unavailable if job fails early: | |
sha: ${{ github.event.workflow_run.head_sha }} | |
context: "Deploy Preview (pull_request => workflow_run)" | |
- name: Deploy preview to Netlify | |
uses: nwtgck/[email protected] | |
id: preview | |
timeout-minutes: 10 | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
NETLIFY_SITE_PREFIX: geotribu-english-${{ env.PR_NUMBER }} | |
with: | |
alias: ${{ env.NETLIFY_SITE_PREFIX }} | |
deploy-message: "Deploy preview of PR ${{ env.PR_TITLE }} (PR #${{ env.PR_NUMBER }} @ commit: ${{ env.PR_HEADSHA }})" | |
enable-commit-comment: false | |
enable-commit-status: false | |
enable-pull-request-comment: false | |
fails-without-credentials: true | |
github-deployment-environment: pr-previews | |
github-deployment-description: "Preview deploy for PRs" | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
overwrites-pull-request-comment: true | |
production-deploy: false | |
publish-dir: ${{ env.BUILD_DIR }} | |
- name: "Comment on PR: Add/Update deployment status" | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
number: ${{ env.PR_NUMBER }} | |
recreate: true | |
message: | | |
:tada: The preview site for this PR has been generated and is [available here](${{ steps.preview.outputs.deploy-url }}). | |
Reference commit : ${{ env.PR_HEADSHA }}. | |
- 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. | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status == 'success' && 'success' || 'failure' }} | |
sha: ${{ github.event.workflow_run.head_sha }} | |
context: "Deploy Preview (pull_request => workflow_run)" | |
description: ${{ job.status == 'success' && env.DEPLOY_SUCCESS || env.DEPLOY_FAILURE }} |