I am trying to trigger different reusable workflows according to target branch name of a created tag. For example if I create a tag from main branch, I want to trigger run-on-prod-tags.yml
workflow and if the branch name starts with feature, I want to trigger run-on-stage-tags.yml
. Should I make something like that in order to do that?
name: Tag Workflow
on:
push:
tags:
- '*'
jobs:
check-tag:
runs-on: docker-runner
steps:
- name: checkout Source Code
uses: actions/checkout@v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: Get Branch
run: |
echo ${{ github.ref }}
raw=$(git branch -r --contains ${{ github.ref }})
branch=${raw##*/}
echo "BRANCH=$branch" >> $GITHUB_ENV
- run: echo ${{env.BRANCH}}
build-and-deploy:
needs: [check-tag]
uses: ./.github/workflows/run-on-${{env.BRANCH}}-tags.yml
If I use something like that, when we change file name of reusable workflows', this code will fail. I should use something more robust. Do you have any idea to do that?
Thanks
P.S. Output Of The Script