ci: move formatting checks to nix

This commit is contained in:
Jake Hillion 2023-12-14 15:18:24 +00:00
parent 8bf7dbae9f
commit 952d3e75c8
3 changed files with 119 additions and 24 deletions

View File

@ -51,6 +51,10 @@ workflows:
exclude_regex: ".*inheritance_polymorphic.*|.*arrays_member_int0|.*fbstring.*|.*std_string_*|.*multi_arg_tb_.*|.*ignored_a"
executors:
nix-docker:
docker:
- image: nixos/nix:latest
resource_class: small
ubuntu-docker:
docker:
- image: ubuntu:jammy
@ -62,33 +66,12 @@ executors:
jobs:
lint:
executor: ubuntu-docker
executor: nix-docker
steps:
- run:
name: Install dependencies
command: |
apt-get update
apt-get install -y \
clang-format \
git \
python3-pip
# click broke semver with 8.1.0, causing issues for black
pip install click==8.0.0 black isort
environment:
DEBIAN_FRONTEND: noninteractive
- checkout
- run:
name: clang-format
command: |
git ls-files '*.cpp' '*.h' | xargs clang-format --fallback-style=Google -i
git ls-files '*.py' | xargs black
git ls-files '*.py' | xargs isort
git diff --exit-code
- run:
name: python linting
command: |
black --check --diff test/
isort --check --diff test/
name: Flake check
command: nix --experimental-features 'nix-command flakes' flake check
build:
# TODO this job could be run in Docker

82
flake.lock Normal file
View File

@ -0,0 +1,82 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1696375444,
"narHash": "sha256-Sv0ICt/pXfpnFhTGYTsX6lUr1SljnuXWejYTI2ZqHa4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "81e8f48ebdecf07aab321182011b067aafc78896",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1695822946,
"narHash": "sha256-IQU3fYo0H+oGlqX5YrgZU3VRhbt2Oqe6KmslQKUO4II=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "720bd006d855b08e60664e4683ccddb7a9ff614a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

30
flake.nix Normal file
View File

@ -0,0 +1,30 @@
{
description = "A flake for building Object Introspection.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, treefmt-nix, ... }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs (pkgs: {
projectRootFile = "flake.nix";
settings.global.excludes = [ "./extern/**" ];
programs.nixfmt.enable = true;
programs.clang-format.enable = true;
programs.black.enable = true;
programs.isort.enable = true;
});
in {
formatter = treefmtEval.config.build.wrapper;
checks.formatting = treefmtEval.config.build.check self;
});
}