Skip to content

👀 PR Preview

👀 PR Preview #4755

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
env:
LANG: "fr_FR.UTF-8"
LC_ALL: "fr_FR.UTF-8"
LC_TIME: "fr_FR.UTF-8"
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 }}
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: Le site de prévisualisation pour cette PR a été généré et est [disponible sous ce lien](${{ steps.preview.outputs.deploy-url }}).
Commit de référence : ${{ 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 }}