From 7992a6389dfef2c926df705a20de67efba2d26d9 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Tue, 24 Sep 2024 02:15:52 +0530 Subject: [PATCH] ci: Check for conventional commits --- .github/workflows/ci.yaml | 2 ++ dev/flake.lock | 28 ++++++---------------------- dev/flake.nix | 27 +++++++++++++++++++++++++++ flake.nix | 8 ++++++++ 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3acf834a..6c10e370 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,5 +15,7 @@ jobs: system: [ x86_64-linux, aarch64-darwin ] steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: om ci run: om ci --extra-access-tokens "github.com=${{ secrets.GITHUB_TOKEN }}" run --systems "${{ matrix.system }}" diff --git a/dev/flake.lock b/dev/flake.lock index a8512fac..a813ca08 100644 --- a/dev/flake.lock +++ b/dev/flake.lock @@ -18,14 +18,16 @@ }, "flake-parts": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs-lib": [ + "nixpkgs" + ] }, "locked": { - "lastModified": 1685662779, - "narHash": "sha256-cKDDciXGpMEjP1n6HlzKinN0H+oLmNpgeCTzYnsA2po=", + "lastModified": 1726153070, + "narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "71fb97f0d875fd4de4994dfb849f2c75e17eb6c3", + "rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a", "type": "github" }, "original": { @@ -104,24 +106,6 @@ "type": "github" } }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1685564631, - "narHash": "sha256-8ywr3AkblY4++3lIVxmrWZFzac7+f32ZEhH/A8pNscI=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "4f53efe34b3a8877ac923b9350c874e3dcd5dc0a", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "nixpkgs_2": { "locked": { "lastModified": 1680945546, diff --git a/dev/flake.nix b/dev/flake.nix index 26e59f28..f18008c7 100644 --- a/dev/flake.nix +++ b/dev/flake.nix @@ -2,6 +2,7 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; flake-root.url = "github:srid/flake-root"; treefmt-nix.url = "github:numtide/treefmt-nix"; pre-commit-hooks-nix = { @@ -32,6 +33,32 @@ nixpkgs-fmt.enable = true; }; }; + + # TODO: Move this under `CIApps` once `omnix` supports running them automatically + # CONSIDER: Generalise the script, see: https://github.com/juspay/services-flake/pull/338/files#r1773042527 + apps.cz-check = rec { + meta.description = program.meta.description; + program = pkgs.writeShellApplication { + name = "cz-check"; + runtimeInputs = with pkgs; [ config.pre-commit.settings.tools.commitizen git gnugrep coreutils ]; + meta.description = "Verify commit messages from the default branch to HEAD follow conventional commit format"; + text = '' + default_branch=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) + + # Get the latest commit on the default branch + # rev range using the `default_branch` branch name (e.g. main..HEAD), doesn't work in Github Actions + latest_default_commit=$(git rev-parse origin/"$default_branch") + + current_commit=$(git rev-parse HEAD) + + if [ "$latest_default_commit" = "$current_commit" ]; then + echo "No commits to check between $default_branch and HEAD." + else + cz check --rev-range "$latest_default_commit"..HEAD + fi + ''; + }; + }; devShells.default = pkgs.mkShell { packages = with pkgs; [ just diff --git a/flake.nix b/flake.nix index 59a62f30..e20c0f7f 100644 --- a/flake.nix +++ b/flake.nix @@ -34,6 +34,14 @@ dev = { inherit overrideInputs; dir = "./dev"; + steps = { + custom = { + cz-check = { + type = "app"; + name = "cz-check"; + }; + }; + }; }; doc = { dir = "./doc";