Skip to content

Commit

Permalink
Run release action only on the main branch, Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
sscheib committed Mar 18, 2024
1 parent 9d0e619 commit 20038ba
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,46 @@ on: # yamllint disable-line rule:truthy
workflow_dispatch: {}

jobs:
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: 'Determine 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
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: 'Publish to Ansible Galaxy'
runs-on: 'ubuntu-latest'
needs: 'check-current-branch'
steps:
- name: 'checkout'
uses: 'actions/checkout@v4'
if: >-
github.ref == 'refs/heads/main'
if: "contains(${{ needs.check.outputs.branch }}, 'main')"

- name: 'galaxy'
uses: 'robertdebock/[email protected]'
if: >-
github.ref == 'refs/heads/main'
if: "contains(${{ needs.check.outputs.branch }}, 'main')"
with:
galaxy_api_key: '${{ secrets.galaxy_api_key }}'
git_branch: 'main'

- name: 'Create a new release on GitHub'
uses: 'softprops/action-gh-release@v2'
if: >-
github.ref == 'refs/heads/main'
if: "contains(${{ needs.check.outputs.branch }}, 'main')"
with:
draft: false
prerelease: false
Expand Down

0 comments on commit 20038ba

Please sign in to comment.