fix getting branch on fork branches

When running the version.py in CI, it only fetches a detached HEAD failing to get the reference. As I do not know very well if modifying the function will affect "normal" cases, I have preferred to use the variables provided by GHA to obtain the branch and the location of the repository.
This commit is contained in:
Ivan Gabaldon 2025-05-07 12:25:47 +02:00
parent e37bd4481f
commit a311c4a2b0
No known key found for this signature in database
GPG Key ID: 075587C93FA67582
4 changed files with 6 additions and 17 deletions

View File

@ -59,8 +59,6 @@ jobs:
uses: actions/checkout@v4
with:
persist-credentials: "false"
# make sure "make ci.container.build" can get the git branches
fetch-depth: "0"
- name: Setup cache Python
uses: actions/cache@v4
@ -121,8 +119,6 @@ jobs:
uses: actions/checkout@v4
with:
persist-credentials: "false"
# make sure "make ci.container.test" can get the git branches
fetch-depth: "0"
- if: ${{ matrix.emulation }}
name: Setup QEMU
@ -161,8 +157,6 @@ jobs:
uses: actions/checkout@v4
with:
persist-credentials: "false"
# make sure "make ci.container.push" can get the git history
fetch-depth: "0"
- if: env.DOCKERHUB_USERNAME != ''
name: Login to GHCR

View File

@ -119,8 +119,6 @@ jobs:
uses: actions/checkout@v4
with:
persist-credentials: "false"
# make sure "make ci.container.build" can get the git branches
fetch-depth: "0"
- name: Setup cache Python
uses: actions/cache@v4
@ -182,8 +180,6 @@ jobs:
uses: actions/checkout@v4
with:
persist-credentials: "false"
# make sure "make ci.container.test" can get the git branches
# fetch-depth: "0"
- if: ${{ matrix.emulation }}
name: Setup QEMU

7
manage
View File

@ -446,13 +446,6 @@ ci.container.build() {
python -m searx.version freeze
eval "$(python -m searx.version)"
# TODO: Remove this
echo $VERSION_STRING
echo $VERSION_TAG
echo $DOCKER_TAG
echo $GIT_URL
echo $GIT_BRANCH
# Get the last git commit id
version_gitcommit=$(echo "$VERSION_TAG" | cut -d+ -f2)
build_msg CONTAINER "Last commit: $version_gitcommit"

View File

@ -41,6 +41,12 @@ def subprocess_run(args, **kwargs):
def get_git_url_and_branch():
# handle GHA directly
if "GITHUB_REPOSITORY" in os.environ and "GITHUB_REF_NAME" in os.environ:
git_url = f"https://github.com/{os.environ['GITHUB_REPOSITORY']}"
git_branch = os.environ["GITHUB_REF_NAME"]
return git_url, git_branch
try:
ref = subprocess_run("git rev-parse --abbrev-ref @{upstream}")
except subprocess.CalledProcessError: