diff --git a/.github/workflows/check-by-name.yml b/.github/workflows/check-by-name.yml index 294775fa1c8e..43237d36bee1 100644 --- a/.github/workflows/check-by-name.yml +++ b/.github/workflows/check-by-name.yml @@ -79,40 +79,8 @@ jobs: echo "headSha=$(git rev-parse HEAD^2)" >> "$GITHUB_ENV" - uses: cachix/install-nix-action@7ac1ec25491415c381d9b62f0657c7a028df52a7 # v24 - - name: Determining channel to use for dependencies - run: | - echo "Determining the preferred channel to use for PR base branch $GITHUB_BASE_REF" - if [[ "$GITHUB_BASE_REF" =~ ^(release|staging|staging-next)-([0-9][0-9]\.[0-9][0-9])$ ]]; then - # Use the release channel for all PRs to release-XX.YY, staging-XX.YY and staging-next-XX.YY - channel=nixos-${BASH_REMATCH[2]} - echo "PR is for a release branch, preferred channel is $channel" - else - # Use the nixos-unstable channel for all other PRs - channel=nixos-unstable - echo "PR is for a non-release branch, preferred channel is $channel" - fi - # Check that the channel exists. It doesn't exist for fresh release branches - if ! curl -fSs "https://channels.nixos.org/$channel"; then - # Fall back to nixos-unstable, makes sense for fresh release branches - echo "Preferred channel $channel could not be fetched, falling back to nixos-unstable" - channel=nixos-unstable - fi - echo "channel=$channel" >> "$GITHUB_ENV" - - name: Fetching latest version of channel - run: | - echo "Fetching latest version of channel $channel" - # This is probably the easiest way to get Nix to output the path to a downloaded channel! - nixpkgs=$(nix-instantiate --find-file nixpkgs -I nixpkgs=channel:"$channel") - # This file only exists in channels - rev=$(<"$nixpkgs"/.git-revision) - echo "Channel $channel is at revision $rev" - echo "nixpkgs=$nixpkgs" >> "$GITHUB_ENV" - echo "rev=$rev" >> "$GITHUB_ENV" - - name: Fetching pre-built nixpkgs-check-by-name from the channel - run: | - echo "Fetching pre-built nixpkgs-check-by-name from channel $channel at revision $rev" - # Passing --max-jobs 0 makes sure that we won't build anything - nix-build "$nixpkgs" -A tests.nixpkgs-check-by-name --max-jobs 0 + - name: Fetching the tool + run: pkgs/test/nixpkgs-check-by-name/scripts/fetch-tool.sh "$GITHUB_BASE_REF" result - name: Running nixpkgs-check-by-name run: | echo "Checking whether the check succeeds on the base branch $GITHUB_BASE_REF" diff --git a/pkgs/test/nixpkgs-check-by-name/scripts/fetch-tool.sh b/pkgs/test/nixpkgs-check-by-name/scripts/fetch-tool.sh new file mode 100755 index 000000000000..fc4df11e747e --- /dev/null +++ b/pkgs/test/nixpkgs-check-by-name/scripts/fetch-tool.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Fetches the prebuilt nixpkgs-check-by-name to use from +# the NixOS channel corresponding to the given base branch + +set -euo pipefail + +if (( $# < 2 )); then + echo >&2 "Usage: $0 BASE_BRANCH OUTPUT_PATH" + echo >&2 "BASE_BRANCH: The base branch to use, e.g. master or release-23.11" + echo >&2 "OUTPUT_PATH: The output symlink path for the tool" + exit 1 +fi +baseBranch=$1 +output=$2 + +echo >&2 -n "Determining the channel to use for PR base branch $baseBranch.. " +if [[ "$baseBranch" =~ ^(release|staging|staging-next)-([0-9][0-9]\.[0-9][0-9])$ ]]; then + # Use the release channel for all PRs to release-XX.YY, staging-XX.YY and staging-next-XX.YY + preferredChannel=nixos-${BASH_REMATCH[2]} +else + # Use the nixos-unstable channel for all other PRs + preferredChannel=nixos-unstable +fi + +# Check that the channel exists. It doesn't exist for fresh release branches +if curl -fSs "https://channels.nixos.org/$preferredChannel"; then + channel=$preferredChannel + echo >&2 "$channel" +else + # Fall back to nixos-unstable, makes sense for fresh release branches + channel=nixos-unstable + echo >&2 -e "\e[33mWarning: Preferred channel $preferredChannel could not be fetched, using fallback: $channel\e[0m" +fi + +echo >&2 -n "Fetching latest version of channel $channel.. " +# This is probably the easiest way to get Nix to output the path to a downloaded channel! +nixpkgs=$(nix-instantiate --find-file nixpkgs -I nixpkgs=channel:"$channel") +echo >&2 "$nixpkgs" + +# This file only exists in channels +echo >&2 -e "Git revision of channel $channel is \e[34m$(<"$nixpkgs/.git-revision")\e[0m" + +echo >&2 -n "Fetching the prebuilt version of nixpkgs-check-by-name.. " +nix-build -o "$output" "$nixpkgs" -A tests.nixpkgs-check-by-name -j 0 >/dev/null +realpath >&2 "$output"