test calling the workflow #21
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Example | |
on: | |
push: | |
pull_request: | |
workflow_call: | |
jobs: | |
Example: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
# Needed to get the called workflow reference | |
id-token: write | |
steps: | |
- name: Get called workflow reference | |
run: | | |
JWT=$(curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL") | |
PAYLOAD=$(echo "$JWT" | cut -d '.' -f 2 | base64 -d 2>/dev/null || true) | |
WORKFLOW_FULL_REF=$( | |
echo "$PAYLOAD" \ | |
| grep -o '"job_workflow_ref":"[^"]*"' \ | |
| cut -d':' -f2 \ | |
| cut -d'@' -f2 \ | |
| tr -d '"' | |
) | |
echo "WORKFLOW_FULL_REF=$WORKFLOW_FULL_REF" | |
case $WORKFLOW_FULL_REF in | |
refs/heads/*) | |
WORKFLOW_REF=${WORKFLOW_FULL_REF#refs/heads/} | |
;; | |
refs/tags/*) | |
WORKFLOW_REF=${WORKFLOW_FULL_REF#refs/tags/} | |
;; | |
refs/pull/*/merge) | |
# exception: we got triggered by a pull request, the ref is the base branch | |
WORKFLOW_REF=$GITHUB_HEAD_REF | |
;; | |
esac | |
echo "::notice ::WORKFLOW_FULL_REF=$WORKFLOW_FULL_REF" | |
echo "::notice ::WORKFLOW_REF=$WORKFLOW_REF" | |
echo "WORKFLOW_REF=$WORKFLOW_REF" | tee -a $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
with: | |
repository: duboisf/get-reusable-workflow-reference | |
ref: ${{ env.WORKFLOW_REF }} | |
- name: Run script from called workflow | |
run: | | |
./scripts/example.sh |