From 8c46c5bab3a62279ce3b5d66b0b3d39826bfbbe8 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sun, 13 Oct 2024 21:31:57 -0700 Subject: [PATCH] *: Migrate to Nix flakes, deprecate non-GHA CI This simplifies the project setup and makes it easier to maintain the CI pipeline. --- .build.yml | 48 ------------------------------ .github/workflows/test.yml | 44 +++++++++++---------------- .gitlab-ci.yml | 53 --------------------------------- flake.lock | 61 ++++++++++++++++++++++++++++++++++++++ flake.nix | 31 +++++++++++++++++++ shell.nix | 11 ------- 6 files changed, 109 insertions(+), 139 deletions(-) delete mode 100644 .build.yml delete mode 100644 .gitlab-ci.yml create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/.build.yml b/.build.yml deleted file mode 100644 index 26cf584..0000000 --- a/.build.yml +++ /dev/null @@ -1,48 +0,0 @@ -image: "nixos/latest" -packages: - - nixos.go - - nixos.git - - nixos.gcc -sources: - - https://github.com/diamondburned/arikawa -secrets: - # Integration test secrets. - - f51d6157-b4be-4697-99d0-6cd129243f63 -environment: - GO111MODULE: "on" - CGO_ENABLED: "1" - # Integration test variables. - SHARD_COUNT: "2" - tested: "./api,./gateway,./bot,./discord" - cov_file: "/tmp/cov_results" - dismock: "github.com/mavolin/dismock/v2/pkg/dismock" - dismock_v: "259685b84e4b6ab364b0fd858aac2aa2dfa42502" - -tasks: - - generate: |- - cd arikawa - go generate ./... - - if [[ "$(git status --porcelain)" ]]; then - echo "Repository differ after regeneration." - exit 1 - fi - - - build: cd arikawa && go build ./... - - unit: cd arikawa && go test -tags unitonly -race ./... - - - integration: |- - sh -c ' - test -f ~/.env || { - echo "Skipped integration tests." - exit 0 - } - - cd arikawa - go get ./... - go get $dismock@$dismock_v - - source ~/.env - go test -coverpkg $tested -coverprofile $cov_file -race ./... $dismock - go tool cover -func $cov_file - ' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f72817d..67a49b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,24 +12,13 @@ on: type: boolean jobs: - nix-env: - name: Initialize Nix - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Install Nix packages - uses: diamondburned/cache-install@main - generate: name: Generate - needs: [nix-env] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Install Nix packages - uses: diamondburned/cache-install@main + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Generate run: | @@ -46,35 +35,36 @@ jobs: fi env: GITHUB_REF: ${{ github.ref }} + shell: nix develop -c {0} build: name: Build runs-on: ubuntu-latest needs: [generate] steps: - - uses: actions/checkout@v2 - - - name: Install Nix packages - uses: diamondburned/cache-install@main + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Build - run: go build ./... + run: go build -v ./... + shell: nix develop -c {0} unit-test: name: Unit Test runs-on: ubuntu-latest needs: [build] steps: - - uses: actions/checkout@v2 - - - name: Install Nix packages - uses: diamondburned/cache-install@main + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Test run: go test $TEST_FLAGS ./... env: TEST_FLAGS: >- -v=${{ runner.debug && '1' || '0' }} + shell: nix develop -c {0} integration-test: name: Integration Test @@ -82,10 +72,9 @@ jobs: runs-on: ubuntu-latest needs: [build] steps: - - uses: actions/checkout@v2 - - - name: Install Nix packages - uses: diamondburned/cache-install@main + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Test run: | @@ -99,6 +88,7 @@ jobs: GUILD_ID: ${{ secrets.GUILD_ID }} VOICE_ID: ${{ secrets.VOICE_ID }} BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + shell: nix develop -c {0} - name: Upload coverage profile uses: actions/upload-artifact@v3 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 3379c48..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,53 +0,0 @@ -{ - "image": "golang:alpine", - "variables": { - "GO111MODULE": "on", - "CGO_ENABLED": "1", # for the race detector - "COV": "/tmp/cov_results", - "dismock": "github.com/mavolin/dismock/v3/pkg/dismock", - "dismock_v": "259685b84e4b6ab364b0fd858aac2aa2dfa42502", - # used only in integration_test - "tested": "./api,./gateway,./bot,./discord" - }, - "before_script": [ - "apk add git build-base" - "go get ./...", - "go get $dismock@$dismock_v", - ], - "stages": [ - "build", - "test" - ], - "build_test": { - "stage": "build", - "script": [ - "go build ./..." - ] - }, - "unit_test": { - "stage": "test", - "timeout": "4m", # 4 minutes - # Don't run the test if we have a $BOT_TOKEN, because - # integration_test will run instead. - "except": { - "variables": [ "$BOT_TOKEN" ] - }, - "script": [ - "go test -coverpkg $tested -coverprofile $COV -tags unitonly -v -race ./... $dismock", - "go tool cover -func $COV" - ] - }, - "integration_test": { - "stage": "test", - "timeout": "8m", # 8 minutes - # Run the test only if we have $BOT_TOKEN, else fallback to unit - # tests. - "only": { - "variables": [ "$BOT_TOKEN", "$CHANNEL_ID", "$VOICE_ID" ] - }, - "script": [ - "go test -coverpkg $tested -coverprofile $COV -v -race ./... $dismock", - "go tool cover -func $COV" - ] - } -} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..243467a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5a1b483 --- /dev/null +++ b/flake.nix @@ -0,0 +1,31 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + }: + + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + go_1_22 + gopls + go-tools + + nixfmt-rfc-style + ]; + }; + } + ); +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index ac43e15..0000000 --- a/shell.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ pkgs ? import {} }: - -pkgs.mkShell { - buildInputs = with pkgs; [ - go - gopls - go-tools - ]; - - CGO_ENABLED = "1"; -}