generated from cloudposse-github-actions/typescript-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
151 lines (139 loc) · 6.18 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
name: "Atmos GitOps Select Components"
description: "A GitHub Action to get list of selected components by jq query"
author: [email protected]
branding:
icon: "file"
color: "white"
inputs:
select-filter:
description: jq query that will be used to select atmos components
required: false
default: '.'
head-ref:
description: The head ref to checkout. If not provided, the head default branch is used.
required: false
default: ${{ github.sha }}
skip-checkout:
description: "Disable actions/checkout for head-ref. Useful for when the checkout happens in a previous step and file are modified outside of git through other actions"
required: false
default: 'false'
atmos-version:
description: The version of atmos to install
required: false
default: ">= 1.63.0"
atmos-config-path:
description: The path to the atmos.yaml file
required: true
jq-version:
description: The version of jq to install if install-jq is true
required: false
default: "1.7"
debug:
description: "Enable action debug mode. Default: 'false'"
default: 'false'
required: false
nested-matrices-count:
required: false
description: 'Number of nested matrices that should be returned as the output (from 1 to 3)'
default: "2"
outputs:
selected-components:
description: Selected GitOps components
value: ${{ steps.selected-components.outputs.components }}
has-selected-components:
description: Whether there are selected components
value: ${{ steps.selected-components.outputs.components != '[]' }}
matrix:
description: The selected components as matrix structure suitable for extending matrix size workaround (see README)
value: ${{ steps.matrix.outputs.matrix }}
runs:
using: "composite"
steps:
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/checkout@v4
if: ${{ inputs.skip-checkout != 'true' }}
with:
ref: ${{ inputs.head-ref }}
- uses: cloudposse-github-actions/install-gh-releases@v1
with:
cache: true
config: |-
jqlang/jq: jq-${{ inputs.jq-version }}
- name: Install Atmos
uses: cloudposse/github-action-setup-atmos@v2
env:
ATMOS_CLI_CONFIG_PATH: ${{inputs.atmos-config-path}}
with:
atmos-version: ${{ inputs.atmos-version }}
install-wrapper: false
- name: Set vars
shell: bash
run: |-
echo "ATMOS_CLI_CONFIG_PATH=$(realpath ${{ inputs.atmos-config-path }})" >> $GITHUB_ENV
- name: config
shell: bash
id: config
run: |-
echo "opentofu-version=$(atmos describe config -f json | jq -r '.integrations.github.gitops["opentofu-version"]')" >> $GITHUB_OUTPUT
echo "terraform-version=$(atmos describe config -f json | jq -r '.integrations.github.gitops["terraform-version"]')" >> $GITHUB_OUTPUT
echo "group-by=$(atmos describe config -f json | jq -r '.integrations.github.gitops.matrix["group-by"]')" >> $GITHUB_OUTPUT
echo "sort-by=$(atmos describe config -f json | jq -r '.integrations.github.gitops.matrix["sort-by"]')" >> $GITHUB_OUTPUT
echo "aws-region=$(atmos describe config -f json | jq -r '.integrations.github.gitops["artifact-storage"].region')" >> $GITHUB_OUTPUT
echo "terraform-plan-role=$(atmos describe config -f json | jq -r '.integrations.github.gitops.role.plan')" >> $GITHUB_OUTPUT
- name: Install Terraform
if: ${{ steps.config.outputs.terraform-version != '' && steps.config.outputs.terraform-version != 'null' }}
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ steps.config.outputs.terraform-version }}
terraform_wrapper: false
- name: Install OpenTofu
uses: cloudposse-github-actions/install-gh-releases@v1
if: ${{ steps.config.outputs.opentofu-version != '' && steps.config.outputs.opentofu-version != 'null' }}
with:
cache: true
config: |-
opentofu/opentofu:
tag: ${{ startsWith(steps.config.outputs.opentofu-version, 'v') && steps.config.outputs.opentofu-version || format('v{0}', steps.config.outputs.opentofu-version) }}
- name: Configure Plan AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
if: ${{ steps.config.outputs.aws-region != '' &&
steps.config.outputs.aws-region != 'null' &&
steps.config.outputs.terraform-plan-role != '' &&
steps.config.outputs.terraform-plan-role != 'null' }}
with:
aws-region: ${{ steps.config.outputs.aws-region }}
role-to-assume: ${{ steps.config.outputs.terraform-plan-role }}
role-session-name: "atmos-terraform-plan-gitops"
mask-aws-account-id: "no"
- name: Filter Components
id: selected-components
shell: bash
env:
JQUERY: |
with_entries(.value |= (.components.terraform)) | ## Deal with components type of terraform
map_values(map_values(select(${{ inputs.select-filter }}))) | ## Filter components by enabled github actions
map_values(select(. != {})) | ## Skip stacks that have 0 selected components
map_values(. | keys) | ## Reduce to component names
with_entries( ## Construct component object
.key as $stack |
.value |= map({
"component": .,
"stack": $stack,
"stack_slug": [$stack, .] | join("-")
})
) | map(.) | flatten ## Reduce to flat array
run: |
atmos describe stacks --format json | jq -ce "${JQUERY}" > components.json
components=$(cat components.json)
echo "Selected components: $components"
printf "%s" "components=$components" >> $GITHUB_OUTPUT
- uses: cloudposse/github-action-matrix-extended@v0
id: matrix
with:
matrix: components.json
sort-by: ${{ steps.config.outputs.sort-by }}
group-by: ${{ steps.config.outputs.group-by }}
nested-matrices-count: ${{ inputs.nested-matrices-count }}