1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-10-31 20:14:21 +00:00

*: Migrate to Nix flakes, deprecate non-GHA CI

This simplifies the project setup and makes it easier to maintain the
CI pipeline.
This commit is contained in:
diamondburned 2024-10-13 21:31:57 -07:00
parent 85debd971d
commit 8c46c5bab3
No known key found for this signature in database
GPG key ID: D78C4471CE776659
6 changed files with 109 additions and 139 deletions

View file

@ -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
'

View file

@ -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

View file

@ -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"
]
}
}

61
flake.lock Normal file
View file

@ -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
}

31
flake.nix Normal file
View file

@ -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
];
};
}
);
}

View file

@ -1,11 +0,0 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
go
gopls
go-tools
];
CGO_ENABLED = "1";
}