-
Notifications
You must be signed in to change notification settings - Fork 18
Add cross-repo CI: trigger downstream tests on PR success #1525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2f890f6
Add cross-repo CI design spec
dannyroberts 9214c79
Add cross-repo CI implementation plan
dannyroberts 9e0e93b
Add workflow to trigger downstream repo tests on PR success
dannyroberts f8b8274
Use env vars instead of direct interpolation in github-script
dannyroberts 61aa3cc
Temporarily target dmr/cross-repo-ci branch for Stage 2 testing
dannyroberts 4ae418e
Move trigger-downstream into build.yml as a job instead of separate w…
dannyroberts e800129
Add target_url to pending status linking to downstream Actions page
dannyroberts a1846e7
Replace superpowers planning docs with permanent cross-repo CI docume…
dannyroberts a375eca
Target master branch for downstream workflow dispatch
dannyroberts e075b79
Temporarily add dmr/cross-repo-ci as a PR target branch for build wor…
dannyroberts 824619f
Send merge SHA for checkout and head SHA for status reporting
dannyroberts 3ea040d
Temporarily target dmr/cross-repo-ci-merge-sha for testing
dannyroberts 1a70d3d
Document merge commit vs head commit SHA distinction in cross-repo CI
dannyroberts fc43cdf
Target master branch for downstream workflow dispatch
dannyroberts 9e7494b
Remove temporary dmr/cross-repo-ci branch from PR trigger filter
dannyroberts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| name: Trigger Downstream Tests | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["CommCare Core Build"] | ||
| types: [completed] | ||
|
|
||
| jobs: | ||
| trigger-downstream: | ||
| # Only run for successful PR builds, not pushes | ||
| if: > | ||
| github.event.workflow_run.conclusion == 'success' && | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.event.workflow_run.pull_requests[0] | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - repo: dimagi/commcare-android | ||
| check_name: "cross-repo / commcare-android" | ||
| workflow_file: commcare-android-pr-workflow.yml | ||
| - repo: dimagi/formplayer | ||
| check_name: "cross-repo / formplayer" | ||
| workflow_file: build.yml | ||
| steps: | ||
| - name: Generate GitHub App token | ||
| id: app-token | ||
| uses: actions/create-github-app-token@v1 | ||
| with: | ||
| app-id: ${{ secrets.CROSS_REPO_CI_APP_ID }} | ||
| private-key: ${{ secrets.CROSS_REPO_CI_PRIVATE_KEY }} | ||
| owner: dimagi | ||
| repositories: commcare-core,commcare-android,formplayer | ||
|
|
||
| - name: Get PR info | ||
| id: pr | ||
| run: | | ||
| echo "sha=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT" | ||
| echo "pr_number=${{ github.event.workflow_run.pull_requests[0].number }}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Set pending status | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| COMMCARE_CORE_SHA: ${{ steps.pr.outputs.sha }} | ||
| CHECK_NAME: ${{ matrix.check_name }} | ||
| with: | ||
| github-token: ${{ steps.app-token.outputs.token }} | ||
| script: | | ||
| await github.rest.repos.createCommitStatus({ | ||
| owner: 'dimagi', | ||
| repo: 'commcare-core', | ||
| sha: process.env.COMMCARE_CORE_SHA, | ||
| state: 'pending', | ||
| context: process.env.CHECK_NAME, | ||
| description: 'Waiting for downstream tests...' | ||
| }); | ||
|
|
||
| - name: Trigger downstream workflow | ||
| id: dispatch | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| COMMCARE_CORE_SHA: ${{ steps.pr.outputs.sha }} | ||
| COMMCARE_CORE_PR: ${{ steps.pr.outputs.pr_number }} | ||
| CHECK_NAME: ${{ matrix.check_name }} | ||
| REPO: ${{ matrix.repo }} | ||
| WORKFLOW_FILE: ${{ matrix.workflow_file }} | ||
| with: | ||
| github-token: ${{ steps.app-token.outputs.token }} | ||
| script: | | ||
| try { | ||
| const [owner, repo] = process.env.REPO.split('/'); | ||
| await github.rest.actions.createWorkflowDispatch({ | ||
| owner, | ||
| repo, | ||
| workflow_id: process.env.WORKFLOW_FILE, | ||
| ref: 'dmr/cross-repo-ci', | ||
|
dannyroberts marked this conversation as resolved.
Outdated
|
||
| inputs: { | ||
| commcare_core_sha: process.env.COMMCARE_CORE_SHA, | ||
| commcare_core_pr: process.env.COMMCARE_CORE_PR, | ||
| commcare_core_check_name: process.env.CHECK_NAME | ||
| } | ||
| }); | ||
| } catch (error) { | ||
| // If dispatch fails, set error status so it doesn't stay pending forever | ||
| await github.rest.repos.createCommitStatus({ | ||
| owner: 'dimagi', | ||
| repo: 'commcare-core', | ||
| sha: process.env.COMMCARE_CORE_SHA, | ||
| state: 'error', | ||
| context: process.env.CHECK_NAME, | ||
| description: `Failed to trigger: ${error.message}`.substring(0, 140) | ||
| }); | ||
| throw error; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.