Workflow Run Example #14
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: Workflow Run Example | |
on: | |
workflow_run: | |
workflows: [Release] | |
types: [completed] | |
permissions: | |
contents: read | |
jobs: | |
on-success: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Dump GitHub context | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: echo "$GITHUB_CONTEXT" | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get Tag | |
id: get-tag | |
run: | | |
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -vE "^v[0-9]+$" | head -n 2 | tail -n 1) | |
echo "previous_tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT" | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v42 | |
with: | |
base_sha: ${{ steps.get-tag.outputs.previous_tag }} | |
sha: ${{ github.event.workflow_run.head_branch }} | |
- name: Echo list of changed files on success | |
run: | | |
echo "Changed files on success:" | |
echo "${{ steps.changed-files.outputs.all_changed_files }}" | |
on-failure: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
steps: | |
- name: Dump GitHub context | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: echo "$GITHUB_CONTEXT" | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get Tag | |
id: get-tag | |
run: | | |
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -vE "^v[0-9]+$" | head -n 2 | tail -n 1) | |
echo "previous_tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT" | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v42 | |
with: | |
base_sha: ${{ steps.get-tag.outputs.previous_tag }} | |
sha: ${{ github.event.workflow_run.head_branch }} | |
- name: Echo list of changed files on failure | |
run: | | |
echo "Changed files on failure:" | |
echo "${{ steps.changed-files.outputs.all_changed_files }}" |