-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (150 loc) · 6.12 KB
/
Copy pathdeploy-finish.yml
File metadata and controls
166 lines (150 loc) · 6.12 KB
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
162
163
164
165
166
# Reusable workflow that performs the end of a deployment.
#
# What this workflow does:
#
# - If the deployment exposes a URL, run [deploy checks](./deploy-checks.md):
# - Update the GitHub deployment status (success or failure).
# - Publish a human-readable deployment summary using the deploy/report action.
# See [report](../../actions/deploy/report/README.md).
# - Lighthouse report URL if available.
# - Extra information if provided.
---
name: Deploy - Finish
on:
workflow_call:
inputs:
runs-on:
description: |
JSON array of runner(s) to use.
See https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job.
type: string
default: '["ubuntu-latest"]'
required: false
deployment-id:
description: |
Deployment ID to use for the deployment.
See https://docs.github.com/en/rest/deployments/deployments?apiVersion=2022-11-28#list-deployments.
type: string
required: true
budget-path:
description: |
Path to the budget file to use for the Lighthouse check.
See [`url-lighthouse`](../../actions/check/url-lighthouse/README.md).
type: string
required: false
default: "./budget.json"
extra:
description: |
Extra information to send to the deployment summary.
Should be a JSON object.
type: string
required: false
permissions: {}
jobs:
get-finished-deployment:
name: Get finished deployment
runs-on: ${{ fromJson(inputs.runs-on) }}
permissions:
actions: read
deployments: read
outputs:
url: ${{ steps.get-finished-deployment.outputs.url }}
environment: ${{ steps.get-finished-deployment.outputs.environment }}
steps:
- id: local-workflow-actions
uses: hoverkraft-tech/ci-github-common/actions/local-workflow-actions@7034f6ae5bae1ec46a0108e8efb60d102e88961d # 0.37.2
with:
actions-path: actions
- id: get-workflow-failure
if: ${{ inputs.deployment-id }}
uses: ./../self-workflow/actions/workflow/get-workflow-failure
with:
github-token: ${{ secrets.github-token || github.token }} # zizmor: ignore[secrets-outside-env] reusable workflow token override is intentional
- id: get-finished-deployment
if: ${{ inputs.deployment-id && steps.get-workflow-failure.outputs.has-failed != 'true' }}
uses: ./../self-workflow/actions/deployment/get-finished
with:
deployment-id: ${{ inputs.deployment-id }}
deploy-checks:
name: Deploy checks
needs: get-finished-deployment
if: ${{ needs.get-finished-deployment.outputs.url }}
uses: ./.github/workflows/deploy-checks.yml
permissions:
contents: read
with:
runs-on: ${{ inputs.runs-on }}
url: ${{ needs.get-finished-deployment.outputs.url }}
budget-path: ${{ inputs.budget-path }}
print-summary: false
deploy-result:
name: Deploy result
if: always()
needs: [get-finished-deployment, deploy-checks]
runs-on: ${{ fromJson(inputs.runs-on) }}
permissions:
actions: read
deployments: write
issues: write
pull-requests: write
steps:
- id: get-extra
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
INPUT_EXTRA: ${{ inputs.extra }}
SUMMARY_OUTPUT: ${{ toJson(needs.deploy-checks.outputs.summary) }}
with:
script: |
const extraInput = process.env.INPUT_EXTRA.trim();
let extra = null;
if (extraInput) {
// Check if is valid JSON
try {
extra = JSON.parse(extraInput);
} catch (error) {
return core.setFailed(`"extra" input is not a valid JSON: ${error}`);
}
if (!extra || typeof extra !== 'object') {
return core.setFailed(`"extra" input is not a valid JSON object.`);
}
}
const deployChecksSummaryOutput = process.env.SUMMARY_OUTPUT.trim();
let deployChecksSummary = null;
if (deployChecksSummaryOutput) {
try {
deployChecksSummary = JSON.parse(deployChecksSummaryOutput);
} catch (error) {
return core.setFailed(`"deploy-checks" job summary output is not a valid JSON: ${error}`);
}
}
if (deployChecksSummary) {
// jscpd:ignore-start
const toSentence = (str) => {
return str
.replace(/([A-Z])/g, ' $1') // Insert space before capital letters
.replace(/-([a-z])/gi, (match, letter) => ` ${letter.toUpperCase()}`) // Replace hyphens with spaces and Uppercase next letter
.replace(/^./, function(char) { return char.toUpperCase(); }) // Capitalize the first letter
.trim();
};
// jscpd:ignore-end
extra = extra || {};
for(const [key, value] of Object.entries(deployChecksSummary["reportSummary"] || {})) {
const value = {};
for(const [metricKey, metricValue] of Object.entries(value)) {
value[toSentence(metricKey)] = metricValue;
}
extra[toSentence(key)] = value;
}
}
return core.setOutput("extra", JSON.stringify(extra));
- id: local-workflow-actions
uses: hoverkraft-tech/ci-github-common/actions/local-workflow-actions@7034f6ae5bae1ec46a0108e8efb60d102e88961d # 0.37.2
with:
actions-path: actions
- uses: ./../self-workflow/actions/deploy/report
with:
deployment-id: ${{ inputs.deployment-id }}
environment: ${{ needs.get-finished-deployment.outputs.environment }}
url: ${{ needs.get-finished-deployment.outputs.url }}
extra: ${{ steps.get-extra.outputs.extra }}
github-token: ${{ secrets.github-token || github.token }} # zizmor: ignore[secrets-outside-env] reusable workflow token override is intentional