Surge PR Preview - Deploy Stage #15
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: Surge PR Preview - Deploy Stage | |
on: | |
workflow_run: | |
workflows: ["Surge PR Preview - Build Stage"] | |
types: | |
- completed | |
permissions: | |
pull-requests: write # surge-preview creates or updates PR comments about the deployment status | |
jobs: | |
# MUST be unique across all surge preview deployments for a repository as the job id is used in the deployment URL | |
# MUST be kept in sync with the job id of the teardown stage (used in the deployment URL) | |
deploy: | |
runs-on: ubuntu-22.04 | |
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: download dist artifact | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
name: pr-build-dist # must be kept in sync with the artifact name downloaded in the build stage | |
path: site/ | |
- name: Debug step | |
run: | | |
echo "workflow_run.head_sha: ${{github.event.workflow_run.head_sha}}" | |
# the following commands used for debug generates an error when run in bash script | |
# echo "workflow_run: ${{toJSON(github.event.workflow_run)}}" | |
# https://github.com/orgs/community/discussions/25220#discussioncomment-8697399 | |
# This is what surge-preview uses to find the related PR number when the workflow is triggered by a "worflow_run" event | |
# - name: Find associated pull request | |
# id: pr | |
# uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 | |
# with: | |
# script: | | |
# const response = await github.rest.search.issuesAndPullRequests({ | |
# q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', | |
# per_page: 1, | |
# }) | |
# const items = response.data.items | |
# if (items.length < 1) { | |
# console.error('No PRs found') | |
# return | |
# } | |
# const pullRequestNumber = items[0].number | |
# console.info("Pull request number is", pullRequestNumber) | |
# return pullRequestNumber | |
- name: Manage Surge deployment | |
uses: afc163/surge-preview@v1 | |
with: | |
surge_token: ${{ secrets.SURGE_TOKEN }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
build: echo done | |
dist: site | |
failOnError: true |