Skip to content

Surge PR Preview - Deploy Stage #2

Surge PR Preview - Deploy Stage

Surge PR Preview - Deploy Stage #2

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:
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@v3
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: ${{toJSON(github.event.workflow_run)}}"
echo "workflow_run.head_sha: ${{github.event.workflow_run.head_sha}}"
# https://github.com/orgs/community/discussions/25220#discussioncomment-8697399
# - 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
# experiment a custom action that supports workflow_run, using the GH API as the commented step above
# TODO can we also manage the teardown of the deployment in case of workflow_run?
# uses: afc163/surge-preview@v1
uses: benjaminParisel/surge-preview@feat/adding_pr_number_parameter
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
build: echo done
dist: site