I'm maintaining an open source project compress4j and had a working pipeline which triggered on tag. However, I've broken it down to allow PRs from forks to be able run the pipeline as certain stages uses secrets to which the forks don't have access.
ci.yaml
name: CI
on:
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main
jobs:
ci:
name: Build
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ ubuntu-latest, macos-12 ]
java: [ 17, 21 ]
...
sonar.yaml
name: Sonar
on:
workflow_run:
workflows:
- CI
types:
- completed
jobs:
build:
name: Sonar
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ ubuntu-latest, macos-12 ]
java: [ 17, 21 ]
if: >
github.event.workflow_run.conclusion == 'success'
...
release.yaml
name: Release
on:
workflow_run:
workflows:
- Sonar
types:
- completed
env:
DEFAULT_JDK_VERSION: 17
jobs:
release:
name: Release
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.ref, 'refs/tags/v')}}
...
However, github.ref seems to be the branch even when a tag is pushed. How can I trigger the release workflow when previous worflows were sucessfull and a tag is pushed?
${{ github.ref_name }}to check the tag when pushed? Check this question to get some insights regarding the differences with${{ github.ref }}. You'll probably have to add anifcondition somewhere as you want to run the workflow for different types of event.