Skip to content

Commit

Permalink
Only run when tagged branch is main
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-oqc authored Sep 12, 2024
1 parent d405735 commit 45f98e3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 45f98e3

Please sign in to comment.