generated from cloudposse-github-actions/composite-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
155 lines (142 loc) · 4.95 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: 'Environments - ArgoCD'
description: 'Get information about environment'
inputs:
environment:
description: "Environment"
required: true
namespace:
description: Kubernetes namespace
required: true
application:
description: "The application name"
required: false
config:
description: "configuration"
required: true
namespace-prefix:
description: Kubernetes namespace prefix
required: false
default: ''
namespace-suffix:
description: Kubernetes namespace suffix
required: false
default: ''
namespace-deny-list:
description: Kubernetes namespace deny list, generated names cannot contain this comma separated list.
required: false
default: kube-system,kube-public,default
outputs:
name:
description: "Environment name"
value: ${{ inputs.environment }}
role:
description: "Environments that need to be deployed"
value: ${{ steps.result.outputs.cluster-role }}
cluster:
description: "Environments that need to be destroyed"
value: ${{ steps.result.outputs.cluster }}
namespace:
description: "Namespace"
value: ${{ steps.result.outputs.namespace }}
ssm-path:
description: "Path to ssm secrets"
value: ${{ steps.result.outputs.ssm-path }}
environment-config:
description: "Environment configuration"
value: ${{ steps.json-to-yaml.outputs.output }}
runs:
using: "composite"
steps:
- uses: actions/checkout@v3
- run: |
echo '''${{ inputs.config }}''' > config.yml
shell: bash
- uses: fabasoad/[email protected]
id: yaml-to-json
with:
input: "config.yml"
from: "yaml"
to: "json"
- name: Evaluate Config
id: parse-config
uses: actions/github-script@v6
with:
script: |
let data = JSON.parse(`${{ steps.yaml-to-json.outputs.output }}`);
let environment = '${{ inputs.environment }}';
for(const [environment, config] of Object.entries(data)) {
if(environment === '${{ inputs.environment }}') {
for(const [key, value] of Object.entries(config)) {
// Support `|` Operations
let operation = '';
let new_value = '';
if(String(value).includes('|')) {
new_value = value.split('|')[0].trim()
operation = value.split('|')[1].trim()
}
switch(operation) {
case 'kebab':
case 'kebabcase':
case 'toKebab':
new_value = new_value.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_/]+/g, '-').toLowerCase()
break;
case 'upper':
case 'uppercase':
case 'toUpper':
new_value = new_value.toLowerCase()
break;
case 'lower':
case 'lowercase':
case 'toLower':
new_value = new_value.toLowerCase()
break;
default:
new_value = new_value
}
if(new_value !== '') {
data[environment][key] = new_value;
}
if(key === 'reformat') {
core.setOutput('reformat', value);
delete data[environment][key];
}
}
}
}
core.setOutput('stripped-config', JSON.stringify(data[environment]));
- name: Reformat
if: ${{ steps.parse-config.outputs.reformat }}
uses: cloudposse/kubernetes-namespace-builder-composite-action@main
id: reformat
with:
flavor: ${{ steps.parse-config.outputs.reformat }}
app-name: ${{ inputs.application }}
prefix: ${{ inputs.namespace-prefix }}
suffix: ${{ inputs.namespace-suffix }}
deny-list: ${{ inputs.namespace-deny-list }}
override-branch-name: ${{ inputs.namespace }}
- name: Merge Substitutions
id: merge-config
uses: actions/github-script@v6
with:
script: |
let data = JSON.parse(`${{ steps.parse-config.outputs.stripped-config }}`);
if('${{ steps.parse-config.outputs.reformat }}') {
data['namespace'] = '${{ steps.reformat.outputs.kubernetes-namespace }}';
}
core.setOutput('merged-config', JSON.stringify(data));
- run: |
echo '''${{ steps.merge-config.outputs.merged-config }}''' > merged-config.json
shell: bash
- uses: fabasoad/[email protected]
id: json-to-yaml
with:
input: "merged-config.json"
from: "json"
to: "yaml"
- name: Environment info
uses: cloudposse/[email protected]
id: result
with:
query: .
config: ${{ steps.json-to-yaml.outputs.output }}