-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (83 loc) · 3.84 KB
/
pr_preview_netlify.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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.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 }}