releng: fix the git push

This was broken because gerrit requires that the revision actually
is known before it is pushed as a tag.

Also, arguably this fixes the original problem mentioned in
https://git.lix.systems/lix-project/lix/issues/439

Change-Id: I0373ac01584440f18d32b8da5699bb359cc2c89a
This commit is contained in:
Jade Lovelace 2024-08-07 20:51:25 -07:00
parent 83247b1c38
commit 7246c2d104
2 changed files with 27 additions and 2 deletions

View file

@ -2,6 +2,7 @@ import json
import subprocess import subprocess
import itertools import itertools
import textwrap import textwrap
import logging
from pathlib import Path from pathlib import Path
import tempfile import tempfile
import hashlib import hashlib
@ -15,6 +16,8 @@ from .version import VERSION, RELEASE_NAME, MAJOR, OFFICIAL_RELEASE
from .gitutils import verify_are_on_tag, git_preconditions from .gitutils import verify_are_on_tag, git_preconditions
from . import release_notes from . import release_notes
log = logging.getLogger(__name__)
$RAISE_SUBPROC_ERROR = True $RAISE_SUBPROC_ERROR = True
$XONSH_SHOW_TRACEBACK = True $XONSH_SHOW_TRACEBACK = True
@ -55,6 +58,9 @@ def official_release_commit_tag(force_tag=False):
git commit -m @(message) git commit -m @(message)
git tag @(['-f'] if force_tag else []) -a -m @(message) @(VERSION) git tag @(['-f'] if force_tag else []) -a -m @(message) @(VERSION)
with open('releng/prev-git-branch.txt', 'w') as fh:
fh.write(prev_branch)
return prev_branch return prev_branch
@ -235,8 +241,24 @@ def upload_artifacts(env: RelengEnvironment, noconfirm=False, no_check_git=False
print('[+] Upload manual') print('[+] Upload manual')
upload_manual(env) upload_manual(env)
print('[+] git push tag') prev_branch = None
git push @(['-f'] if force_push_tag else []) @(env.git_repo) f'{VERSION}:refs/tags/{VERSION}' try:
with open('releng/prev-git-branch.txt', 'r') as fh:
prev_branch = fh.read().strip()
except FileNotFoundError:
log.warn('Cannot find previous git branch file, skipping pushing git objects')
if prev_branch:
print('[+] git push to the repo')
# We have to push the ref to gerrit for review at least such that the
# commit is known, before we can push it as a tag.
if env.git_repo_is_gerrit:
git push @(env.git_repo) f'{prev_branch}:refs/for/{prev_branch}'
else:
git push @(env.git_repo) f'{prev_branch}:{prev_branch}'
print('[+] git push tag')
git push @(['-f'] if force_push_tag else []) @(env.git_repo) f'{VERSION}:refs/tags/{VERSION}'
def do_tag_merge(force_tag=False, no_check_git=False): def do_tag_merge(force_tag=False, no_check_git=False):

View file

@ -52,6 +52,7 @@ class RelengEnvironment:
releases_bucket: str releases_bucket: str
docs_bucket: str docs_bucket: str
git_repo: str git_repo: str
git_repo_is_gerrit: bool
docker_targets: list[DockerTarget] docker_targets: list[DockerTarget]
@ -79,6 +80,7 @@ STAGING = RelengEnvironment(
cache_store_overlay={'secret-key': 'staging.key'}, cache_store_overlay={'secret-key': 'staging.key'},
releases_bucket='s3://staging-releases', releases_bucket='s3://staging-releases',
git_repo='ssh://git@git.lix.systems/lix-project/lix-releng-staging', git_repo='ssh://git@git.lix.systems/lix-project/lix-releng-staging',
git_repo_is_gerrit=False,
docker_targets=[ docker_targets=[
# latest will be auto tagged if appropriate # latest will be auto tagged if appropriate
DockerTarget('git.lix.systems/lix-project/lix-releng-staging', DockerTarget('git.lix.systems/lix-project/lix-releng-staging',
@ -113,6 +115,7 @@ PROD = RelengEnvironment(
cache_store_overlay={'secret-key': 'prod.key'}, cache_store_overlay={'secret-key': 'prod.key'},
releases_bucket='s3://releases', releases_bucket='s3://releases',
git_repo=guess_gerrit_remote(), git_repo=guess_gerrit_remote(),
git_repo_is_gerrit=True,
docker_targets=[ docker_targets=[
# latest will be auto tagged if appropriate # latest will be auto tagged if appropriate
DockerTarget('git.lix.systems/lix-project/lix', DockerTarget('git.lix.systems/lix-project/lix',