|
| 1 | +name: 'ecosystem_ci_auto_run_commit' |
| 2 | +description: 'Trigger downstream ecosystem CI for commits and comment on failures' |
| 3 | + |
| 4 | +inputs: |
| 5 | + github-token: |
| 6 | + description: 'Token with access to the downstream ecosystem CI repository' |
| 7 | + required: true |
| 8 | + ecosystem-owner: |
| 9 | + description: 'Owner of the downstream ecosystem CI repository' |
| 10 | + required: false |
| 11 | + default: 'rspack-contrib' |
| 12 | + ecosystem-repo: |
| 13 | + description: 'Repository containing the downstream workflow' |
| 14 | + required: true |
| 15 | + workflow-file: |
| 16 | + description: 'Workflow file to execute in the downstream repository' |
| 17 | + required: true |
| 18 | + workflow-ref: |
| 19 | + description: 'Ref to use when triggering the downstream workflow' |
| 20 | + required: false |
| 21 | + default: 'main' |
| 22 | + client-payload: |
| 23 | + description: 'JSON payload passed to the downstream workflow dispatch' |
| 24 | + required: false |
| 25 | + default: '{}' |
| 26 | + result-heading: |
| 27 | + description: 'Heading to use in the formatted summary output' |
| 28 | + required: false |
| 29 | + default: 'Ran ecosystem CI' |
| 30 | + job-name-prefix: |
| 31 | + description: 'Job name prefix to match when summarizing downstream jobs' |
| 32 | + required: false |
| 33 | + default: 'execute-all ' |
| 34 | + commit-comment-on-failure: |
| 35 | + description: 'Set to true to create a commit comment when the downstream workflow fails' |
| 36 | + required: false |
| 37 | + default: 'true' |
| 38 | + commit-sha: |
| 39 | + description: 'Commit SHA to comment on when commit-comment-on-failure is enabled; defaults to the current SHA' |
| 40 | + required: false |
| 41 | + default: '' |
| 42 | + fail-on-failure: |
| 43 | + description: 'Fail this job when the downstream workflow reports a failure' |
| 44 | + required: false |
| 45 | + default: 'false' |
| 46 | + |
| 47 | +outputs: |
| 48 | + workflow-id: |
| 49 | + description: 'ID of the triggered downstream workflow run' |
| 50 | + value: ${{ steps.trigger.outputs.workflow_id }} |
| 51 | + workflow-url: |
| 52 | + description: 'URL of the triggered downstream workflow run' |
| 53 | + value: ${{ steps.trigger.outputs.workflow_url }} |
| 54 | + conclusion: |
| 55 | + description: 'Conclusion reported by the downstream workflow' |
| 56 | + value: ${{ steps.trigger.outputs.conclusion }} |
| 57 | + summary: |
| 58 | + description: 'Formatted markdown summary of downstream job results' |
| 59 | + value: ${{ steps.summarize.outputs.result }} |
| 60 | + |
| 61 | +runs: |
| 62 | + using: composite |
| 63 | + steps: |
| 64 | + - id: trigger |
| 65 | + name: Trigger downstream workflow |
| 66 | + uses: convictional/trigger-workflow-and-wait@f69fa9eedd3c62a599220f4d5745230e237904be # v1.6.5 |
| 67 | + continue-on-error: true |
| 68 | + with: |
| 69 | + owner: ${{ inputs.ecosystem-owner }} |
| 70 | + repo: ${{ inputs.ecosystem-repo }} |
| 71 | + workflow_file_name: ${{ inputs.workflow-file }} |
| 72 | + ref: ${{ inputs.workflow-ref }} |
| 73 | + github_token: ${{ inputs.github-token }} |
| 74 | + client_payload: ${{ inputs.client-payload }} |
| 75 | + |
| 76 | + - id: summarize |
| 77 | + if: ${{ always() }} |
| 78 | + name: Summarize downstream jobs |
| 79 | + uses: ../ecosystem-ci-result |
| 80 | + with: |
| 81 | + owner: ${{ inputs.ecosystem-owner }} |
| 82 | + repo: ${{ inputs.ecosystem-repo }} |
| 83 | + job-prefix: ${{ inputs.job-name-prefix }} |
| 84 | + heading: ${{ inputs.result-heading }} |
| 85 | + workflow-output: ${{ toJson(steps.trigger.outputs) }} |
| 86 | + |
| 87 | + - id: commit-comment |
| 88 | + if: ${{ always() && inputs.commit-comment-on-failure == 'true' && steps.trigger.outputs.conclusion == 'failure' }} |
| 89 | + name: Create commit comment on failure |
| 90 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 |
| 91 | + env: |
| 92 | + SUMMARY: ${{ steps.summarize.outputs.result }} |
| 93 | + COMMIT_SHA: ${{ inputs.commit-sha != '' && inputs.commit-sha || github.sha }} |
| 94 | + with: |
| 95 | + script: | |
| 96 | + const summary = process.env.SUMMARY?.trim(); |
| 97 | + if (!summary || summary.includes('cannot determine workflow run id')) { |
| 98 | + core.warning('Downstream workflow failed but no summary is available to comment'); |
| 99 | + return; |
| 100 | + } |
| 101 | +
|
| 102 | + const commitSha = process.env.COMMIT_SHA; |
| 103 | + if (!commitSha) { |
| 104 | + core.warning('No commit SHA provided for failure comment'); |
| 105 | + return; |
| 106 | + } |
| 107 | +
|
| 108 | + await github.rest.repos.createCommitComment({ |
| 109 | + owner: context.repo.owner, |
| 110 | + repo: context.repo.repo, |
| 111 | + commit_sha: commitSha, |
| 112 | + body: summary, |
| 113 | + }); |
| 114 | +
|
| 115 | + - if: ${{ always() && inputs.fail-on-failure == 'true' && steps.trigger.outputs.conclusion == 'failure' }} |
| 116 | + name: Fail when downstream workflow fails |
| 117 | + shell: bash |
| 118 | + run: | |
| 119 | + echo "::error::Downstream ecosystem CI workflow reported a failure" |
| 120 | + exit 1 |
0 commit comments