diff options
author | Christian Breunig <christian@breunig.cc> | 2024-02-25 08:41:46 +0100 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2024-02-25 08:49:11 +0100 |
commit | 7c27657c79046dac8ae509a4eacb1a3a152e2d23 (patch) | |
tree | 6c12a69a74f425442658af9b218a200a2d872ae0 /scripts | |
parent | a3e60a00b400a1bad8609d5ce1abb0bb7abed7bc (diff) | |
download | vyos-build-7c27657c79046dac8ae509a4eacb1a3a152e2d23.tar.gz vyos-build-7c27657c79046dac8ae509a4eacb1a3a152e2d23.zip |
T6064: add build error if branch information from Git repository is missing
This was discussed in slack, where a user was missing the Git commit ID in his
custom build
Reason is/was:
git clone --single-branch -b 1.4.0-epa1 https://github.com/vyos/vyos-build
Checks out the 1.4.0-epa1 tag as HEAD and does not clone any branch information.
This results in:
>>> import git
>>> repo = git.Repo('.')
>>> repo.head.object.hexsha[:14]
'bcac2eb1f9b49c'
>>> git_branch = repo.active_branch.name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/git/repo/base.py", line 881, in active_branch
return self.head.reference
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/git/refs/symbolic.py", line 311, in _get_reference
raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
TypeError: HEAD is a detached symbolic reference as it points to 'bcac2eb1f9b49cc15ebda65838e5465543dbb9c6'
during the build. The exception handler resets the branch and commit name to an empty string: https://github.com/vyos/vyos-build/blob/a3e60a00b400a1bad8609d5ce1abb0bb7abed7bc/scripts/build-vyos-image#L281-L296
This now adds a proper error message during build so it fails early.
(07:46) vyos_bld 08278c5a1172:/vyos/vyos-build # isobuild -test
Building custom VyOS version: 1.5-test-202402250746
I: Checking if packages required for VyOS image build are installed
build/config
Could not retrieve information from git: HEAD is a detached symbolic reference as it points to '39612f541e55bea19868f50f16d7a6c6e0034ed2'
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build-vyos-image | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/scripts/build-vyos-image b/scripts/build-vyos-image index 6b47fca7..ed00175d 100755 --- a/scripts/build-vyos-image +++ b/scripts/build-vyos-image @@ -290,10 +290,9 @@ if __name__ == "__main__": # Retrieve git branch name git_branch = repo.active_branch.name except Exception as e: - print("Could not retrieve information from git: {0}".format(str(e))) + exit(f'Could not retrieve information from git: {e}') build_git = "" git_branch = "" - git_commit = "" # Create the build version string if build_config['build_type'] == 'development': |