From ee9f5599d295a0dd498e3010577d07c6a4c52cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20V=C3=A1zquez=20Gil?= Date: Fri, 30 Aug 2024 17:30:46 +0200 Subject: [PATCH 1/2] fix: Added branch name to image_tag when a branch is specified as the from value --- .github/workflows/build_images.yaml | 16 +--------------- .../workflows/build_images/build_images.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build_images.yaml b/.github/workflows/build_images.yaml index 7589b8f6..7c318150 100644 --- a/.github/workflows/build_images.yaml +++ b/.github/workflows/build_images.yaml @@ -94,20 +94,6 @@ jobs: ref: ${{ inputs.from }} path: build - - name: Get tag - id: get-tag - shell: bash - run: | - ref=${{ inputs.from }} - if [[ $ref =~ ^[0-9a-fA-F]{40}$ ]]; then - short_sha=$(echo $ref | cut -c1-7) - echo "tag=${short_sha}" >> $GITHUB_OUTPUT - echo "Ref $ref is a Git SHA, $short_sha is used as a tag." - else - echo "tag=${ref}" >> $GITHUB_OUTPUT - echo "Ref is not a Git SHA, $ref is used as a tag or branch name." - fi - - name: Checkout repository to get config file uses: actions/checkout@v4 with: @@ -130,7 +116,7 @@ jobs: releases_registry="${{ vars.DOCKER_REGISTRY_RELEASES }}" output_results="build_images_results.yaml" type="${{ inputs.type }}" - from="${{ steps.get-tag.outputs.tag }}" + from="${{ inputs.from }}" workflow_run_id=${{ github.run_id}} workflow_run_url="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" login_required="true" diff --git a/firestarter/workflows/build_images/build_images.py b/firestarter/workflows/build_images/build_images.py index df1511a6..9c42f783 100644 --- a/firestarter/workflows/build_images/build_images.py +++ b/firestarter/workflows/build_images/build_images.py @@ -16,6 +16,7 @@ import yaml import fnmatch import subprocess +import re logger = logging.getLogger(__name__) @@ -150,11 +151,16 @@ def dereference_from_version(self): if f'refs/tags/{self._from}' == tag_name: return self._from - short_sha = subprocess.run( + image_tag = subprocess.run( ['git', 'rev-parse', self._from], stdout=subprocess.PIPE ).stdout.decode('utf-8')[:7] - return short_sha + # If self._from is not a SHA, we assume it's a branch. + # We append its name to the image_tag so it's easier to identify + if not re.match('^[0-9a-f]{7,40}$', self._from): + image_tag = f'{self._from}_{image_tag}' + + return image_tag def resolve_secrets(self, secrets=None): sr = SecretResolver(secrets) From 6bf948a6f4abe3edba4847fef0df391c823dde79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20V=C3=A1zquez=20Gil?= Date: Mon, 2 Sep 2024 11:46:45 +0200 Subject: [PATCH 2/2] fix: Fix workflow call branch --- .github/workflows/build_images.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_images.yaml b/.github/workflows/build_images.yaml index 7c318150..3cea3efe 100644 --- a/.github/workflows/build_images.yaml +++ b/.github/workflows/build_images.yaml @@ -107,7 +107,7 @@ jobs: pyproject_path: .dagger workflow: build_images config_file: ../config/.github/build_images.yaml - ref: "v1" + ref: "fix/branch-name-in-image-tag" vars: | repo_name="${{ github.repository }}" flavors="${{ inputs.flavors }}" @@ -120,7 +120,7 @@ jobs: workflow_run_id=${{ github.run_id}} workflow_run_url="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" login_required="true" - ref="v1" + ref="fix/branch-name-in-image-tag" service_path="${{ fromJSON(vars.DOCKER_REGISTRIES_BASE_PATHS).services[inputs.type] }}" secrets: ${{ inputs.secrets }}