forked from jetify-com/devbox-install-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
243 lines (226 loc) · 9.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
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
name: 'devbox installer'
description: 'Install Devbox in your CICD workflow'
branding:
icon: 'box'
color: 'purple'
inputs:
project-path: # path to folder
description: 'Project path to devbox.json. Default to the root directory of the repository.'
default: '.'
enable-cache: # 'true' or 'false'
description: 'Caching the entire Nix store in github based on your devbox.json'
default: 'true'
refresh-cli: # 'true' or 'false'
description: 'Specify whether the CLI should be redownloaded'
default: 'false'
devbox-version: # version of the devbox cli
description: 'Specify devbox CLI version you want to pin to. Default to latest'
default: ''
sha256-checksum: # the expected SHA256 checksum of the devbox binary.
description: 'Specify an explicit checksum for the devbox binary. For extra security on top of the existing checks in the devbox launch script'
disable-nix-access-token: # 'true' or 'false'
description: 'Disable configuration of nix access-tokens with the GitHub token used in the workflow'
default: 'false'
skip-nix-installation: # 'true' or 'false'
description: 'Skip the installation of nix'
default: 'false'
use-fallback-cache: # 'true' or 'false'
description: 'Use the fallback cache if the S3 bucket cache fails'
default: 'true'
s3-bucket-name:
default: 'replace-me'
description: 'S3 bucket name in which to cache'
aws-region:
required: false
description: 'AWS region'
aws-access-key-id:
description: 'AWS access key ID'
required: false
aws-secret-access-key:
description: 'AWS secret access key'
required: false
aws-session-token:
description: 'AWS session token - required when using role'
required: false
runs:
using: "composite"
steps:
- name: Get devbox version
shell: bash
env:
DEVBOX_USE_VERSION: ${{ inputs.devbox-version }}
run: |
if [[ -n $DEVBOX_USE_VERSION ]]; then
echo "latest_version=$DEVBOX_USE_VERSION" >> $GITHUB_ENV
else
tmp_file=$(mktemp)
latest_url="https://releases.jetify.com/devbox/stable/version"
curl --fail --silent --location --output "${tmp_file}" "${latest_url}"
latest_version=$(cat "${tmp_file}")
if [[ -n ${latest_version} ]]; then
echo "Found devbox latest version ${latest_version}."
echo "latest_version=$latest_version" >> $GITHUB_ENV
else
echo "ERROR: unable to find the latest devbox version."
exit 1
fi
fi
- name: Mount devbox cli cache
if: inputs.refresh-cli == 'false'
id: cache-devbox-cli
uses: tespkg/actions-cache/restore@v1
with:
path: ~/.local/bin/devbox
key: ${{ runner.os }}-${{ runner.arch }}-devbox-cli-${{ env.latest_version }}
use-fallback: ${{ inputs.use-fallback-cache }}
bucket: ${{ inputs.s3-bucket-name }}
region: ${{ inputs.aws-region }}
accessKey: ${{ inputs.aws-access-key-id }}
secretKey: ${{ inputs.aws-secret-access-key }}
sessionToken: ${{ inputs.aws-session-token }}
- name: Install devbox cli
if: steps.cache-devbox-cli.outputs.cache-hit != 'true'
shell: bash
env:
DEVBOX_SHA256: ${{ inputs.sha256-checksum }}
run: |
export DEVBOX_USE_VERSION="${{ env.latest_version }}"
curl -fsSL https://get.jetify.com/devbox | FORCE=1 bash
version=$(devbox version)
if [[ ! "$version" = "$DEVBOX_USE_VERSION" ]]; then
echo "ERROR: mismatch devbox version downloaded. Expected $DEVBOX_USE_VERSION, got $version."
exit 1
fi
DEVBOX_BINARY="$(find "${HOME}/.cache/devbox/bin" -name devbox)"
if [ -n "$DEVBOX_SHA256" ]; then
if command -v "sha256sum" 1>/dev/null 2>&1; then
# Linux distributions will likely have this.
DEVBOX_CHECKSUM="$(sha256sum "$DEVBOX_BINARY" | cut -f1 -d' ')"
elif command -v "shasum" 1>/dev/null 2>&1; then
# MacOS comes with this.
DEVBOX_CHECKSUM="$(shasum -a 256 "$DEVBOX_BINARY" | cut -f1 -d' ')"
fi
if [ -z "$DEVBOX_CHECKSUM" ]; then
echo "ERROR: unable to get devbox checksum. Please ensure sha256sum or shasum is installed."
exit 2
fi
if [[ ! "$DEVBOX_CHECKSUM" = "$DEVBOX_SHA256" ]]; then
echo "ERROR: checksums do not match. Expected $DEVBOX_SHA256, got $DEVBOX_CHECKSUM."
exit 3
fi
fi
mkdir -p ~/.local/bin
mv "$DEVBOX_BINARY" ~/.local/bin/devbox
- name: Add devbox binary to path
shell: bash
run: |
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Save devbox cli cache
if: inputs.refresh-cli == 'false' && steps.cache-devbox-cli.outputs.cache-hit != 'true'
uses: tespkg/actions-cache/save@v1
with:
path: ~/.local/bin/devbox
key: ${{ runner.os }}-${{ runner.arch }}-devbox-cli-${{ env.latest_version }}
use-fallback: ${{ inputs.use-fallback-cache }}
bucket: ${{ inputs.s3-bucket-name }}
region: ${{ inputs.aws-region }}
accessKey: ${{ inputs.aws-access-key-id }}
secretKey: ${{ inputs.aws-secret-access-key }}
sessionToken: ${{ inputs.aws-session-token }}
- name: Workaround nix store cache permission issue
if: inputs.enable-cache == 'true'
shell: bash
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
gtar_path=$(which gtar)
sudo mv $gtar_path $gtar_path.orig
echo "#!/bin/sh" >> $gtar_path
echo "exec sudo $gtar_path.orig \"\$@\"" >> $gtar_path
sudo chmod +x $gtar_path
elif [ "$RUNNER_OS" == "Linux" ]; then
mkdir -p ~/.cache
mkdir -p ~/.local/bin
echo "#!/bin/sh" >> ~/.local/bin/tar
echo 'exec sudo /usr/bin/tar "$@"' >> ~/.local/bin/tar
sudo chmod +x ~/.local/bin/tar
fi
- name: Configure nix access-tokens
if: inputs.disable-nix-access-token == 'false'
shell: bash
run: |
mkdir -p ~/.config/nix
echo "access-tokens = github.com=${{ github.token }}" >> ~/.config/nix/nix.conf
- name: Install nix
if: inputs.skip-nix-installation == 'false'
uses: DeterminateSystems/nix-installer-action@e50d5f73bfe71c2dd0aa4218de8f4afa59f8f81d # v16
with:
logger: pretty
extra-conf: experimental-features = ca-derivations fetch-closure
- name: Get nix version
shell: bash
run: |
NIX_VERSION_OUTPUT=$(nix --version)
NIX_VERSION=$(echo "${NIX_VERSION_OUTPUT}" | awk '{print $NF}')
echo "nix_version=$NIX_VERSION" >> $GITHUB_ENV
- name: Mount nix store cache
id: cache-devbox-nix-store
if: inputs.enable-cache == 'true'
uses: tespkg/actions-cache/restore@v1
with:
path: |
~/.cache/devbox
~/.cache/nix
~/.local/state/nix
~/.nix-defexpr
~/.nix-profile
/nix/store
/nix/var/nix
key: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ env.nix_version }}-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
use-fallback: ${{ inputs.use-fallback-cache }}
bucket: ${{ inputs.s3-bucket-name }}
region: ${{ inputs.aws-region }}
accessKey: ${{ inputs.aws-access-key-id }}
secretKey: ${{ inputs.aws-secret-access-key }}
sessionToken: ${{ inputs.aws-session-token }}
restore-keys: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ env.nix_version }}-
- name: Install devbox packages
shell: bash
run: |
devbox run --config=${{ inputs.project-path }} -- echo "Packages installed!"
- name: List nix store cache on failure
shell: bash
if: failure()
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "It is likely that nix has shipped a backwards incompatible change. Proceed to the actions tab and manually delete the following cache objects:"
gh cache list --key ${{ runner.os }}-${{ runner.arch }}-devbox --json key
- name: Save nix store cache
if: inputs.enable-cache == 'true' && steps.cache-devbox-nix-store.outputs.cache-hit != 'true'
uses: tespkg/actions-cache/save@v1
with:
path: |
~/.cache/devbox
~/.cache/nix
~/.local/state/nix
~/.nix-defexpr
~/.nix-profile
/nix/store
/nix/var/nix
key: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ env.nix_version }}-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
use-fallback: ${{ inputs.use-fallback-cache }}
bucket: ${{ inputs.s3-bucket-name }}
region: ${{ inputs.aws-region }}
accessKey: ${{ inputs.aws-access-key-id }}
secretKey: ${{ inputs.aws-secret-access-key }}
sessionToken: ${{ inputs.aws-session-token }}
- name: Restore tar command
if: inputs.enable-cache == 'true'
shell: bash
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
gtar_path=$(which gtar)
sudo mv $gtar_path.orig $gtar_path
elif [ "$RUNNER_OS" == "Linux" ]; then
rm ~/.local/bin/tar
fi