Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
297 lines (265 loc) · 11.1 KB
/
Copy pathaction.yml
File metadata and controls
297 lines (265 loc) · 11.1 KB
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
name: "Setup Amp"
description: |
Install Amp (`ampd`, `ampctl`, `ampsql`) in CI via ampup, with version
pinning and caching of the ampup-managed install directory.
branding:
icon: "zap"
color: "purple"
inputs:
version:
description: |
Amp version to install.
Accepts `stable` (the latest stable release), `latest` (an alias for
`stable`), `nightly` (the most recent nightly release), or an explicit
release tag such as `v0.0.36` or `nightly-425b88a`.
Use `none` to install only `ampup` itself, without installing any Amp
version (no `ampd`/`ampctl`/`ampsql`). This skips version resolution
and caching, and requires no GitHub token.
required: false
default: "stable"
github-token:
description: |
GitHub token used to resolve versions and download release assets from
the Amp repository.
While the Amp repository is private, this must be a token with read
access to `edgeandnode/amp` releases. The default workflow token only
has access to the repository running the workflow, so workflows in
other repositories must pass a GitHub App or PAT token here.
required: false
default: ${{ github.token }}
cache:
description: |
Whether to cache the ampup-managed install directory across runs.
Caching is enabled by default. The cache is saved by a post step at the
end of a successful job, and restored before installing.
required: false
default: "true"
cache-key:
description: |
Custom cache key to use instead of the automatic
`setup-amp-<repo>-<platform>-<arch>-<resolved version>` key.
Note that overriding the key removes the resolved version from the
cache identity; the action still converges on the requested version by
running `ampup install` after a restore.
required: false
default: ""
cache-restore-keys:
description: |
Additional cache restore keys (one per line), used to restore a
partially matching cache when no exact key match exists.
A partial restore avoids re-downloading `ampup` itself; the requested
Amp version is still installed on top of the restored directory.
required: false
default: ""
outputs:
version:
description: |
The installed Amp version as a release tag (e.g. `v0.0.36` or
`nightly-425b88a`), after resolving `stable`, `latest`, or `nightly`.
value: ${{ steps.version.outputs.version }}
cache-hit:
description: |
Whether the ampup install directory was restored from an exact cache
key match. `false` when caching is disabled.
value: ${{ steps.cache.outputs.cache-hit == 'true' }}
runs:
using: composite
steps:
- name: Detect platform
id: platform
shell: bash
run: |
: detect the runner platform and architecture, mirroring ampup
case "$(uname -s)" in
Linux) _platform=linux ;;
Darwin) _platform=darwin ;;
*)
echo "::error title=setup-amp::Unsupported platform: $(uname -s). Amp supports Linux and macOS runners (Windows is not supported)."
exit 1
;;
esac
case "$(uname -m)" in
x86_64 | amd64) _arch=x86_64 ;;
arm64 | aarch64) _arch=aarch64 ;;
*)
echo "::error title=setup-amp::Unsupported architecture: $(uname -m). Amp supports x86_64 and aarch64 runners."
exit 1
;;
esac
: resolve the install directory the same way ampup does
if [ -z "${AMP_DIR:-}" ]; then
if [ -n "${XDG_CONFIG_HOME:-}" ]; then
AMP_DIR="${XDG_CONFIG_HOME}/.amp"
else
AMP_DIR="${HOME}/.amp"
fi
fi
echo "Platform: ${_platform}, Architecture: ${_arch}, Install directory: ${AMP_DIR}"
echo "AMP_DIR=${AMP_DIR}" >> "$GITHUB_ENV"
{
echo "platform=${_platform}"
echo "arch=${_arch}"
echo "amp-dir=${AMP_DIR}"
} >> "$GITHUB_OUTPUT"
- name: Resolve Amp version
id: version
shell: bash
env:
SETUP_AMP_VERSION: ${{ inputs.version }}
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
: resolve the requested version to a concrete release tag
if [ "${SETUP_AMP_VERSION}" = "none" ]; then
echo "Skipping Amp installation ('none' requested): only ampup will be installed"
echo "version=none" >> "$GITHUB_OUTPUT"
exit 0
fi
AMP_REPO="${AMP_REPO:-edgeandnode/amp}"
_auth=()
if [ -n "${GITHUB_TOKEN:-}" ]; then
_auth=(--header "Authorization: Bearer ${GITHUB_TOKEN}")
fi
api() {
curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location \
--retry 5 --retry-connrefused \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
"${_auth[@]}" \
"https://api.github.com/repos/${AMP_REPO}/${1}"
}
case "${SETUP_AMP_VERSION}" in
"" | stable | latest)
if ! _release="$(api releases/latest)"; then
echo "::error title=setup-amp::Failed to resolve the latest stable release of ${AMP_REPO}. If the repository is private, pass a 'github-token' with read access to it."
exit 1
fi
_tag="$(printf '%s' "${_release}" | jq -r '.tag_name')"
;;
nightly)
if ! _releases="$(api 'releases?per_page=100')"; then
echo "::error title=setup-amp::Failed to list releases of ${AMP_REPO}. If the repository is private, pass a 'github-token' with read access to it."
exit 1
fi
: pick the most recent nightly that has downloadable assets --
: nightlies are sometimes published before their binaries land
_tag="$(printf '%s' "${_releases}" | jq -r '[.[] | select(.draft | not) | select(.tag_name | startswith("nightly-")) | select((.assets | length) > 0)][0].tag_name // empty')"
if [ -z "${_tag}" ]; then
echo "::error title=setup-amp::No nightly releases with downloadable assets found in ${AMP_REPO}."
exit 1
fi
;;
*)
if ! api "releases/tags/${SETUP_AMP_VERSION}" > /dev/null; then
echo "::error title=setup-amp::Unknown Amp version '${SETUP_AMP_VERSION}' or no access to ${AMP_REPO} releases. Expected 'stable', 'latest', 'nightly', or an existing release tag (e.g. 'v0.0.36'). If ${AMP_REPO} is private, ensure 'github-token' has read access to it."
exit 1
fi
_tag="${SETUP_AMP_VERSION}"
;;
esac
echo "Resolved Amp version: ${SETUP_AMP_VERSION:-stable} -> ${_tag} (from ${AMP_REPO})"
{
echo "version=${_tag}"
echo "repo=${AMP_REPO//\//-}"
} >> "$GITHUB_OUTPUT"
- name: Restore cached install
id: cache
if: inputs.cache == 'true' && inputs.version != 'none'
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ${{ steps.platform.outputs.amp-dir }}
key: ${{ inputs.cache-key != '' && inputs.cache-key || format('setup-amp-{0}-{1}-{2}-{3}', steps.version.outputs.repo, steps.platform.outputs.platform, steps.platform.outputs.arch, steps.version.outputs.version) }}
restore-keys: ${{ inputs.cache-restore-keys }}
- name: Install ampup
shell: bash
env:
AMP_DIR: ${{ steps.platform.outputs.amp-dir }}
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
: bootstrap ampup unless a cached copy was restored
if [ -x "${AMP_DIR}/bin/ampup" ]; then
echo "ampup already installed, skipping bootstrap"
exit 0
fi
curl --proto '=https' --tlsv1.2 --silent --show-error --fail \
--retry 5 --retry-connrefused \
https://ampup.sh/install \
| sh -s -- --no-modify-path --no-install-latest
- name: Install Amp (${{ inputs.version }})
if: inputs.version != 'none'
shell: bash
env:
AMP_DIR: ${{ steps.platform.outputs.amp-dir }}
AMP_VERSION: ${{ steps.version.outputs.version }}
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
: install the resolved version, a no-op if restored from cache
AMP_REPO="${AMP_REPO:-edgeandnode/amp}"
"${AMP_DIR}/bin/ampup" install --repo "${AMP_REPO}" "${AMP_VERSION}"
- name: Add Amp to PATH
shell: bash
env:
AMP_DIR: ${{ steps.platform.outputs.amp-dir }}
run: echo "${AMP_DIR}/bin" >> "$GITHUB_PATH"
- name: Verify installation
shell: bash
env:
AMP_DIR: ${{ steps.platform.outputs.amp-dir }}
PLATFORM: ${{ steps.platform.outputs.platform }}
ARCH: ${{ steps.platform.outputs.arch }}
REQUESTED_VERSION: ${{ inputs.version }}
RESOLVED_VERSION: ${{ steps.version.outputs.version }}
CACHE_ENABLED: ${{ inputs.cache }}
CACHE_HIT: ${{ steps.cache.outputs.cache-hit }}
run: |
: verify the installed binaries and publish a step summary
_ampup_version="$("${AMP_DIR}/bin/ampup" --version)"
echo "ampup: ${_ampup_version}"
if [ "${RESOLVED_VERSION}" = "none" ]; then
{
echo "## Setup Amp"
echo ""
echo "| | |"
echo "| --- | --- |"
echo "| Requested version | \`none\` (ampup only) |"
echo "| Platform | \`${PLATFORM}-${ARCH}\` |"
echo "| ampup | \`${_ampup_version}\` |"
} >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
_ampd_version="$("${AMP_DIR}/bin/ampd" --version)"
echo "ampd: ${_ampd_version}"
if [ -x "${AMP_DIR}/bin/ampctl" ]; then
_ampctl_version="$("${AMP_DIR}/bin/ampctl" --version)"
echo "ampctl: ${_ampctl_version}"
else
_ampctl_version="not included in this release"
echo "::notice title=setup-amp::ampctl is not included in release ${RESOLVED_VERSION}"
fi
if [ -x "${AMP_DIR}/bin/ampsql" ]; then
_ampsql_version="$("${AMP_DIR}/bin/ampsql" --version)"
echo "ampsql: ${_ampsql_version}"
else
_ampsql_version="not included in this release"
echo "::notice title=setup-amp::ampsql is not included in release ${RESOLVED_VERSION}"
fi
if [ "${CACHE_ENABLED}" != "true" ]; then
_cache_status="disabled"
elif [ "${CACHE_HIT}" = "true" ]; then
_cache_status="hit"
else
_cache_status="miss"
fi
{
echo "## Setup Amp"
echo ""
echo "| | |"
echo "| --- | --- |"
echo "| Requested version | \`${REQUESTED_VERSION:-stable}\` |"
echo "| Installed version | \`${RESOLVED_VERSION}\` |"
echo "| Platform | \`${PLATFORM}-${ARCH}\` |"
echo "| Cache | ${_cache_status} |"
echo "| ampup | \`${_ampup_version}\` |"
echo "| ampd | \`${_ampd_version}\` |"
echo "| ampctl | \`${_ampctl_version}\` |"
echo "| ampsql | \`${_ampsql_version}\` |"
} >> "$GITHUB_STEP_SUMMARY"