|
| 1 | +name: example-job-trigger |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["pr-check"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + extract-context: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 13 | + outputs: |
| 14 | + workflow-run-id: ${{ steps.parse-event.outputs.workflow-run-id }} |
| 15 | + fork-owner: ${{ steps.parse-event.outputs.fork-owner }} |
| 16 | + fork-repo: ${{ steps.parse-event.outputs.fork-repo }} |
| 17 | + fork-branch: ${{ steps.parse-event.outputs.fork-branch }} |
| 18 | + commit-sha: ${{ steps.parse-event.outputs.commit-sha }} |
| 19 | + base-repo: ${{ steps.parse-event.outputs.base-repo }} |
| 20 | + changes-detected: ${{ steps.parse-event.outputs.changes-detected }} |
| 21 | + steps: |
| 22 | + - name: Parse event data |
| 23 | + id: parse-event |
| 24 | + env: |
| 25 | + WORKFLOW_RUN: ${{ toJson(github.event.workflow_run) }} |
| 26 | + GH_TOKEN: ${{ github.token }} |
| 27 | + run: | |
| 28 | + echo "Workflow run ID: ${{ fromJson(env.WORKFLOW_RUN).id }}" |
| 29 | + echo "workflow-run-id=${{ fromJson(env.WORKFLOW_RUN).id }}" >> $GITHUB_OUTPUT |
| 30 | + echo "Fork owner: ${{ fromJson(env.WORKFLOW_RUN).head_repository.owner.login }}" |
| 31 | + echo "fork-owner=${{ fromJson(env.WORKFLOW_RUN).head_repository.owner.login }}" >> $GITHUB_OUTPUT |
| 32 | + echo "Fork repo: ${{ fromJson(env.WORKFLOW_RUN).head_repository.name }}" |
| 33 | + echo "fork-repo=${{ fromJson(env.WORKFLOW_RUN).head_repository.name }}" >> $GITHUB_OUTPUT |
| 34 | + echo "Fork branch: ${{ fromJson(env.WORKFLOW_RUN).head_branch }}" |
| 35 | + echo "fork-branch=${{ fromJson(env.WORKFLOW_RUN).head_branch }}" >> $GITHUB_OUTPUT |
| 36 | + echo "Commit SHA: ${{ fromJson(env.WORKFLOW_RUN).head_sha }}" |
| 37 | + echo "commit-sha=${{ fromJson(env.WORKFLOW_RUN).head_sha }}" >> $GITHUB_OUTPUT |
| 38 | + echo "Base repo: ${{ fromJson(env.WORKFLOW_RUN).repository.full_name }}" |
| 39 | + echo "base-repo=${{ fromJson(env.WORKFLOW_RUN).repository.full_name }}" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + git clone "https://www.github.com/${{ fromJson(env.WORKFLOW_RUN).repository.full_name }}" "${{ fromJson(env.WORKFLOW_RUN).repository.name }}" --depth 1 |
| 42 | + cd "${{ fromJson(env.WORKFLOW_RUN).repository.name }}" |
| 43 | + git remote add upstream "https://www.github.com/${{ fromJson(env.WORKFLOW_RUN).head_repository.full_name }}" |
| 44 | + git fetch upstream |
| 45 | + git diff --name-only upstream/${{ fromJson(env.WORKFLOW_RUN).head_branch }} HEAD > changes.txt |
| 46 | + if grep -qe 'packages/backend/src/assets/ai.json' changes.txt; then |
| 47 | + echo "Changes detected in ai.json" |
| 48 | + echo "changes-detected=true" >> $GITHUB_OUTPUT |
| 49 | + else |
| 50 | + echo "No changes detected in ai.json" |
| 51 | + echo "changes-detected=false" >> $GITHUB_OUTPUT |
| 52 | + gh run cancel ${{ github.run_id}} |
| 53 | + fi |
| 54 | +
|
| 55 | + trigger-template: |
| 56 | + needs: extract-context |
| 57 | + uses: ScrewTSW/podman-desktop-extension-ai-lab/.github/workflows/example-job-template.yaml@main |
| 58 | + if: ${{ needs.extract-context.outputs.changes-detected == 'true' }} |
| 59 | + strategy: |
| 60 | + fail-fast: false |
| 61 | + with: |
| 62 | + trigger-workflow-run-id: ${{ needs.extract-context.outputs.workflow-run-id }} |
| 63 | + trigger-workflow-fork: ${{ needs.extract-context.outputs.fork-owner }} |
| 64 | + trigger-workflow-repo-name: ${{ needs.extract-context.outputs.fork-repo }} |
| 65 | + trigger-workflow-branch: ${{ needs.extract-context.outputs.fork-branch }} |
| 66 | + trigger-workflow-commit-sha: ${{ needs.extract-context.outputs.commit-sha }} |
| 67 | + trigger-workflow-base-repo: ${{ needs.extract-context.outputs.base-repo }} |
0 commit comments