-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
133 lines (121 loc) · 4.56 KB
/
action.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
name: PR Preview Deploys
description: Easy PR Preview Deploy UX
inputs:
step:
description: start, finish, or cleanup
required: true
env:
description: Environment
required: true
env_url:
description: Environment URL. Required during 'finish' step.
head_ref:
description: "`github.head_ref`. Required during 'start' step."
status:
description: "`job.status`. Required during 'finish' step."
deployment_id:
description: Required during 'finish' step.
app_id:
description: |
ID of a GitHub App installed on this repo with repo Administration permissions.
Required during 'cleanup' step.
default: ""
private_key:
description: |
Private Key from the above GitHub App installation.
Required during 'cleanup' step.
default: ""
token:
description: |
A Github token. `secrets.GITHUB_TOKEN`` is fine for start and finish steps.
default: ""
log_url_job_name:
description: |
Name of the step to use for the Deployment's log URL. Case-insensitive.
Defaults to using the workflow summary url.
default: ''
outputs:
deployment_id:
description: "ID of deployment created during start step."
value: ${{ steps.deployment.outputs.deployment_id }}
runs:
using: "composite"
steps:
- name: Get token
if: ${{ inputs.token == '' && inputs.app_id != '' && inputs.private_key != '' }}
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 # v1.8.0
id: token
with:
app_id: ${{ inputs.app_id || 'unset' }}
private_key: ${{ inputs.private_key || 'unset' }}
- name: Determine deployment log URL
if: ${{ inputs.step == 'start' || inputs.step == 'finish' }}
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
id: job-url
env:
JOB_NAME: ${{ inputs.log_url_job_name }}
with:
script: |
const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRunAttempt, {
...context.repo,
run_id: context.runId,
attempt_number: process.env.GITHUB_RUN_ATTEMPT,
});
const matching = jobs.find(job => job.name.toLowerCase() == process.env.JOB_NAME.toLowerCase())?.html_url;
if (matching !== undefined) {
return matching;
}
// if we didn't find the right job, pop the last two portions
// of the url off to get the summary of the workflow
const last = jobs.pop().html_url.split("/");
last.pop();
last.pop();
return last.join("/");
result-encoding: string
- name: Start deployment
if: ${{ inputs.step == 'start' }}
uses: bobheadxi/deployments@88ce5600046c82542f8246ac287d0a53c461bca3 # v1.4.0
id: deployment
with:
step: start
token: ${{ steps.token.outputs.token != '' && steps.token.outputs.token || inputs.token }}
ref: ${{ inputs.head_ref }}
logs: ${{ steps.job-url.outputs.result }}
env: ${{ inputs.env }}
override: false
- name: Finish deployment
if: ${{ inputs.step == 'finish' }}
uses: bobheadxi/deployments@88ce5600046c82542f8246ac287d0a53c461bca3 # v1.4.0
with:
step: finish
token: ${{ steps.token.outputs.token != '' && steps.token.outputs.token || inputs.token }}
ref: ${{ inputs.head_ref }}
logs: ${{ steps.job-url.outputs.result }}
deployment_id: ${{ inputs.deployment_id }}
status: ${{ inputs.status }}
env: ${{ inputs.env }}
override: false
auto_inactive: true
env_url: ${{ inputs.env_url }}
- name: Mark deployments as deactivated
if: ${{ inputs.step == 'cleanup' }}
uses: bobheadxi/deployments@88ce5600046c82542f8246ac287d0a53c461bca3 # v1.4.0
with:
step: deactivate-env
token: ${{ steps.token.outputs.token != '' && steps.token.outputs.token || inputs.token }}
env: ${{ inputs.env }}
desc: PR was closed
- name: Delete environment
if: ${{ inputs.step == 'cleanup' }}
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
env:
ENVIRONMENT_TO_DELETE: ${{ inputs.env }}
with:
github-token: "${{ steps.token.outputs.token }}"
result-encoding: string
script: |
const { data } = await github.rest.repos.deleteAnEnvironment({
...context.repo,
environment_name: process.env.ENVIRONMENT_TO_DELETE
});
console.log(data);