-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
305 lines (261 loc) · 10.2 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: Platform setup
description: Install and configure PlatformCLI and Stackctl
inputs:
version:
description: |
The version of PlatformCLI to install. Do not include the `v` prefix here.
The default is to lookup the latest release. We recommend using this
default, along with specifying a `required_version` constraint (such as
`=~ 3`) in your `.platform.yaml`.
required: false
token:
description: |
A GitHub access token with rights to fetch the private PlatformCLI release
artifacts. Either this or `github-app-{id,private-key}` must be given.
required: false
github-app-id:
description: |
Provide this (and `github-private-key`) instead of `token` to generate
and use one from the identified App.
required: false
github-private-key:
description: |
Provide this (and `github-app-id`) instead of `token` to generate and use
one from the identified App.
required: false
github-app-private-key:
description: Deprecated, use github-private-key
required: false
app-directory:
description: |
If present, this will be set as `PLATFORM_APP_DIRECTORY` for the remainder
of the workflow. For details on what this affects, see `platform(1)`.
default: ""
environment:
description: |
If present, this will be set as `PLATFORM_ENVIRONMENT` for the remainder
of the workflow. For details on what this affects, see `platform(1)`.
required: false
resource:
description: |
If present, this will be set as `PLATFORM_RESOURCE` for the remainder of
the workflow. For details on what this affects, see `platform(1)`.
required: false
no-validate:
description: |
If present, this will be set as `PLATFORM_NO_VALIDATE` for the remainder
of the workflow. For details on what this affects, see `platform(1)`.
required: false
stackctl-version:
description: |
The version of Stackctl to install. Do not include the `v` prefix here.
The default is to lookup the latest release.
required: false
stackctl-directory:
description: Value to set as STACKCTL_DIRECTORY
default: .platform/specs
stackctl-filter:
description: Value to set as STACKCTL_FILTER
required: false
fetch-platform-yaml:
description: |
Automatically fetch `.platform.yaml` via GitHub API if not present. This
can be useful to avoid a checkout if all your Job needs is this file. This
will always use `github.token`, regardless of our own `token` input.
default: "true"
outputs:
tag:
value: ${{ steps.set-tag.outputs.tag }}
description: |
A consistent, source-specific value that should be used throughout
build/push/deploy actions. It's currently the head sha for `pull_request`
events, the "after" sha for `push` events, and `github.sha` for all other
events
cache:
value: ${{ steps.set-cache.outputs.cache }}
description: |
Path to the `.platform/cache` directory, for which we've setup an
`actions/cache` step. This output is only useful if in a multi-app
repository.
runs:
using: composite
steps:
- if: ${{ !inputs.token && !(inputs.github-app-id && (inputs.github-private-key || inputs.github-app-private-key)) }}
shell: bash
run: |
# Validate token or github-app inputs
echo "Either token or github-app-id/private-key must be provided" >&2
exit 1
- id: app-token
if: ${{ !inputs.token }}
uses: actions/create-github-app-token@v1
with:
app-id: ${{ inputs.github-app-id }}
private-key: ${{ inputs.github-private-key || inputs.github-app-private-key }}
repositories: platform,stackctl
- id: token
shell: bash
run: |
# Choose token output
token=${{ inputs.token || steps.app-token.outputs.token }}
echo "token=$token" >>"$GITHUB_OUTPUT"
- if: ${{ runner.os == 'macOS' }}
shell: bash
run: |
# Replace BSD install with GNU install
brew install coreutils
sudo mkdir -p /usr/local/bin
sudo ln -sf "$(which ginstall)" /usr/local/bin/install
install --version | grep -Fq GNU
- id: prep
if: ${{ inputs.version == '' }}
shell: bash
run: |
# Determine latest PlatformCLI version
curl \
--header "Authorization: Bearer ${{ steps.token.outputs.token }}" \
--silent \
--show-error \
--fail https://api.github.com/repos/freckle/platform/releases |
jq '.[] | select(.draft|not) | select(.prerelease|not) | .tag_name' --raw-output |
head -n 1 |
sed 's/^v/version=/' >>"$GITHUB_OUTPUT"
- id: prep-stackctl
if: ${{ inputs.stackctl-version == '' }}
shell: bash
run: |
# Determine latest Stackctl version
curl \
--header "Authorization: Bearer ${{ steps.token.outputs.token }}" \
--silent \
--show-error \
--fail https://api.github.com/repos/freckle/stackctl/releases |
jq '.[] | select(.draft|not) | select(.prerelease|not) | .tag_name' --raw-output |
head -n 1 |
sed 's/^v/version=/' >>"$GITHUB_OUTPUT"
- name: Install PlatformCLI
uses: pbrisbin/setup-tool-action@v2
with:
name: platform
version: ${{ inputs.version || steps.prep.outputs.version }}
url: "https://github.com/freckle/{name}/releases/download/v{version}/{name}-{arch}-{os}.{ext}"
github-token: ${{ steps.token.outputs.token }}
arch: x86_64
os-darwin: osx
subdir: "{name}"
- name: Install Stackctl
uses: pbrisbin/setup-tool-action@v2
with:
name: stackctl
version: ${{ inputs.stackctl-version || steps.prep-stackctl.outputs.version }}
url: "https://github.com/freckle/{name}/releases/download/v{version}/{name}-{arch}-{os}.{ext}"
arch: x86_64
os-darwin: osx
subdir: "{name}"
- shell: bash
run: |
# Configure PlatformCLI and Stackctl ENV
{
echo 'LOG_COLOR=always'
echo 'LOG_DESTINATION=stderr'
if [[ -n "${{ inputs.app-directory }}" ]]; then
echo 'PLATFORM_APP_DIRECTORY=${{ inputs.app-directory }}'
fi
if [[ -n "${{ inputs.environment }}" ]]; then
echo 'PLATFORM_ENVIRONMENT=${{ inputs.environment }}'
fi
if [[ -n "${{ inputs.resource }}" ]]; then
echo 'PLATFORM_RESOURCE=${{ inputs.resource }}'
fi
if [[ -n "${{ inputs.no-validate }}" ]]; then
echo 'PLATFORM_NO_VALIDATE=${{ inputs.no-validate }}'
fi
if [[ -n "${{ inputs.stackctl-directory }}" ]]; then
app=${{ inputs.app-directory }}
app=${app:-.}
echo "STACKCTL_DIRECTORY=$app/${{ inputs.stackctl-directory }}"
fi
if [[ -n "${{ inputs.stackctl-filter }}" ]]; then
echo "STACKCTL_FILTER=${{ inputs.stackctl-filter }}"
echo "STACKCTL_FILTERS=${{ inputs.stackctl-filter }}"
fi
} >>"$GITHUB_ENV"
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
#
# > Note that GITHUB_SHA for [the pull] event is the last merge commit of
# > the pull request merge branch. If you want to get the commit ID for the
# > last commit to the head branch of the pull request, use
# > github.event.pull_request.head.sha instead.
#
- id: set-tag
shell: bash
run: |
# Set tag output
tag=${{ github.event.pull_request.head.sha }}
tag=${tag:-${{ github.event.after }}}
tag=${tag:-${{ github.sha }}}
echo "tag=$tag" >>"$GITHUB_OUTPUT"
- id: set-cache
shell: bash
run: |
# Set cache path output and resource
app=$PLATFORM_APP_DIRECTORY
app=${app:-.}
echo "cache=$app/.platform/cache" >>"$GITHUB_OUTPUT"
resource=$PLATFORM_RESOURCE
resource=${resource:-all-resources}
echo "resource=$resource" >>"$GITHUB_OUTPUT"
- name: Cache .platform/cache directory
uses: actions/cache@v4
with:
path: ${{ steps.set-cache.outputs.cache }}
key: ${{ runner.os }}-${{ github.job }}-${{ steps.set-cache.outputs.resource }}-${{ steps.set-tag.outputs.tag }}
restore-keys: |
${{ runner.os }}-${{ github.job }}-${{ steps.set-cache.outputs.resource }}-
${{ runner.os }}-${{ github.job }}-
- shell: bash
run: |
# Configure Slack notification ENV
title="Deploy"
if [[ -n "$PLATFORM_APP_DIRECTORY" ]] && [[ -n "$PLATFORM_RESOURCE" ]]; then
title+=" $PLATFORM_APP_DIRECTORY/$PLATFORM_RESOURCE"
elif [[ -n "$PLATFORM_APP_DIRECTORY" ]]; then
title+=" $PLATFORM_APP_DIRECTORY"
elif [[ -n "$PLATFORM_RESOURCE" ]]; then
title+=" $PLATFORM_RESOURCE"
fi
if [[ -n "$PLATFORM_ENVIRONMENT" ]]; then
title+=" to $PLATFORM_ENVIRONMENT"
fi
cat <<EOM >>"$GITHUB_ENV"
SLACK_ICON=https://github.com/freckle-automation.png?size=48
SLACK_USERNAME=GitHub Actions
SLACK_TITLE=$title
SLACK_FOOTER=${{ steps.set-tag.outputs.tag }}
MSG_MINIMAL=actions url,commit
EOM
- if: ${{ inputs.fetch-platform-yaml == 'true' }}
shell: bash
run: |
# Download .platform.yaml if necessary
if [[ -e "${PLATFORM_APP_DIRECTORY:-.}/.platform.yaml" ]]; then
echo "Skipping: .platform.yaml exists"
exit 0
fi
if [[ "$PLATFORM_APP_DIRECTORY" == /* ]]; then
echo "Skipping: \$PLATFORM_APP_DIRECTORY is an absolute path"
exit 0
fi
if [[ -n "$PLATFORM_APP_DIRECTORY" ]]; then
config=$PLATFORM_APP_DIRECTORY/.platform.yaml
else
config=.platform.yaml
fi
ghpath="/repos/$GITHUB_REPOSITORY/contents/$config?ref=$TAG"
echo "Downloading $ghpath..."
mkdir -p "$(dirname "$config")"
gh api "$ghpath" --jq '.content' | base64 -d >"$config"
env:
GH_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
TAG: ${{ steps.set-tag.outputs.tag }}