-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
87 lines (84 loc) · 2.99 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
name: 'Terraform Plan Summary'
description: "Summarizes a json terraform plan"
inputs:
json-tf-plan:
description: Path to json terraform plan file
required: true
environment:
description: Environment where plan is being run. Populate this to help distinguish between multiple environments in a single workflow
default: ""
required: false
outputs:
no-op-count:
description: Count of resources with no change
update-count:
description: Count of resources to update
delete-count:
description: Count of resource to delete
runs:
using: 'composite'
steps:
- run: env
shell: bash
- uses: actions/github-script@v7
with:
script: |
const plan = require("${{ inputs.json-tf-plan }}");
let actionMap = {}
if (plan.resource_changes) {
for (resource of plan.resource_changes) {
const actions = resource.change.actions.join(",")
if (!actionMap.hasOwnProperty(actions)) {
actionMap[actions] = []
}
actionMap[resource.change.actions.join(",")].push(resource.address)
}
}
//console.log(actionMap);
function capitalize(s) {
return s[0].toUpperCase() + s.substring(1);
}
let summaryCounts = ""
let summaryTable = [[{data: 'Action', header: true}, {data: 'Count', header: true}]]
for (const [action, resources] of Object.entries(actionMap)) {
let pluralString = "s"
if (resources.length == 1) {
pluralString = ""
}
let emoji = ""
if (action.includes('update')) {
emoji = '⬆️'
} else if (action.includes('create')) {
emoji = '🆕'
} else if (action.includes('delete')) {
emoji = '❌'
} else if (action.includes('no-op')) {
emoji = '🟰'
}
const row = [`${emoji} ${capitalize(action)}`,` ${resources.length} resource${pluralString}`];
summaryTable.push(row);
}
console.log(summaryTable)
let summary = core.summary
.addHeading('${{ inputs.environment }} Terraform Plan')
.addTable(summaryTable)
.addRaw('<details><summary>Resources</summary>')
let noOpCount, updateCount, deleteCount = 0
for (const [action, resources] of Object.entries(actionMap)) {
if (action != "no-op") {
summary.addHeading(capitalize(action), 3);
summary.addList(resources);
}
// Generate outputs
if (action.includes("no-op")) {
noOpCount = noOpCount + 1
}
if (action.includes("update")) {
updateCount = updateCount + 1
}
if (action.includes("delete")) {
deleteCount = deleteCount + 1
}
}
summary.addRaw('</details>')
.write()