about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-12-16 03:13:12 +0100
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-12-20 17:38:03 +0100
commit92238ac52d13f6af1158eb8ae0b1132c79cdef33 (patch)
treeaf70788bb024d64db946f9ae0a327267dec06ccc /pkgs
parentc6267887db1379c3854c4f604b121b6ff7560a7a (diff)
downloadnixlib-92238ac52d13f6af1158eb8ae0b1132c79cdef33.tar
nixlib-92238ac52d13f6af1158eb8ae0b1132c79cdef33.tar.gz
nixlib-92238ac52d13f6af1158eb8ae0b1132c79cdef33.tar.bz2
nixlib-92238ac52d13f6af1158eb8ae0b1132c79cdef33.tar.lz
nixlib-92238ac52d13f6af1158eb8ae0b1132c79cdef33.tar.xz
nixlib-92238ac52d13f6af1158eb8ae0b1132c79cdef33.tar.zst
nixlib-92238ac52d13f6af1158eb8ae0b1132c79cdef33.zip
tests.nixpkgs-check-by-name: Create script to run locally
Due to the check soon depending on the base branch (see `--base`),
the CI check can't reasonably share all code with a local check.
We can still make a script to run it locally, just not sharing all code.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/by-name/README.md11
-rwxr-xr-xpkgs/test/nixpkgs-check-by-name/scripts/run-local.sh66
2 files changed, 71 insertions, 6 deletions
diff --git a/pkgs/by-name/README.md b/pkgs/by-name/README.md
index a7cdc57201df..948003bb5573 100644
--- a/pkgs/by-name/README.md
+++ b/pkgs/by-name/README.md
@@ -112,12 +112,11 @@ There's some limitations as to which packages can be defined using this structur
 
 CI performs [certain checks](../test/nixpkgs-check-by-name/README.md#validity-checks) on the `pkgs/by-name` structure.
 This is done using the [`nixpkgs-check-by-name` tool](../test/nixpkgs-check-by-name).
-The version of this tool used is the one that corresponds to the NixOS channel of the PR base branch.
-See [here](../../.github/workflows/check-by-name.yml) for details.
 
-The tool can be run locally using
+You can locally emulate the CI check using
 
-```bash
-nix-build -A tests.nixpkgs-check-by-name
-result/bin/nixpkgs-check-by-name .
 ```
+$ ./pkgs/test/nixpkgs-check-by-name/scripts/run-local.sh master
+```
+
+See [here](../../.github/workflows/check-by-name.yml) for more info.
diff --git a/pkgs/test/nixpkgs-check-by-name/scripts/run-local.sh b/pkgs/test/nixpkgs-check-by-name/scripts/run-local.sh
new file mode 100755
index 000000000000..a1debe73f8ad
--- /dev/null
+++ b/pkgs/test/nixpkgs-check-by-name/scripts/run-local.sh
@@ -0,0 +1,66 @@
+#!/usr/bin/env bash
+# shellcheck disable=SC2016
+
+set -euo pipefail
+
+cleanup_commands=()
+cleanup() {
+    echo -n >&2 "Cleaning up.. "
+    # Run all cleanup commands in inverse order
+    for (( i=${#cleanup_commands[@]}-1; i>=0; i-- )); do
+        eval "${cleanup_commands[i]}"
+    done
+    echo >&2 "Done"
+}
+trap cleanup exit
+
+tmp=$(mktemp -d)
+cleanup_commands+=('rmdir "$tmp"')
+
+repo=https://github.com/NixOS/nixpkgs.git
+
+if (( $# != 0 )); then
+    baseBranch=$1
+    shift
+else
+    echo >&2 "Usage: $0 BASE_BRANCH [REPOSITORY]"
+    echo >&2 "BASE_BRANCH: The base branch to use, e.g. master or release-23.11"
+    echo >&2 "REPOSITORY: The repository to fetch the base branch from, defaults to $repo"
+    exit 1
+fi
+
+if (( $# != 0 )); then
+    repo=$1
+    shift
+fi
+
+if [[ -n "$(git status --porcelain)" ]]; then
+    echo >&2 -e "\e[33mWarning: Dirty tree, uncommitted changes won't be taken into account\e[0m"
+fi
+headSha=$(git rev-parse HEAD)
+echo >&2 -e "Using HEAD commit \e[34m$headSha\e[0m"
+
+echo >&2 -n "Creating Git worktree for the HEAD commit in $tmp/merged.. "
+git worktree add --detach -q "$tmp/merged" HEAD
+cleanup_commands+=('git worktree remove --force "$tmp/merged"')
+echo >&2 "Done"
+
+echo >&2 -n "Fetching base branch $baseBranch to compare against.. "
+git fetch -q "$repo" refs/heads/"$baseBranch"
+baseSha=$(git rev-parse FETCH_HEAD)
+echo >&2 -e "\e[34m$baseSha\e[0m"
+
+echo >&2 -n "Creating Git worktree for the base branch in $tmp/base.. "
+git worktree add -q "$tmp/base" "$baseSha"
+cleanup_commands+=('git worktree remove --force "$tmp/base"')
+echo >&2 "Done"
+
+echo >&2 -n "Merging base branch into the HEAD commit in $tmp/merged.. "
+git -C "$tmp/merged" merge -q --no-edit "$baseSha"
+echo >&2 -e "\e[34m$(git -C "$tmp/merged" rev-parse HEAD)\e[0m"
+
+"$tmp/merged/pkgs/test/nixpkgs-check-by-name/scripts/fetch-tool.sh" "$baseBranch" "$tmp/tool"
+cleanup_commands+=('rm "$tmp/tool"')
+
+echo >&2 "Running nixpkgs-check-by-name.."
+"$tmp/tool/bin/nixpkgs-check-by-name" "$tmp/merged"