ci: check that old URLs aren't removed but redirected

(cherry picked from commit 43050baefb)
This commit is contained in:
Valentin Gagarin
2026-09-02 18:59:55 +02:00
committed by github-actions[bot]
parent 69c25fe8f7
commit 219e91b552
4 changed files with 79 additions and 0 deletions

View File

@@ -78,6 +78,36 @@ jobs:
# Tests multiple versions at once, let's make sure all of them run, so keep-going.
nix-build nixpkgs/untrusted/ci --arg nixpkgs ./nixpkgs/untrusted-pinned -A parse --keep-going
redirects:
runs-on: ubuntu-24.04-arm
timeout-minutes: 10
steps:
- name: Checkout merge and target commits
uses: $/.github/actions/checkout
with:
merged-as-untrusted-at: ${{ inputs.mergedSha }}
target-as-trusted-at: ${{ inputs.targetSha }}
- uses: cachix/install-nix-action@3dc140bfc76c49fbd4dd958429132e3746bcb086 # v31.11.5
- uses: cachix/cachix-action@ae1cbf444b9889291590b7d87f4b676406df16aa # v17
continue-on-error: true
with:
# The nixpkgs-gha cache should not be trusted or used outside of Nixpkgs and its forks' CI.
name: ${{ vars.CACHIX_NAME || 'nixpkgs-gha' }}
extraPullNames: nixpkgs-gha
authToken: ${{ secrets.CACHIX_AUTH_TOKEN_GHA }}
pushFilter: -source$
- name: Check manual redirect URLs are preserved
run: |
nix-build nixpkgs/untrusted/ci --arg nixpkgs ./nixpkgs/untrusted-pinned \
-A redirects-nixpkgs \
-A redirects-nixos \
--arg base ./nixpkgs/trusted \
--arg head ./nixpkgs/untrusted \
--keep-going
nixpkgs-vet:
runs-on: ubuntu-24.04-arm
timeout-minutes: 10

View File

@@ -75,6 +75,12 @@ rec {
nixpkgs-vet = pkgs.callPackage ./nixpkgs-vet.nix {
nix = pkgs.nixVersions.latest;
};
redirects-nixpkgs = pkgs.callPackage ./redirects-check.nix {
redirectsFile = "doc/redirects.json";
};
redirects-nixos = pkgs.callPackage ./redirects-check.nix {
redirectsFile = "nixos/doc/manual/redirects.json";
};
parse = pkgs.lib.recurseIntoAttrs {
nix_latest = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.latest; };
stable = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.stable; };

40
ci/redirects-check.nix Normal file
View File

@@ -0,0 +1,40 @@
{
lib,
jq,
runCommand,
writeText,
redirectsFile,
}:
{
base,
head,
}:
let
help = writeText "redirects-check-help" ''
Please don't remove old URLs, since this will break links and bookmarks.
Redirect them to a different anchor, such as a release note mentioning the removal.
To avoid manual book keeping, inside `nix-shell ${dirOf redirectsFile}` run:
redirects remove-and-redirect <old-id> <target-id>
'';
redirects =
root:
lib.fileset.toSource {
inherit root;
fileset = lib.path.append root redirectsFile;
};
in
runCommand "redirects-check" { nativeBuildInputs = [ jq ]; } ''
removed=$(comm -23 \
<(jq -r '.[][]' "${redirects base}/${redirectsFile}" | sort -u) \
<(jq -r '.[][]' "${redirects head}/${redirectsFile}" | sort -u))
if [ -n "$removed" ]; then
cat ${help}
echo
echo "URLs removed from ${redirectsFile}:"
while IFS= read -r url; do echo " $url"; done <<< "$removed"
exit 1
fi
touch $out
''

View File

@@ -28,6 +28,9 @@ This allows us to catch:
- Content that was moved from one location to another
- Various consistency errors in the redirects mapping
Additionally, we have a [CI check](../../../../ci/redirects-check.nix) that ensures no URLs are removed from the redirects files.
As a result, external links to the Nixpkgs and NixOS manuals never break.
### Design considerations
The creation, movement, and removal of every identifier is captured in the Git history.