ci: improvements to building in pipeline

This commit is contained in:
silver 2024-06-03 23:06:27 +01:00
parent 7c2d392e35
commit d8b232b546
4 changed files with 93 additions and 58 deletions

View file

@ -1,6 +1,3 @@
# copied a good chunk from my bfom config
image: rust:latest
stages: stages:
- lint - lint
- build - build
@ -14,50 +11,45 @@ variables:
- nix --extra-experimental-features 'nix-command flakes' profile install nixpkgs#attic-client - nix --extra-experimental-features 'nix-command flakes' profile install nixpkgs#attic-client
- attic login skynet https://nix-cache.skynet.ie/ $CACHE_KEY - attic login skynet https://nix-cache.skynet.ie/ $CACHE_KEY
- attic use skynet-cache - attic use skynet-cache
- attic watch-store skynet-cache &
.build_template: &nix
tags:
- nix
before_script:
- *scripts_cache
.rules_template: &rules
rules:
- if: $CI_COMMIT_TAG
when: never
- changes:
- src/**/*
- Cargo.*
when: always
# clippy and fmt are magic # clippy and fmt are magic
# runs on all commits/branches # runs on all commits/branches
lint-clippy: lint-clippy:
stage: lint stage: lint
<<: *nix
<<: *rules
script: script:
- rustup component add clippy - nix --extra-experimental-features "nix-command flakes" build --verbose .#clippy
- rustc --version
- cargo version
- cargo clippy
- cargo test --verbose
rules:
- if: $CI_COMMIT_TAG
when: never
- changes:
- src/**/*
- Cargo.*
when: always
lint-fmt: lint-fmt:
stage: lint stage: lint
<<: *nix
<<: *rules
script: script:
- rustup component add rustfmt - nix --extra-experimental-features "nix-command flakes" build --verbose .#fmt
- rustc --version
- cargo version
- cargo fmt -- --check
rules:
- if: $CI_COMMIT_TAG
when: never
- changes:
- src/**/*
- Cargo.*
when: always
# has to actually compile # has to actually compile
build: build:
stage: build stage: build
tags: <<: *nix
- nix
before_script:
- *scripts_cache
script: script:
- attic watch-store skynet-cache &
- nix --extra-experimental-features "nix-command flakes" build --verbose - nix --extra-experimental-features "nix-command flakes" build --verbose
rules: rules:
- if: $CI_COMMIT_TAG - if: $CI_COMMIT_TAG

View file

@ -1,55 +1,57 @@
{ {
"nodes": { "nodes": {
"naersk": { "crane": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"lastModified": 1692351612, "lastModified": 1717386774,
"narHash": "sha256-KTGonidcdaLadRnv9KFgwSMh1ZbXoR/OBmPjeNMhFwU=", "narHash": "sha256-YYMGHDo4f+tu7k2q6hWNiI5C8gAN5eksb3g3EbKFf4k=",
"owner": "nix-community", "owner": "ipetkov",
"repo": "naersk", "repo": "crane",
"rev": "78789c30d64dea2396c9da516bbcc8db3a475207", "rev": "ad21f86e47a2751faa99aecd0d494be70411d5e9",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-community", "owner": "ipetkov",
"repo": "naersk", "repo": "crane",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1693060755, "lastModified": 1714656196,
"narHash": "sha256-KNsbfqewEziFJEpPR0qvVz4rx0x6QXxw1CcunRhlFdk=", "narHash": "sha256-kjQkA98lMcsom6Gbhw8SYzmwrSo+2nruiTcTZp5jK7o=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "c66ccfa00c643751da2fd9290e096ceaa30493fc", "rev": "94035b482d181af0a0f8f77823a790b256b7c3cc",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "owner": "NixOS",
"type": "indirect" "ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
} }
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1693087214, "lastModified": 1717144377,
"narHash": "sha256-Kn1SSqRfPpqcI1MDy82JXrPT1WI8c03TA2F0xu6kS+4=", "narHash": "sha256-F/TKWETwB5RaR8owkPPi+SPJh83AQsm6KrQAlJ8v/uA=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "f155f0cf4ea43c4e3c8918d2d327d44777b6cad4", "rev": "805a384895c696f802a9bf5bf4720f37385df547",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "id": "nixpkgs",
"ref": "nixos-23.05", "ref": "nixos-24.05",
"type": "indirect" "type": "indirect"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"naersk": "naersk", "crane": "crane",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2",
"utils": "utils" "utils": "utils"
} }

View file

@ -2,8 +2,8 @@
description = "Skynet Discord Bot"; description = "Skynet Discord Bot";
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixos-23.05"; nixpkgs.url = "nixpkgs/nixos-24.05";
naersk.url = "github:nix-community/naersk"; crane.url = "github:ipetkov/crane";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
}; };
@ -21,26 +21,67 @@
self, self,
nixpkgs, nixpkgs,
utils, utils,
naersk, crane,
}: }:
utils.lib.eachDefaultSystem ( utils.lib.eachDefaultSystem (
system: let system: let
pkgs = nixpkgs.legacyPackages."${system}"; pkgs = nixpkgs.legacyPackages."${system}";
naersk-lib = naersk.lib."${system}";
package_name = "skynet_discord_bot"; package_name = "skynet_discord_bot";
desc = "Skynet Discord Bot"; desc = "Skynet Discord Bot";
in rec {
# `nix build` craneLib = crane.mkLib pkgs;
packages."${package_name}" = naersk-lib.buildPackage {
src = craneLib.cleanCargoSource (craneLib.path ./.);
commonArgs = {
src = src;
strictDeps = true;
pname = "${package_name}"; pname = "${package_name}";
root = ./.;
buildInputs = with pkgs; [ buildInputs = with pkgs; [
# Add extra build inputs here, etc.
openssl openssl
];
nativeBuildInputs = with pkgs; [
# Add extra native build inputs here, etc.
pkg-config pkg-config
]; ];
}; };
cargoArtifacts = craneLib.buildDepsOnly (commonArgs
// {
pname = "${package_name}-deps";
});
clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
fmt = craneLib.cargoFmt {
inherit src;
};
result = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
});
in rec {
packages = {
# nix build --verbose
"${package_name}" = result;
# nix build --verbose .#clippy
clippy = clippy;
# nix build --verbose .#fmt
fmt = fmt;
};
defaultPackage = packages."${package_name}"; defaultPackage = packages."${package_name}";
# `nix run` # `nix run`