forked from Skynet/discord-bot
ci: improvements to building in pipeline
This commit is contained in:
parent
7c2d392e35
commit
d8b232b546
4 changed files with 93 additions and 58 deletions
|
@ -1,6 +1,3 @@
|
|||
# copied a good chunk from my bfom config
|
||||
image: rust:latest
|
||||
|
||||
stages:
|
||||
- lint
|
||||
- build
|
||||
|
@ -14,50 +11,45 @@ variables:
|
|||
- nix --extra-experimental-features 'nix-command flakes' profile install nixpkgs#attic-client
|
||||
- attic login skynet https://nix-cache.skynet.ie/ $CACHE_KEY
|
||||
- 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
|
||||
# runs on all commits/branches
|
||||
lint-clippy:
|
||||
stage: lint
|
||||
<<: *nix
|
||||
<<: *rules
|
||||
script:
|
||||
- rustup component add clippy
|
||||
- rustc --version
|
||||
- cargo version
|
||||
- cargo clippy
|
||||
- cargo test --verbose
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: never
|
||||
- changes:
|
||||
- src/**/*
|
||||
- Cargo.*
|
||||
when: always
|
||||
- nix --extra-experimental-features "nix-command flakes" build --verbose .#clippy
|
||||
|
||||
lint-fmt:
|
||||
stage: lint
|
||||
<<: *nix
|
||||
<<: *rules
|
||||
script:
|
||||
- rustup component add rustfmt
|
||||
- rustc --version
|
||||
- cargo version
|
||||
- cargo fmt -- --check
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: never
|
||||
- changes:
|
||||
- src/**/*
|
||||
- Cargo.*
|
||||
when: always
|
||||
- nix --extra-experimental-features "nix-command flakes" build --verbose .#fmt
|
||||
|
||||
|
||||
# has to actually compile
|
||||
build:
|
||||
stage: build
|
||||
tags:
|
||||
- nix
|
||||
before_script:
|
||||
- *scripts_cache
|
||||
<<: *nix
|
||||
script:
|
||||
- attic watch-store skynet-cache &
|
||||
- nix --extra-experimental-features "nix-command flakes" build --verbose
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
|
|
|
@ -37,4 +37,4 @@ chrono = "0.4.26"
|
|||
lettre = "0.10.4"
|
||||
maud = "0.25.0"
|
||||
|
||||
serde = "1.0.188"
|
||||
serde = "1.0.188"
|
38
flake.lock
38
flake.lock
|
@ -1,55 +1,57 @@
|
|||
{
|
||||
"nodes": {
|
||||
"naersk": {
|
||||
"crane": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1692351612,
|
||||
"narHash": "sha256-KTGonidcdaLadRnv9KFgwSMh1ZbXoR/OBmPjeNMhFwU=",
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"rev": "78789c30d64dea2396c9da516bbcc8db3a475207",
|
||||
"lastModified": 1717386774,
|
||||
"narHash": "sha256-YYMGHDo4f+tu7k2q6hWNiI5C8gAN5eksb3g3EbKFf4k=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "ad21f86e47a2751faa99aecd0d494be70411d5e9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1693060755,
|
||||
"narHash": "sha256-KNsbfqewEziFJEpPR0qvVz4rx0x6QXxw1CcunRhlFdk=",
|
||||
"lastModified": 1714656196,
|
||||
"narHash": "sha256-kjQkA98lMcsom6Gbhw8SYzmwrSo+2nruiTcTZp5jK7o=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c66ccfa00c643751da2fd9290e096ceaa30493fc",
|
||||
"rev": "94035b482d181af0a0f8f77823a790b256b7c3cc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1693087214,
|
||||
"narHash": "sha256-Kn1SSqRfPpqcI1MDy82JXrPT1WI8c03TA2F0xu6kS+4=",
|
||||
"lastModified": 1717144377,
|
||||
"narHash": "sha256-F/TKWETwB5RaR8owkPPi+SPJh83AQsm6KrQAlJ8v/uA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "f155f0cf4ea43c4e3c8918d2d327d44777b6cad4",
|
||||
"rev": "805a384895c696f802a9bf5bf4720f37385df547",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-23.05",
|
||||
"ref": "nixos-24.05",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"naersk": "naersk",
|
||||
"crane": "crane",
|
||||
"nixpkgs": "nixpkgs_2",
|
||||
"utils": "utils"
|
||||
}
|
||||
|
|
57
flake.nix
57
flake.nix
|
@ -2,8 +2,8 @@
|
|||
description = "Skynet Discord Bot";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-23.05";
|
||||
naersk.url = "github:nix-community/naersk";
|
||||
nixpkgs.url = "nixpkgs/nixos-24.05";
|
||||
crane.url = "github:ipetkov/crane";
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
|
@ -21,26 +21,67 @@
|
|||
self,
|
||||
nixpkgs,
|
||||
utils,
|
||||
naersk,
|
||||
crane,
|
||||
}:
|
||||
utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
pkgs = nixpkgs.legacyPackages."${system}";
|
||||
naersk-lib = naersk.lib."${system}";
|
||||
|
||||
package_name = "skynet_discord_bot";
|
||||
desc = "Skynet Discord Bot";
|
||||
in rec {
|
||||
# `nix build`
|
||||
packages."${package_name}" = naersk-lib.buildPackage {
|
||||
|
||||
craneLib = crane.mkLib pkgs;
|
||||
|
||||
src = craneLib.cleanCargoSource (craneLib.path ./.);
|
||||
|
||||
commonArgs = {
|
||||
src = src;
|
||||
strictDeps = true;
|
||||
|
||||
pname = "${package_name}";
|
||||
root = ./.;
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
# Add extra build inputs here, etc.
|
||||
openssl
|
||||
];
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
# Add extra native build inputs here, etc.
|
||||
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}";
|
||||
|
||||
# `nix run`
|
||||
|
|
Loading…
Reference in a new issue