From a311c4a2b0e606f8635a11f853a58a09f9073bbe Mon Sep 17 00:00:00 2001 From: Ivan Gabaldon Date: Wed, 7 May 2025 12:25:47 +0200 Subject: [PATCH] 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. --- .github/workflows/container.yml | 6 ------ .github/workflows/integration.yml | 4 ---- manage | 7 ------- searx/version.py | 6 ++++++ 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 15f9ba136..5e80ae8a0 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -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 diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 34d22803a..a64e7a07e 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -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 diff --git a/manage b/manage index 7bdefc312..0c9feda54 100755 --- a/manage +++ b/manage @@ -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" diff --git a/searx/version.py b/searx/version.py index d2013808b..565cc7e7a 100644 --- a/searx/version.py +++ b/searx/version.py @@ -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: