From 1c3a5b1a084c2177627d2577ff88d356b53de348 Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Tue, 10 Oct 2023 12:40:53 -0700 Subject: [PATCH 1/8] [cicd] Unify lint, add caching --- .github/workflows/cli-tests.yaml | 22 +++++++++++++++------- devbox.json | 3 +-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/cli-tests.yaml b/.github/workflows/cli-tests.yaml index 76c07540569..d67a4dae492 100644 --- a/.github/workflows/cli-tests.yaml +++ b/.github/workflows/cli-tests.yaml @@ -85,13 +85,7 @@ jobs: key: go-${{ runner.os }}-${{ hashFiles('go.sum') }} # Use main devbox for now to ensure it supports runx - - run: go run ./cmd/devbox run fmt - - - name: golangci-lint - uses: golangci/golangci-lint-action@v3.7.0 - with: - args: "--out-${NO_FUTURE}format colored-line-number --timeout=10m" - skip-cache: true + - run: go run ./cmd/devbox run lint test: strategy: @@ -133,6 +127,13 @@ jobs: - uses: actions/setup-go@v4 with: go-version-file: ./go.mod + - name: Mount golang cache + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg + key: go-devbox-tests-${{ runner.os }}-${{ hashFiles('go.sum') }} - name: Build devbox run: go install ./cmd/devbox - name: Install additional shells (dash, zsh) @@ -180,6 +181,13 @@ jobs: - uses: actions/setup-go@v4 with: go-version-file: ./go.mod + - name: Mount golang cache + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg + key: go-devbox-tests-${{ runner.os }}-${{ hashFiles('go.sum') }} - name: Build devbox run: go install ./cmd/devbox - name: Install nix and devbox packages diff --git a/devbox.json b/devbox.json index af14a34f0ee..829defe2abb 100644 --- a/devbox.json +++ b/devbox.json @@ -21,8 +21,7 @@ "GOOS=linux GOARCH=arm64 go build -o dist/devbox-linux-arm64 ./cmd/devbox" ], "code": "code .", - "fmt": "scripts/gofumpt.sh", - "lint": "golangci-lint run", + "lint": "golangci-lint run && scripts/gofumpt.sh", "test": "go test -race -cover ./...", "update-examples": "devbox run build && go run testscripts/testrunner/updater/main.go" } From 44c631a0db440b87b9d3a522bf06b97c7c418c7b Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Tue, 10 Oct 2023 12:54:02 -0700 Subject: [PATCH 2/8] Improve caching and use artifacts --- .github/workflows/cli-tests.yaml | 50 +++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/.github/workflows/cli-tests.yaml b/.github/workflows/cli-tests.yaml index d67a4dae492..32ae7f4ceb8 100644 --- a/.github/workflows/cli-tests.yaml +++ b/.github/workflows/cli-tests.yaml @@ -46,6 +46,31 @@ env: DEVBOX_DEBUG: 1 jobs: + build-devbox: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version-file: ./go.mod + - name: Mount golang cache + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg + key: go-devbox-build-${{ runner.os }}-${{ hashFiles('go.sum') }} + - name: Build devbox + run: go build -o dist/devbox ./cmd/devbox + - name: Upload compiled binary as artifact + uses: actions/upload-artifact@v3 + with: + name: devbox-${{ runner.os }} + path: ./dist/devbox + typos: name: Spell Check with Typos if: github.ref != 'refs/heads/main' @@ -88,6 +113,7 @@ jobs: - run: go run ./cmd/devbox run lint test: + needs: build-devbox strategy: matrix: is-main: @@ -134,8 +160,6 @@ jobs: ~/.cache/go-build ~/go/pkg key: go-devbox-tests-${{ runner.os }}-${{ hashFiles('go.sum') }} - - name: Build devbox - run: go install ./cmd/devbox - name: Install additional shells (dash, zsh) run: | if [ "$RUNNER_OS" == "Linux" ]; then @@ -172,6 +196,7 @@ jobs: go test -v -timeout $DEVBOX_GOLANG_TEST_TIMEOUT ./... auto-nix-install: # ensure Devbox installs nix and works properly after installation. + needs: build-devbox strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -181,15 +206,11 @@ jobs: - uses: actions/setup-go@v4 with: go-version-file: ./go.mod - - name: Mount golang cache - uses: actions/cache@v3 + - name: Download devbox + uses: actions/download-artifact@v3 with: - path: | - ~/.cache/go-build - ~/go/pkg - key: go-devbox-tests-${{ runner.os }}-${{ hashFiles('go.sum') }} - - name: Build devbox - run: go install ./cmd/devbox + name: devbox-${{ runner.os }} + - run: chmod +x ./devbox - name: Install nix and devbox packages run: | export NIX_INSTALLER_NO_CHANNEL_ADD=1 @@ -206,6 +227,7 @@ jobs: # Run a sanity test to make sure Devbox can install and remove packages with # the last 3 Nix releases. test-nix-versions: + needs: build-devbox strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -213,11 +235,11 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - name: Download devbox + uses: actions/download-artifact@v3 with: - go-version-file: ./go.mod - - name: Build devbox - run: go install ./cmd/devbox + name: devbox-${{ runner.os }} + - run: chmod +x ./devbox - name: Install Nix uses: DeterminateSystems/nix-installer-action@v4 with: From e68691d6d0a3b0062393ad1c63542c9e8e28675e Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Tue, 10 Oct 2023 12:54:51 -0700 Subject: [PATCH 3/8] Set retention to 5 days --- .github/workflows/cli-tests.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cli-tests.yaml b/.github/workflows/cli-tests.yaml index 32ae7f4ceb8..3b8f06052c7 100644 --- a/.github/workflows/cli-tests.yaml +++ b/.github/workflows/cli-tests.yaml @@ -65,11 +65,12 @@ jobs: key: go-devbox-build-${{ runner.os }}-${{ hashFiles('go.sum') }} - name: Build devbox run: go build -o dist/devbox ./cmd/devbox - - name: Upload compiled binary as artifact + - name: Upload devbox artifact uses: actions/upload-artifact@v3 with: name: devbox-${{ runner.os }} path: ./dist/devbox + retention-days: 7 typos: name: Spell Check with Typos @@ -203,9 +204,6 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version-file: ./go.mod - name: Download devbox uses: actions/download-artifact@v3 with: From bb51199db4cf7c98eacb0a35cf10c972b8ddf631 Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Tue, 10 Oct 2023 13:03:41 -0700 Subject: [PATCH 4/8] Add devbox to path --- .github/workflows/cli-tests.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cli-tests.yaml b/.github/workflows/cli-tests.yaml index 3b8f06052c7..5267cbece8f 100644 --- a/.github/workflows/cli-tests.yaml +++ b/.github/workflows/cli-tests.yaml @@ -208,7 +208,10 @@ jobs: uses: actions/download-artifact@v3 with: name: devbox-${{ runner.os }} - - run: chmod +x ./devbox + - name: Add devbox to path + run: | + chmod +x ./devbox + sudo mv ./devbox /usr/local/bin/ - name: Install nix and devbox packages run: | export NIX_INSTALLER_NO_CHANNEL_ADD=1 @@ -237,7 +240,10 @@ jobs: uses: actions/download-artifact@v3 with: name: devbox-${{ runner.os }} - - run: chmod +x ./devbox + - name: Add devbox to path + run: | + chmod +x ./devbox + sudo mv ./devbox /usr/local/bin/ - name: Install Nix uses: DeterminateSystems/nix-installer-action@v4 with: From dd0bf27c2652e2676a5c0d6268a58928d22bbef2 Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Tue, 10 Oct 2023 13:11:15 -0700 Subject: [PATCH 5/8] Requested changes --- .github/workflows/cli-tests.yaml | 24 ++++++++++++++---------- devbox.json | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cli-tests.yaml b/.github/workflows/cli-tests.yaml index 5267cbece8f..3f49fc402c7 100644 --- a/.github/workflows/cli-tests.yaml +++ b/.github/workflows/cli-tests.yaml @@ -68,7 +68,7 @@ jobs: - name: Upload devbox artifact uses: actions/upload-artifact@v3 with: - name: devbox-${{ runner.os }} + name: devbox-${{ runner.os }}-${{ runner.arch }} path: ./dist/devbox retention-days: 7 @@ -95,11 +95,7 @@ jobs: go-version-file: ./go.mod cache: false - # This can be reanabled once released version supports runx - # - name: Install devbox - # uses: jetpack-io/devbox-install-action@v0.7.0 - # with: - # enable-cache: true + # TODO ADD nix only cache - name: Mount golang cache uses: actions/cache@v3 @@ -110,8 +106,16 @@ jobs: ~/go/pkg key: go-${{ runner.os }}-${{ hashFiles('go.sum') }} - # Use main devbox for now to ensure it supports runx - - run: go run ./cmd/devbox run lint + - name: Download devbox + uses: actions/download-artifact@v3 + with: + name: devbox-${{ runner.os }}-${{ runner.arch }} + - name: Add devbox to path + run: | + chmod +x ./devbox + sudo mv ./devbox /usr/local/bin/ + + - run: devbox run lint test: needs: build-devbox @@ -207,7 +211,7 @@ jobs: - name: Download devbox uses: actions/download-artifact@v3 with: - name: devbox-${{ runner.os }} + name: devbox-${{ runner.os }}-${{ runner.arch }} - name: Add devbox to path run: | chmod +x ./devbox @@ -239,7 +243,7 @@ jobs: - name: Download devbox uses: actions/download-artifact@v3 with: - name: devbox-${{ runner.os }} + name: devbox-${{ runner.os }}-${{ runner.arch }} - name: Add devbox to path run: | chmod +x ./devbox diff --git a/devbox.json b/devbox.json index 829defe2abb..be1d55f4538 100644 --- a/devbox.json +++ b/devbox.json @@ -21,7 +21,7 @@ "GOOS=linux GOARCH=arm64 go build -o dist/devbox-linux-arm64 ./cmd/devbox" ], "code": "code .", - "lint": "golangci-lint run && scripts/gofumpt.sh", + "lint": "golangci-lint run --timeout 5m && scripts/gofumpt.sh", "test": "go test -race -cover ./...", "update-examples": "devbox run build && go run testscripts/testrunner/updater/main.go" } From d75588fbc2aca68ad5732634d4ba9705ae10cf56 Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Tue, 10 Oct 2023 13:12:25 -0700 Subject: [PATCH 6/8] Fix --- .github/workflows/cli-tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cli-tests.yaml b/.github/workflows/cli-tests.yaml index 3f49fc402c7..0a0d2138349 100644 --- a/.github/workflows/cli-tests.yaml +++ b/.github/workflows/cli-tests.yaml @@ -81,6 +81,7 @@ jobs: - uses: crate-ci/typos@v1.13.16 golangci-lint: + needs: build-devbox strategy: matrix: os: [ubuntu-latest, macos-latest] From 2cfc1bf768e7a36d32b97f7bba1fbc4c3bd0a8d0 Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Tue, 10 Oct 2023 13:21:11 -0700 Subject: [PATCH 7/8] Update comment --- .github/workflows/cli-tests.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cli-tests.yaml b/.github/workflows/cli-tests.yaml index 0a0d2138349..89d01132968 100644 --- a/.github/workflows/cli-tests.yaml +++ b/.github/workflows/cli-tests.yaml @@ -96,7 +96,12 @@ jobs: go-version-file: ./go.mod cache: false - # TODO ADD nix only cache + # This can be reanabled once released version supports runx + # and we can remove needs: build-devbox + # - name: Install devbox + # uses: jetpack-io/devbox-install-action@v0.7.0 + # with: + # enable-cache: true - name: Mount golang cache uses: actions/cache@v3 From c3672195b07a1fd2c4d58c65834a9004336d2cf7 Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Tue, 10 Oct 2023 14:03:52 -0700 Subject: [PATCH 8/8] Bump timout --- .github/workflows/cli-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cli-tests.yaml b/.github/workflows/cli-tests.yaml index 89d01132968..b214c44a16c 100644 --- a/.github/workflows/cli-tests.yaml +++ b/.github/workflows/cli-tests.yaml @@ -148,7 +148,7 @@ jobs: os: macos-latest runs-on: ${{ matrix.os }} - timeout-minutes: ${{ (github.ref == 'refs/heads/main' || inputs.run-mac-tests) && 37 || 25 }} + timeout-minutes: 37 steps: - name: Maximize build disk space uses: easimon/maximize-build-space@v8