61 lines
2.2 KiB
YAML
61 lines
2.2 KiB
YAML
name: Deploy PR to Netlify
|
|
run-name: "Deploy PR to Netlify (${{ github.event.workflow_run.head_branch }})"
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["Build pull request"]
|
|
types: [completed]
|
|
|
|
jobs:
|
|
deploy-pull-request:
|
|
name: Deploy pull request
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
steps:
|
|
- name: Download pr number
|
|
uses: dawidd6/action-download-artifact@d63b86af1b34672e53c440b1b83979861906bad7 # v24
|
|
with:
|
|
workflow: ${{ github.event.workflow.id }}
|
|
run_id: ${{ github.event.workflow_run.id }}
|
|
name: pr
|
|
- name: Validate and output pr number
|
|
id: pr
|
|
run: |
|
|
PR_ID=$(<pr.txt)
|
|
if ! [[ "${PR_ID}" =~ ^[0-9]+$ ]]; then
|
|
echo "::error::pr.txt contains non-numeric content: ${PR_ID}"
|
|
exit 1
|
|
fi
|
|
echo "id=${PR_ID}" >> "${GITHUB_OUTPUT}"
|
|
- name: Download artifact
|
|
uses: dawidd6/action-download-artifact@d63b86af1b34672e53c440b1b83979861906bad7 # v24
|
|
with:
|
|
workflow: ${{ github.event.workflow.id }}
|
|
run_id: ${{ github.event.workflow_run.id }}
|
|
name: preview
|
|
path: dist
|
|
- name: Deploy to Netlify
|
|
id: netlify
|
|
uses: nwtgck/actions-netlify@d22a32a27c918fe470bbc562e984f80ec48c2668 # v4.0.0
|
|
with:
|
|
publish-dir: dist
|
|
deploy-message: "Deploy PR ${{ steps.pr.outputs.id }}"
|
|
alias: ${{ steps.pr.outputs.id }}
|
|
# These don't work because we're in workflow_run
|
|
enable-pull-request-comment: false
|
|
enable-commit-comment: false
|
|
env:
|
|
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN_PR }}
|
|
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID_PR_CINNY }}
|
|
timeout-minutes: 1
|
|
- name: Comment preview on PR
|
|
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5
|
|
with:
|
|
number: ${{ steps.pr.outputs.id }}
|
|
message: |
|
|
Preview: ${{ steps.netlify.outputs.deploy-url }}
|
|
⚠️ Exercise caution. Use test accounts. ⚠️
|