-
Notifications
You must be signed in to change notification settings - Fork 5
64 lines (57 loc) · 2.65 KB
/
surge-pr-fork-02-deploy.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
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: Debug step
run: |
echo "workflow_run.workflow_id: ${{github.event.workflow_run.workflow_id}}"
echo "workflow_run.id: ${{github.event.workflow_run.id}}"
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)}}"
- name: download dist artifact
uses: dawidd6/action-download-artifact@v7
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: pr-build-dist # must be kept in sync with the artifact name downloaded in the build stage
path: site/
# 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 "workflow_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
teardown: false # the teardown is managed in another workflow