|
30 | 30 | push: |
31 | 31 | branches: |
32 | 32 | - master |
| 33 | + # Add any additional branches you want to include |
| 34 | + # - dev/test_ci_branch |
| 35 | + |
33 | 36 | # Pull requests from forks will not have access to the required GitHub API |
34 | 37 | # secrets below, even if they are using an appropriate deployment environment |
35 | 38 | # and the workflow runs have been approved according to this environment's |
36 | 39 | # rules. We don't know whether this is a bug on GitHub's end or deliberate. |
| 40 | + # |
37 | 41 | # Either way, for now we disable this workflow to run on PRs until we have |
38 | 42 | # an API proxy that securely performs these GitHub API calls (adding runners |
39 | 43 | # and starting Treadmill jobs with those runner registration tokens), which |
40 | 44 | # allows this workflow to run without access to repository secrets. |
41 | | - #pull_request: |
| 45 | + # |
| 46 | + # However, because GitHub's merge queues don't allow to differentiate required |
| 47 | + # checks for *entering* the merge queue from those that are required to *pass* |
| 48 | + # it, we also can't disable this trigger entirely. Instead, we use a selector |
| 49 | + # to avoid running any actual checks on this trigger, while still technically |
| 50 | + # succeeding for PRs. |
| 51 | + pull_request: |
| 52 | + |
42 | 53 | merge_group: # Run CI for the GitHub merge queue |
43 | 54 |
|
| 55 | + # Manually dispatch for a specific branch (will require approval |
| 56 | + # through the treadmill-ci-merged environment: |
| 57 | + workflow_dispatch: |
| 58 | + inputs: |
| 59 | + tock-kernel-ref: |
| 60 | + description: 'Ref (revision/branch/tag) of the upstream Tock repo to test' |
| 61 | + required: true |
| 62 | + default: 'master' |
| 63 | + libtock-c-ref: |
| 64 | + description: 'Ref (revision/branch/tag) of the upstream libtock-c repo to test' |
| 65 | + required: true |
| 66 | + default: 'master' |
| 67 | + tests-json: |
| 68 | + description: 'tests-json value passed to HWCI workflow (if empty, output from hwci-determine-tests step is used)' |
| 69 | + required: false |
| 70 | + |
44 | 71 | permissions: |
45 | 72 | contents: read |
46 | 73 |
|
47 | 74 | jobs: |
48 | | - treadmill-ci: |
| 75 | + hwci-determine-tests: |
| 76 | + runs-on: ubuntu-latest |
| 77 | + |
| 78 | + # Don't run on a pull request, as explained above. |
| 79 | + if: github.event_name != 'pull_request' |
| 80 | + |
| 81 | + outputs: |
| 82 | + hwci-tests-json: ${{ steps.determine-tests.outputs.hwci-tests-json }} |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Checkout the tock/tock repository |
| 86 | + uses: actions/checkout@v4 |
| 87 | + with: |
| 88 | + # Checkout the repository at the commit that triggered the workflow |
| 89 | + repository: tock/tock |
| 90 | + ref: ${{ github.sha }} |
| 91 | + path: tock-tock |
| 92 | + |
| 93 | + - name: Checkout the tock-hardware-ci repository |
| 94 | + uses: actions/checkout@v4 |
| 95 | + with: |
| 96 | + repository: tock/tock-hardware-ci |
| 97 | + # Change this in accordance with the two other `tock-hardware-ci` refs |
| 98 | + # referenced below in the reusable workflow's parameters: |
| 99 | + ref: 'main' |
| 100 | + path: tock-hardware-ci |
| 101 | + |
| 102 | + - name: Analyze changes to determine relevant tests |
| 103 | + id: determine-tests |
| 104 | + run: | |
| 105 | + # Ensure Python dependencies are installed |
| 106 | + python3 -m pip install --user --upgrade pip |
| 107 | +
|
| 108 | + # Run the select_tests.py script |
| 109 | + python3 tock-hardware-ci/hwci/select_tests.py \ |
| 110 | + --repo-path tock-tock \ |
| 111 | + --hwci-path tock-hardware-ci/hwci \ |
| 112 | + --output selected_tests.json |
| 113 | +
|
| 114 | + echo "Selected HWCI tests:" |
| 115 | + cat selected_tests.json |
| 116 | +
|
| 117 | + # Output the tests JSON |
| 118 | + hwci_tests_json=$(cat selected_tests.json | jq -c '.') |
| 119 | + echo "hwci-tests-json=${hwci_tests_json}" >> "$GITHUB_OUTPUT" |
| 120 | +
|
| 121 | + hwci-treadmill-dispatch: |
| 122 | + needs: [hwci-determine-tests] |
| 123 | + |
| 124 | + # This checks whether there is at least one test to run, see |
| 125 | + # https://github.com/orgs/community/discussions/27125#discussioncomment-3254720 |
| 126 | + # |
| 127 | + # Don't run on a pull request, as explained above. |
| 128 | + if: github.event_name != 'pull_request' && (fromJSON(needs.hwci-determine-tests.outputs.hwci-tests-json)[0] != null || github.event_name == 'workflow_dispatch') |
| 129 | + |
| 130 | + # The main tock-hardware-ci workflow is imported from another repository. It |
| 131 | + # can be reused across multiple Tock repositories such as the kernel, |
| 132 | + # libtock-c, and libtock-rs. |
49 | 133 | uses: tock/tock-hardware-ci/.github/workflows/treadmill-ci.yml@main |
| 134 | + |
50 | 135 | with: |
51 | 136 | # Only run on a specific repository, as others will not have the right |
52 | 137 | # environments set up and secrets configured. Forks may want to change |
53 | 138 | # this parameter. |
54 | 139 | repository-filter: 'tock/tock' |
55 | 140 |
|
56 | 141 | # Provide access to the required Treadmill secrets by running in the |
57 | | - # appropriate environment (depending on the on: triggers above) |
58 | | - job-environment: ${{ github.event_name == 'pull_request' && 'treadmill-ci' || 'treadmill-ci-merged' }} |
| 142 | + # appropriate environment (depending on the `on:` triggers above) |
| 143 | + job-environment: ${{ (github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch') && 'treadmill-ci' || 'treadmill-ci-merged' }} |
59 | 144 |
|
60 | | - # Use the latest upstream Tock hardware CI tests and userspace components: |
61 | | - libtock-c-ref: 'master' |
| 145 | + # Reference for tock-hardware-ci repo, change if you want a specific test |
| 146 | + # suite. In this case, you should also update the branch reference in the |
| 147 | + # "uses" line above. |
62 | 148 | tock-hardware-ci-ref: 'main' |
63 | 149 |
|
64 | | - # Test the tock kernel revision that triggered this workflow |
65 | | - tock-kernel-ref: ${{ github.sha }} |
| 150 | + # Test the tock kernel revision that triggered this workflow: |
| 151 | + tock-kernel-ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tock-kernel-ref || github.sha }} |
| 152 | + |
| 153 | + # Use the latest upstream libtock-c library: |
| 154 | + libtock-c-ref: ${{ github.event_name == 'workflow_dispatch' && inputs.libtock-c-ref || 'master' }} |
| 155 | + |
| 156 | + # Pass the selected tests: |
| 157 | + tests-json: ${{ (github.event_name == 'workflow_dispatch' && inputs.tests-json != '') && inputs.tests-json || needs.hwci-determine-tests.outputs.hwci-tests-json }} |
66 | 158 |
|
67 | 159 | secrets: inherit |
| 160 | + |
| 161 | + # We cannot depend on *all* test-execute jobs of hwci-treadmill-dispatch as |
| 162 | + # required checks for pull requests and merge queues. Thus, we run another |
| 163 | + # single dummy step here that waits for all the hwci-treadmill-dispatch jobs |
| 164 | + # to complete and report success. |
| 165 | + # |
| 166 | + # We also use this to report a "dummy" success value for the "pull_request" |
| 167 | + # trigger, as explained in the comment of the "on:" parameters above. |
| 168 | + hwci-report-success: |
| 169 | + needs: [hwci-determine-tests, hwci-treadmill-dispatch] |
| 170 | + |
| 171 | + if: always() |
| 172 | + |
| 173 | + runs-on: ubuntu-latest |
| 174 | + |
| 175 | + steps: |
| 176 | + - name: Fail if any of the 'hwci-treadmill-dispatch' jobs failed |
| 177 | + if: github.event_name != 'pull_request' && contains(needs.*.result, 'failure') |
| 178 | + run: exit 1 |
0 commit comments