-
Notifications
You must be signed in to change notification settings - Fork 4
83 lines (75 loc) · 2.9 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
# 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 }}"