Skip to content

Commit 4380b7c

Browse files
authored
[cicd] Unify lint, add caching (#1549)
## Summary * unified gofumpt and lint * Added go caching to tests * Added pre-building devbox binary to be shared between tests ## How was it tested? CICD
1 parent 5598f26 commit 4380b7c

File tree

2 files changed

+63
-20
lines changed

2 files changed

+63
-20
lines changed

.github/workflows/cli-tests.yaml

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ env:
4646
DEVBOX_DEBUG: 1
4747

4848
jobs:
49+
build-devbox:
50+
strategy:
51+
matrix:
52+
os: [ubuntu-latest, macos-latest]
53+
runs-on: ${{ matrix.os }}
54+
steps:
55+
- uses: actions/checkout@v3
56+
- uses: actions/setup-go@v4
57+
with:
58+
go-version-file: ./go.mod
59+
- name: Mount golang cache
60+
uses: actions/cache@v3
61+
with:
62+
path: |
63+
~/.cache/go-build
64+
~/go/pkg
65+
key: go-devbox-build-${{ runner.os }}-${{ hashFiles('go.sum') }}
66+
- name: Build devbox
67+
run: go build -o dist/devbox ./cmd/devbox
68+
- name: Upload devbox artifact
69+
uses: actions/upload-artifact@v3
70+
with:
71+
name: devbox-${{ runner.os }}-${{ runner.arch }}
72+
path: ./dist/devbox
73+
retention-days: 7
74+
4975
typos:
5076
name: Spell Check with Typos
5177
if: github.ref != 'refs/heads/main'
@@ -55,6 +81,7 @@ jobs:
5581
- uses: crate-ci/[email protected]
5682

5783
golangci-lint:
84+
needs: build-devbox
5885
strategy:
5986
matrix:
6087
os: [ubuntu-latest, macos-latest]
@@ -70,6 +97,7 @@ jobs:
7097
cache: false
7198

7299
# This can be reanabled once released version supports runx
100+
# and we can remove needs: build-devbox
73101
# - name: Install devbox
74102
# uses: jetpack-io/[email protected]
75103
# with:
@@ -84,16 +112,19 @@ jobs:
84112
~/go/pkg
85113
key: go-${{ runner.os }}-${{ hashFiles('go.sum') }}
86114

87-
# Use main devbox for now to ensure it supports runx
88-
- run: go run ./cmd/devbox run fmt
89-
90-
- name: golangci-lint
91-
uses: golangci/[email protected]
115+
- name: Download devbox
116+
uses: actions/download-artifact@v3
92117
with:
93-
args: "--out-${NO_FUTURE}format colored-line-number --timeout=10m"
94-
skip-cache: true
118+
name: devbox-${{ runner.os }}-${{ runner.arch }}
119+
- name: Add devbox to path
120+
run: |
121+
chmod +x ./devbox
122+
sudo mv ./devbox /usr/local/bin/
123+
124+
- run: devbox run lint
95125

96126
test:
127+
needs: build-devbox
97128
strategy:
98129
matrix:
99130
is-main:
@@ -117,7 +148,7 @@ jobs:
117148
os: macos-latest
118149

119150
runs-on: ${{ matrix.os }}
120-
timeout-minutes: ${{ (github.ref == 'refs/heads/main' || inputs.run-mac-tests) && 37 || 25 }}
151+
timeout-minutes: 37
121152
steps:
122153
- name: Maximize build disk space
123154
uses: easimon/maximize-build-space@v8
@@ -133,8 +164,13 @@ jobs:
133164
- uses: actions/setup-go@v4
134165
with:
135166
go-version-file: ./go.mod
136-
- name: Build devbox
137-
run: go install ./cmd/devbox
167+
- name: Mount golang cache
168+
uses: actions/cache@v3
169+
with:
170+
path: |
171+
~/.cache/go-build
172+
~/go/pkg
173+
key: go-devbox-tests-${{ runner.os }}-${{ hashFiles('go.sum') }}
138174
- name: Install additional shells (dash, zsh)
139175
run: |
140176
if [ "$RUNNER_OS" == "Linux" ]; then
@@ -171,17 +207,21 @@ jobs:
171207
go test -v -timeout $DEVBOX_GOLANG_TEST_TIMEOUT ./...
172208
173209
auto-nix-install: # ensure Devbox installs nix and works properly after installation.
210+
needs: build-devbox
174211
strategy:
175212
matrix:
176213
os: [ubuntu-latest, macos-latest]
177214
runs-on: ${{ matrix.os }}
178215
steps:
179216
- uses: actions/checkout@v3
180-
- uses: actions/setup-go@v4
217+
- name: Download devbox
218+
uses: actions/download-artifact@v3
181219
with:
182-
go-version-file: ./go.mod
183-
- name: Build devbox
184-
run: go install ./cmd/devbox
220+
name: devbox-${{ runner.os }}-${{ runner.arch }}
221+
- name: Add devbox to path
222+
run: |
223+
chmod +x ./devbox
224+
sudo mv ./devbox /usr/local/bin/
185225
- name: Install nix and devbox packages
186226
run: |
187227
export NIX_INSTALLER_NO_CHANNEL_ADD=1
@@ -198,18 +238,22 @@ jobs:
198238
# Run a sanity test to make sure Devbox can install and remove packages with
199239
# the last 3 Nix releases.
200240
test-nix-versions:
241+
needs: build-devbox
201242
strategy:
202243
matrix:
203244
os: [ubuntu-latest, macos-latest]
204245
nix-version: [2.15.1, 2.16.1, 2.17.0, 2.18.0]
205246
runs-on: ${{ matrix.os }}
206247
steps:
207248
- uses: actions/checkout@v3
208-
- uses: actions/setup-go@v4
249+
- name: Download devbox
250+
uses: actions/download-artifact@v3
209251
with:
210-
go-version-file: ./go.mod
211-
- name: Build devbox
212-
run: go install ./cmd/devbox
252+
name: devbox-${{ runner.os }}-${{ runner.arch }}
253+
- name: Add devbox to path
254+
run: |
255+
chmod +x ./devbox
256+
sudo mv ./devbox /usr/local/bin/
213257
- name: Install Nix
214258
uses: DeterminateSystems/nix-installer-action@v4
215259
with:

devbox.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"GOOS=linux GOARCH=arm64 go build -o dist/devbox-linux-arm64 ./cmd/devbox"
2222
],
2323
"code": "code .",
24-
"fmt": "scripts/gofumpt.sh",
25-
"lint": "golangci-lint run",
24+
"lint": "golangci-lint run --timeout 5m && scripts/gofumpt.sh",
2625
"test": "go test -race -cover ./...",
2726
"update-examples": "devbox run build && go run testscripts/testrunner/updater/main.go"
2827
}

0 commit comments

Comments
 (0)