-
Notifications
You must be signed in to change notification settings - Fork 4
161 lines (148 loc) · 5.88 KB
/
pull-request-preview.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# Deploy pull requests to surge, so multiple previews can exist at once
# The deployments API is used to make the deployments visible in the pull request
# https://surge.sh/
# to install surge:
# $ npm install --global surge
# to log in to surge or create an account, run
# $ surge
# to publish a folder as a static site, run
# $ surge --project <folder> --domain <example28928.surge.sh>
# or
# $ surge <folder>
# to remove a site, run
# $ surge teardown <example28928.surge.sh>
# to list active sites, run
# $ surge list
# this workflow requires one secret: SURGE_TOKEN, generated with
# $ surge token
# note: the PDFs are not deployed, as they turn a ~60mb site into a ~600mb site.
# workflow modified from https://sanderknape.com/2020/05/deploy-pull-requests-github-actions-deployments/
name: Deploy pull request preview to surge
on:
pull_request_target:
types: [opened, reopened, synchronize]
permissions:
contents: read
# deployments: write
pull-requests: write
statuses: write
issues: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# - name: get pull request ref
# id: get_pull_request_ref
# uses: octokit/[email protected]
# with:
# route: GET /repos/:repository/pulls/:issue_id
# repository: ${{ github.repository }}
# issue_id: ${{ github.event.number }}
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# - name: create deployment
# id: create_deployment
# uses: octokit/[email protected]
# with:
# route: POST /repos/:repository/deployments
# repository: ${{ github.repository }}
# ref: ${{ github.event.pull_request.base.ref }}
# environment: dev
# auto_merge: false
# required_contexts: "[]"
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# - name: set deployment status to in progress
# id: start_deployment
# uses: octokit/[email protected]
# with:
# route: POST /repos/:repository/deployments/:deployment/statuses
# repository: ${{ github.repository }}
# deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
# environment: dev
# log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
# state: in_progress
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# deployment goes here
- name: Checkout
uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.ref }}"
repository: "${{ github.event.pull_request.head.repo.full_name }}"
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build with Eleventy
run: npm run build
- name: Remove pdfs (filesize restraints)
run: rm _site/pdfs/*.pdf
- name: Install surge
run: npm install -g surge
- name: deploy to surge
run: surge --token "${{ secrets.SURGE_TOKEN }}" --project _site --domain liputenpotest-${{ github.event.number }}.surge.sh
# - name: set deployment status to success
# id: successful_deployment
# uses: octokit/[email protected]
# with:
# route: POST /repos/:repository/deployments/:deployment/statuses
# repository: ${{ github.repository }}
# deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
# environment: dev
# environment_url: https://liputenpotest-${{ github.event.number }}.surge.sh
# log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
# state: success
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# - name: set deployment status to failure
# id: failed_deployment
# uses: octokit/[email protected]
# if: failure()
# with:
# route: POST /repos/:repository/deployments/:deployment/statuses
# repository: ${{ github.repository }}
# deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
# environment: dev
# log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
# state: failure
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# - name: Send confirmation
# id: send_confirmation
# uses: octokit/[email protected]
# with:
# route: POST /repos/:repository/issues/:issue_id/comments
# repository: ${{ github.repository }}
# issue_id: ${{ github.event.number }}
# body: "surge: deployed to <https://liputenpotest-${{ github.event.number }}.surge.sh>"
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "surge: "
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
surge: deployed to <https://liputenpotest-${{ github.event.number }}.surge.sh>
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
surge: deployed to <https://liputenpotest-${{ github.event.number }}.surge.sh>
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"