Skip to content

Commit 7acad82

Browse files
authored
Merge pull request #5 from jetpack-io/lucille--rate-limit
Cache devbox cli, avoid github api rate limit
2 parents d8bd95b + 7edbf3b commit 7acad82

File tree

3 files changed

+57
-31
lines changed

3 files changed

+57
-31
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install devbox
3636
uses: ./
3737
with:
38-
devbox-version: '0.2.0'
38+
devbox-version: '0.2.2'
3939
project-path: 'testdata'
4040

4141
test-action-with-cache:

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
# devbox-install-action
2+
23
This action downloads the devbox CLI and installs the Nix packages defined in your `devbox.json`.
34

45
[![version](https://img.shields.io/github/v/release/jetpack-io/devbox-install-action?color=green&label=version&sort=semver)](https://github.com/jetpack-io/devbox-install-action/releases) [![tests](https://github.com/jetpack-io/devbox-install-action/actions/workflows/test.yaml/badge.svg)](https://github.com/jetpack-io/devbox-install-action/actions/workflows/test.yaml?branch=main)
56

67
## Example Workflow
8+
79
```
810
name: Testing with devbox
911
1012
on: push
11-
13+
1214
jobs:
1315
test:
1416
runs-on: ubuntu-latest
1517
steps:
1618
- uses: actions/checkout@v3
17-
19+
1820
- name: Install devbox
1921
uses: jetpack-io/devbox-install-action@v0.1.0
20-
22+
2123
- name: Run arbitrary commands
2224
run: devbox shell -- echo "done!"
23-
25+
2426
- name: Run a script called test
2527
run: devbox run test
2628
```
2729

2830
## Configure Action
2931

3032
### Action Inputs
31-
| Input argument | description | default |
32-
| -------------- | ----------- | ------- |
33-
| project-path | Path to the folder that contains a valid `devbox.json` | repo's root directory |
34-
| enable-cache | Cache the entire Nix store in github based on your `devbox.json` | false |
35-
| devbox-version | Specify devbox CLI version you want to pin to | latest |
33+
34+
| Input argument | description | default |
35+
| -------------- | ------------------------------------------------------------------- | --------------------- |
36+
| project-path | Path to the folder that contains a valid `devbox.json` | repo's root directory |
37+
| enable-cache | Cache the entire Nix store in github based on your `devbox.json` | false |
38+
| devbox-version | Specify devbox CLI version you want to pin to. Only supports >0.2.2 | latest |
3639

3740
### Example Configuration
41+
3842
Here's an example job with all three inputs:
43+
3944
```
4045
- name: Install devbox
4146
uses: jetpack-io/devbox-install-action@v0.1.0
4247
with:
4348
project-path: 'path-to-folder'
4449
enable-cache: true
45-
devbox-version: '0.2.0'
50+
devbox-version: '0.2.2'
4651
```
47-

action.yml

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ inputs:
1818
runs:
1919
using: "composite"
2020
steps:
21-
- name: Install devbox
22-
shell: bash
23-
run: |
24-
curl -fsSL https://get.jetpack.io/devbox | FORCE=1 bash
25-
2621
- name: Workaround for permission issue
2722
if: inputs.enable-cache == 'true'
2823
shell: bash
@@ -39,24 +34,51 @@ runs:
3934
/nix/var/nix
4035
key: ${{ runner.os }}-devbox-${{ hashFiles(format('{0}/devbox.json', inputs.project-path)) }}
4136

42-
- name: devbox version
43-
id: devbox-version
44-
if: inputs.devbox-version == ''
45-
uses: pozetroninc/github-action-get-latest-release@v0.5.0
37+
- name: Get devbox version
38+
shell: bash
39+
env:
40+
DEVBOX_USE_VERSION: ${{ inputs.devbox-version }}
41+
run: |
42+
if [[ -n $DEVBOX_USE_VERSION ]]; then
43+
echo "latest_version=$DEVBOX_USE_VERSION" >> $GITHUB_ENV
44+
else
45+
tmp_file=$(mktemp)
46+
latest_url="https://releases.jetpack.io/devbox/latest/version"
47+
curl --fail --silent --location --output "${tmp_file}" "${latest_url}"
48+
latest_version=$(cat "${tmp_file}")
49+
if [[ -n ${latest_version} ]]; then
50+
echo "Found devbox latest version ${latest_version}."
51+
echo "latest_version=$latest_version" >> $GITHUB_ENV
52+
else
53+
echo "ERROR: unable to find the latest devbox version."
54+
exit 1
55+
fi
56+
fi
57+
58+
- name: Mount devbox cli cache
59+
id: cache-devbox-cli
60+
uses: actions/cache@v3
4661
with:
47-
repository: jetpack-io/devbox
48-
excludes: prerelease, draft
62+
path: /usr/local/bin/devbox
63+
key: ${{ runner.os }}-devbox-${{ env.latest_version }}
64+
65+
- name: Install devbox cli
66+
if: steps.cache-devbox-cli.outputs.cache-hit != 'true'
67+
shell: bash
68+
run: |
69+
DEVBOX_USE_VERSION="${{ env.latest_version }}"
70+
curl -fsSL https://get.jetpack.io/devbox | FORCE=1 bash
71+
72+
version=$(devbox version)
73+
if [[ ! "$version" = "$DEVBOX_USE_VERSION" ]]; then
74+
echo "ERROR: mismatch devbox version downloaded. Expected $DEVBOX_USE_VERSION, got $version."
75+
exit 1
76+
fi
77+
sudo mv ${HOME}/.cache/devbox/bin/${version}_*/devbox /usr/local/bin/devbox
4978
5079
- name: Install nix and devbox packages
5180
shell: bash
52-
env:
53-
DEVBOX_USE_VERSION: ${{ inputs.devbox-version }}
5481
run: |
5582
NIX_INSTALLER_NO_CHANNEL_ADD=1
5683
NIX_BUILD_SHELL=/bin/bash
57-
if [[ ! -n $DEVBOX_USE_VERSION ]]; then
58-
DEVBOX_USE_VERSION=${{ steps.devbox-version.outputs.release }}
59-
fi
60-
devbox shell --config=${{ inputs.project-path }} -- echo "Installing nix..." || true
61-
source /home/runner/.nix-profile/etc/profile.d/nix.sh
62-
devbox shell --config=${{ inputs.project-path }} -- echo "Installing packages..."
84+
devbox shell --config=${{ inputs.project-path }} -- echo "Packages installed!"

0 commit comments

Comments
 (0)