fix(ows): per-job runtime directories + proper local refspec

The local refspec was weird and exploiting a edge case for the nixpkgs
jobs where local and from were the same.

We are more explicit now, which fixes the sandbox jobs.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
raito 2024-07-22 15:41:47 +02:00
parent d84a43b781
commit 62ccc0282b
2 changed files with 13 additions and 12 deletions

View file

@ -51,7 +51,7 @@
name = "nixpkgs-${branchName}"; name = "nixpkgs-${branchName}";
fromUri = "https://github.com/NixOS/nixpkgs"; fromUri = "https://github.com/NixOS/nixpkgs";
fromRefspec = branchName; fromRefspec = branchName;
localRefspec = "refs/remotes/origin/${branchName}"; localRefspec = branchName;
inherit timer; inherit timer;
}; };
in in
@ -81,7 +81,7 @@
name = "raito-unstable-sync"; name = "raito-unstable-sync";
fromUri = "https://github.com/NixOS/nixpkgs"; fromUri = "https://github.com/NixOS/nixpkgs";
fromRefspec = "nixos-unstable-small"; fromRefspec = "nixos-unstable-small";
localRefspec = "refs/remotes/origin/sandbox/raito/raito-unstable-small"; localRefspec = "sandbox/raito/raito-unstable-small";
timer = "*-*-* 12:00:00"; timer = "*-*-* 12:00:00";
}; };
@ -89,7 +89,7 @@
name = "raito-release-sync"; name = "raito-release-sync";
fromUri = "https://github.com/NixOS/nixpkgs"; fromUri = "https://github.com/NixOS/nixpkgs";
fromRefspec = "nixos-24.05"; fromRefspec = "nixos-24.05";
localRefspec = "refs/remotes/origin/sandbox/raito/raito-nixos-24.05"; localRefspec = "sandbox/raito/raito-nixos-24.05";
timer = "daily"; timer = "daily";
}; };
}; };

View file

@ -16,7 +16,8 @@ let
path = [ pkgs.gitFull pkgs.openssh pkgs.lix ]; path = [ pkgs.gitFull pkgs.openssh pkgs.lix ];
script = '' script = ''
set -xe set -xe
trap "git worktree prune && git worktree remove -f ${name}" EXIT RUNTIME_DIRECTORY="/run/onewaysync-${name}"
trap "git worktree remove -f "$RUNTIME_DIRECTORY"/${name}" EXIT
if [ ! -d "/var/lib/onewaysync/nixpkgs" ]; then if [ ! -d "/var/lib/onewaysync/nixpkgs" ]; then
echo "First run, synchronizing nixpkgs..." echo "First run, synchronizing nixpkgs..."
@ -26,19 +27,19 @@ let
cd /var/lib/onewaysync/nixpkgs cd /var/lib/onewaysync/nixpkgs
echo "Syncing ${fromUri}:${fromRefspec} to /var/lib/onewaysync/nixpkgs:${targetRef}" echo "Syncing ${fromUri}:${fromRefspec} to /var/lib/onewaysync/nixpkgs:${targetRef}"
echo "Current ref: $EXPECTED_REF" echo "Current ref: $EXPECTED_REF"
git worktree add -f ${cfg.workingDir}/${name} ${localRefspec} git worktree add -f "$RUNTIME_DIRECTORY"/${name} refs/remotes/origin/${localRefspec}
cd ${cfg.workingDir}/${name} cd "$RUNTIME_DIRECTORY"/${name}
git pull origin ${fromRefspec} git pull origin ${localRefspec}
EXPECTED_REF=$(git rev-list ${localRefspec} | head -1) EXPECTED_REF=$(git rev-list refs/remotes/origin/${localRefspec} | head -1)
git config user.name Fork-o-Tron git config user.name Fork-o-Tron
git config user.email noreply@forkos.org git config user.email noreply@forkos.org
git fetch ${fromUri} ${fromRefspec} git fetch ${fromUri} ${fromRefspec}
'' + lib.optionalString (!(lib.hasInfix "staging" localRefspec)) '' '' + lib.optionalString (!(lib.hasInfix "staging" localRefspec)) ''
OLD_STDENV=$(nix eval -f . stdenv.outPath --store /run/onewaysync) OLD_STDENV=$(nix eval -f . stdenv.outPath --store "$RUNTIME_DIRECTORY")
'' + '' '' + ''
git merge FETCH_HEAD git merge FETCH_HEAD
'' + lib.optionalString (!(lib.hasInfix "staging" localRefspec)) '' '' + lib.optionalString (!(lib.hasInfix "staging" localRefspec)) ''
NEW_STDENV=$(nix eval -f . stdenv.outPath --store /run/onewaysync) NEW_STDENV=$(nix eval -f . stdenv.outPath --store "$RUNTIME_DIRECTORY")
# Do not allow auto-merging a staging iteration # Do not allow auto-merging a staging iteration
test "$OLD_STDENV" = "$NEW_STDENV" test "$OLD_STDENV" = "$NEW_STDENV"
'' + '' '' + ''
@ -48,8 +49,8 @@ let
User = "git"; User = "git";
Group = "git"; Group = "git";
Type = "oneshot"; Type = "oneshot";
RuntimeDirectory = "onewaysync"; RuntimeDirectory = "onewaysync-${name}";
WorkingDirectory = cfg.workingDir; WorkingDirectory = "/run/onewaysync-${name}";
StateDirectory = "onewaysync"; StateDirectory = "onewaysync";
}; };
}; };