-
Notifications
You must be signed in to change notification settings - Fork 4
113 lines (102 loc) · 3.98 KB
/
pull-request-preview-cleanup.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
# Remove preview from surge
# see `pull-request-preview.yml` for more context
name: Clean up pull request surge preview
on:
pull_request_target:
types: [closed]
# permissions:
# contents: read
# deployments: write
# pull-requests: write
# statuses: write
# issues: write
jobs:
cleanup:
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: list deployments
# id: list_deployments
# uses: octokit/[email protected]
# with:
# route: GET /repos/:repository/deployments
# repository: ${{ github.repository }}
# ref: ${{ fromJson(steps.get_pull_request_ref.outputs.data).head.ref }}
# environment: dev
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# - name: get deployment
# id: get_deployment
# uses: octokit/[email protected]
# with:
# route: GET /repos/:repository/deployments/:deployment
# repository: ${{ github.repository }}
# deployment: ${{ fromJson(steps.list_deployments.outputs.data)[0].id }}
# ref: ${{ fromJson(steps.get_pull_request_ref.outputs.data).head.ref }}
# environment: dev
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# cleanup goes here
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: npm install -g surge
- name: teardown from surge
run: surge teardown --token "${{ secrets.SURGE_TOKEN }}" --domain "liputenpotest-${{ github.event.number }}.surge.sh"
# we cannot delete the deployment as one must exist in the dev environment
# we could change its status but I will just leave it for now
# - name: delete deployment
# id: delete_deployment
# uses: octokit/[email protected]
# with:
# route: DELETE /repos/:repository/deployments/:deployment
# repository: ${{ github.repository }}
# deployment: ${{ fromJson(steps.list_deployments.outputs.data)[0].id }}
# 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: "removed the deployment on <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: removed the deployment on <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: removed the deployment on <https://liputenpotest-${{ github.event.number }}.surge.sh>
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"