From 45f98e3fbd85dd1c1e47ced68468a1ccada75e8b Mon Sep 17 00:00:00 2001 From: Matt Heath <164215278+matt-oqc@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:03:56 +0100 Subject: [PATCH] Only run when tagged branch is `main` --- .github/workflows/publish.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3240265..0067b51 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,9 +7,34 @@ on: workflow_dispatch: jobs: + # @see https://stackoverflow.com/a/72959712/8179249 + check-current-branch: + runs-on: ubuntu-latest + outputs: + branch: ${{ steps.check_step.outputs.branch }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get current branch + id: check_step + # 1. Get the list of branches ref where this tag exists + # 2. Remove 'origin/' from that result + # 3. Put that string in output + # => We can now use function 'contains(list, item)'' + run: | + raw=$(git branch -r --contains ${{ github.ref }}) + branch="$(echo ${raw//origin\//} | tr -d '\n')" + echo "{name}=branch" >> $GITHUB_OUTPUT + echo "Branches where this tag exists : $branch." + build: name: Build runs-on: ubuntu-latest + needs: check-current-branch + # only run if tag is present on branch 'main' + if: contains(${{ needs.check.outputs.branch }}, 'main')` steps: - uses: actions/checkout@v4 - name: Install Poetry