-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
79 lines (74 loc) · 2.53 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
name: 'Set up Heroku'
description: 'Set up the Heroku CLI'
inputs:
version:
description: "Version to install"
required: true
default: "latest"
runs:
using: "composite"
steps:
- name: "Ensure dependencies are installed"
shell: bash
run: |
if ! command -v gpg; then sudo -n apt-get install --no-install-recommends gnupg2 ; fi
if ! command -v curl; then sudo -n apt-get install --no-install-recommends curl ; fi
if ! command -v jq; then sudo -n apt-get install --no-install-recommends jq ; fi
- name: "Determine download url"
id: get_url
shell: bash
env:
version: ${{ inputs.version }}
run: |
set -euo pipefail
wd="$(mktemp -d)"
on_exit() {
status=$?
[[ -n "$wd" ]] && rm -rf "$wd"
exit $status
}
trap on_exit EXIT INT TERM
raw_machine="$(uname -m)"
if [[ "$raw_machine" = "aarch64" ]]; then
machine="arm"
elif [[ "$raw_machine" = "x86_64" ]]; then
machine="x64"
else
echo >&2 "Unhandled machine type $raw_machine"
exit 1
fi
curl -fqs -o "$wd/versions.json" "https://cli-assets.heroku.com/versions/heroku-linux-${machine}-tar-gz.json"
if [[ "$version" = "latest" ]]; then
url="https://cli-assets.heroku.com/channels/stable/heroku-linux-${machine}.tar.gz"
else
url="$(jq -cr '.["'"${version}"'"]' < "$wd/versions.json")"
fi
if [[ -z "$url" ]] || [[ "$url" = "null" ]]; then
echo >&2 "Could not find download for ${version} for ${machine}"
exit 1
fi
echo "url=${url}" >> "$GITHUB_OUTPUT"
- name: Cache CLI
id: cache_cli
uses: actions/cache@v4
with:
path: /tmp/heroku-${{ inputs.version }}.tar.gz
key: ${{ runner.os }}-${{ runner.arch }}-${{ steps.get_url.outputs.url }}
- name: "Download CLI"
shell: bash
if: steps.cache_cli.outputs.cache-hit != 'true'
run: |
curl -o "/tmp/heroku-${{ inputs.version }}.tar.gz" -sq "${{ steps.get_url.outputs.url }}"
- name: "Install Heroku CLI"
shell: bash
run: |
set -euo pipefail
sudo -n rm -rf /usr/local/lib/heroku
sudo -n mkdir -p /usr/local/lib/heroku
sudo -n tar -C /usr/local/lib -xpzf "/tmp/heroku-${{ inputs.version }}.tar.gz"
sudo -n rm -f /usr/local/bin/heroku
sudo -n ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku
/usr/local/lib/heroku/bin/node -v || sudo -n rm /usr/local/lib/heroku/bin/node
- name: "Test that it runs correctly"
run: "heroku version"
shell: bash