From 9236475664a1c4e396ddc26690e7a32e08c0f782 Mon Sep 17 00:00:00 2001 From: Guilherme Caulada Date: Tue, 10 Sep 2024 10:55:44 -0300 Subject: [PATCH] Fix issue detecting prod releases on build-and-publish workflow (#117) --- .../workflows/packer-build-and-publish.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/packer-build-and-publish.yml b/.github/workflows/packer-build-and-publish.yml index 42e80dc2b182..270faa66a2ef 100644 --- a/.github/workflows/packer-build-and-publish.yml +++ b/.github/workflows/packer-build-and-publish.yml @@ -8,7 +8,22 @@ permissions: id-token: write jobs: + get-branch: + runs-on: ubuntu-latest + outputs: + branch: ${{ steps.branch.outputs.value }} + steps: + - name: Checkout repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Determine the branch that contains the tag + id: branch + run: | + branch=$(git branch -r --contains ${{ github.sha }} | grep -v 'HEAD' | head -n 1 | sed 's/ *origin\///') + echo "value=$branch" >> $GITHUB_OUTPUT + build: + needs: get-branch runs-on: ubuntu-latest env: @@ -24,8 +39,8 @@ jobs: - images/ubuntu/templates/ubuntu-22.04.pkr.hcl - images/ubuntu/templates/ubuntu-22.04.arm64.pkr.hcl prodRelease: - # if we are tagging main, the tag starts with v and doesn't contain an hyphen, this is a prod release - - ${{ github.base_ref == 'main' && !contains(github.ref_name, '-') }} + # if we are tagging main and the tag doesn't contain an hyphen, this is a prod release + - ${{ needs.get-branch.outputs.branch == 'main' && !contains(github.ref_name, '-') }} exclude: # exclude releasing to prod if this is not a prod release - prodRelease: false