generated from cloudposse-github-actions/composite-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
147 lines (141 loc) · 5.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: "Atmos Affected Stacks Trigger Spacelift"
description: "A GitHub action to trigger the corresponding Spacelift Stack from `atmos describe affected`"
author: hello@cloudposse.com
branding:
icon: "file"
color: "white"
inputs:
atmos-config-path:
default: .
description: A path to the folder where atmos.yaml is located
required: false
atmos-version:
default: latest
description: The version of atmos to install if install-atmos is true
required: false
default-branch:
default: ${{ github.event.repository.default_branch }}
description: The default branch to use for the base ref.
required: false
deploy:
default: 'false'
description: A flag to indicate if a deployment should be triggered. If false, a preview will be triggered.
github-token:
description: A GitHub token for running the spacelift-io/setup-spacectl action
required: true
head-ref:
description: The head ref to checkout. If not provided, the head default branch is used.
required: false
install-atmos:
default: 'true'
description: Whether to install atmos
required: false
install-jq:
default: 'false'
description: Whether to install jq
required: false
install-spacectl:
default: 'true'
description: Whether to install spacectl
required: false
install-terraform:
default: 'true'
description: Whether to install terraform
required: false
jq-force:
default: 'true'
description: Whether to force the installation of jq
required: false
jq-version:
default: '1.6'
description: The version of jq to install if install-jq is true
required: false
spacectl-version:
default: latest
description: The version of spacectl to install if install-spacectl is true
required: false
spacelift-api-key-id:
description: The SPACELIFT_API_KEY_ID
required: false
spacelift-api-key-secret:
description: The SPACELIFT_API_KEY_SECRET
required: false
spacelift-endpoint:
description: The Spacelift endpoint. For example, https://unicorn.app.spacelift.io
required: false
terraform-version:
default: latest
description: The version of terraform to install if install-terraform is true
required: false
trigger-method:
default: 'comment'
description: The method to use to trigger the Spacelift stack. Valid values are `comment` and `spacectl`
required: false
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Atmos Affected Stacks
id: affected-stacks
uses: cloudposse/github-action-atmos-affected-stacks@v1
with:
default-branch: ${{inputs.default-branch}}
head-ref: ${{inputs.head-ref}}
install-atmos: ${{inputs.install-atmos}}
atmos-version: ${{inputs.atmos-version}}
atmos-config-path: ${{inputs.atmos-config-path}}
atmos-include-spacelift-admin-stacks: "true"
install-terraform: ${{inputs.install-terraform}}
terraform-version: ${{inputs.terraform-version}}
install-jq: ${{inputs.install-jq}}
jq-version: ${{inputs.jq-version}}
jq-force: ${{inputs.jq-force}}
- name: Setup Spacectl
if: ${{ steps.affected-stacks.outputs.has-affected-stacks == 'true' && inputs.install-spacectl == 'true' && inputs.trigger-method == 'spacectl' }}
uses: spacelift-io/setup-spacectl@v1.0.0
env:
GITHUB_TOKEN: ${{inputs.github-token}}
with:
version: ${{inputs.spacectl-version}}
- name: Trigger Spacelift Stacks with Spacectl
if: ${{ steps.affected-stacks.outputs.has-affected-stacks == 'true' && inputs.trigger-method == 'spacectl' }}
shell: bash
env:
SPACELIFT_API_KEY_ENDPOINT: ${{inputs.spacelift-endpoint}}
SPACELIFT_API_KEY_ID: ${{ inputs.spacelift-api-key-id }}
SPACELIFT_API_KEY_SECRET: ${{ inputs.spacelift-api-key-secret }}
TRIGGERING_SHA: ${{ github.event.pull_request.head.sha || github.sha}}
run: |
spacectl_deploy="false"
if [ "${{inputs.deploy}}" = "true" ]; then
spacectl_deploy="true"
fi
printf "%s\n" '${{ steps.affected-stacks.outputs.affected }}' >affected-stacks.json
${GITHUB_ACTION_PATH}/scripts/spacelift-trigger-affected-stacks.sh $spacectl_deploy
- name: Create PR Comment Body with Affected Stacks
if: ${{ steps.affected-stacks.outputs.has-affected-stacks == 'true' && inputs.trigger-method == 'comment' }}
id: create-pr-comment-body
shell: bash
run: |
spacectl_deploy="false"
if [ "${{inputs.deploy}}" = "true" ]; then
spacectl_deploy="true"
fi
printf "%s\n" '${{ steps.affected-stacks.outputs.affected }}' >affected-stacks.json
${GITHUB_ACTION_PATH}/scripts/spacelift-generate-pr-comment-body.sh $spacectl_deploy
# Check if comment body is empty (when all affected stacks have spacelift workspace disabled)
if [ -s comment-body.txt ]; then
echo "affected-stacks-enabled=true" >> $GITHUB_OUTPUT
else
echo "affected-stacks-enabled=false" >> $GITHUB_OUTPUT
fi
- name: Create PR Comment with Affected Stacks
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0
if: ${{ steps.affected-stacks.outputs.has-affected-stacks == 'true' && inputs.trigger-method == 'comment' && fromJSON(steps.create-pr-comment-body.outputs.affected-stacks-enabled) }}
with:
header: atmos-affected-stacks
recreate: true
path: comment-body.txt
env:
GITHUB_TOKEN: ${{inputs.github-token}}