gerrit-one-way-sync: disallow auto-merging a staging iteration into master

This commit is contained in:
Yureka 2024-07-20 00:31:54 +02:00
parent 6f7675fa22
commit 73b8952acb

View file

@ -15,7 +15,7 @@ let
mkSyncService = targetRef: { name, fromUri, fromRefspec, localRefspec, ... }: { mkSyncService = targetRef: { name, fromUri, fromRefspec, localRefspec, ... }: {
path = [ pkgs.gitFull pkgs.openssh ]; path = [ pkgs.gitFull pkgs.openssh ];
script = '' script = ''
set -x set -xe
trap "git worktree prune && git worktree remove -f ${name}" EXIT trap "git worktree prune && git worktree remove -f ${name}" EXIT
if [ ! -d "/var/lib/onewaysync/nixpkgs" ]; then if [ ! -d "/var/lib/onewaysync/nixpkgs" ]; then
@ -33,7 +33,15 @@ let
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 (localRefspec == "refs/heads/master") ''
OLD_STDENV=$(nix eval -f . stdenv.outPath)
'' + ''
git merge FETCH_HEAD git merge FETCH_HEAD
'' + lib.optionalString (localRefspec == "refs/heads/master") ''
NEW_STDENV=$(nix eval -f . stdenv.outPath)
# Do not allow auto-merging a staging iteration
test "$OLD_STDENV" = "$NEW_STDENV"
'' + ''
GIT_SSH_COMMAND='ssh -i ${cfg.deployKeyPath}' git push ${cfg.pushUrl} HEAD:${targetRef} GIT_SSH_COMMAND='ssh -i ${cfg.deployKeyPath}' git push ${cfg.pushUrl} HEAD:${targetRef}
''; '';
serviceConfig = { serviceConfig = {