|
3 | 3 | # |
4 | 4 | # Aspect Workflows is a more feature-rich, powerful, and cheaper approach. |
5 | 5 | # See the configuration in /.aspect/workflows for how that CI/CD system is configured. |
6 | | -# Note that the root module in this repo is tested on Aspect Workflows, so |
7 | | -# this file only executes tests for the nested sub-modules. |
8 | 6 | name: CI |
9 | 7 |
|
10 | 8 | # Controls when the action will run. |
|
19 | 17 | workflow_dispatch: |
20 | 18 |
|
21 | 19 | jobs: |
22 | | - # matrix-prep-* steps dynamically generate a bit of JSON depending on whether our action has |
23 | | - # access to repository secrets. When running on a pull_request from a fork, the author is |
24 | | - # untrusted so the secret will be absent. Insanely complex for how simple this requirement is... |
25 | | - # inspired from |
26 | | - # https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional |
27 | | - |
| 20 | + # matrix-prep-* jobs dynamically generate a bit of JSON which we read later to construct a matrix of test jobs |
28 | 21 | matrix-prep-os: |
29 | 22 | # Prepares the 'os' axis of the test matrix |
30 | 23 | runs-on: ubuntu-latest |
31 | 24 | steps: |
32 | | - - uses: actions/checkout@v3 |
33 | 25 | - id: linux |
34 | 26 | run: echo "os=ubuntu-latest" >> $GITHUB_OUTPUT |
35 | 27 | - id: macos |
36 | 28 | run: echo "os=macos-latest" >> $GITHUB_OUTPUT |
37 | | - # Only run on main branch (not PRs) to minimize macOS minutes (billed at 10X) |
| 29 | + # Only run on main branch (or branches that contain 'macos') to minimize macOS minutes (billed at 10X) |
38 | 30 | # https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes |
39 | | - if: ${{ github.ref == 'refs/heads/main' }} |
| 31 | + if: github.ref == 'refs/heads/main' || contains(github.head_ref, 'macos') |
| 32 | + - id: windows |
| 33 | + run: echo "os=windows-latest" >> $GITHUB_OUTPUT |
| 34 | + # Only run on branches that contain 'windows' to minimize Windows minutes (billed at 2X) and because Windows support is spotty. |
| 35 | + if: contains(github.head_ref, 'windows') |
40 | 36 | outputs: |
41 | 37 | # Will look like ["ubuntu-latest", "macos-latest"] |
42 | 38 | os: ${{ toJSON(steps.*.outputs.os) }} |
43 | 39 |
|
44 | | - test: |
45 | | - # The type of runner that the job will run on |
46 | | - runs-on: ${{ matrix.os }} |
| 40 | + # The goal of this matrix prep is to determine whether nested Bazel modules need to be tested. |
| 41 | + # When they do, we create a separate "matrix" job so they are tested in parallel with the root module. |
| 42 | + matrix-prep-folder: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + # Clone the last two commits, so we can see what files were changed. |
| 48 | + fetch-depth: 2 |
| 49 | + # Get a list of nested Bazel modules that were touched |
| 50 | + - uses: tj-actions/changed-files@v45 |
| 51 | + with: |
| 52 | + # NB: this list must match all files that live within a nested Bazel module. |
| 53 | + # Should match the /.bazelignore file as well. |
| 54 | + files: | |
| 55 | + angular/** |
| 56 | + angular-ngc/** |
| 57 | + jest/** |
| 58 | + bzlmod/** |
| 59 | + check-npm-determinism/** |
| 60 | + directory_path/** |
| 61 | + eager-fetch/** |
| 62 | + git_push/** |
| 63 | + go_workspaces/** |
| 64 | + jest/** |
| 65 | + nestjs/** |
| 66 | + oci_go_image/** |
| 67 | + oci_python_image/** |
| 68 | + pnpm-workspaces/** |
| 69 | + prisma/** |
| 70 | + bufbuild/** |
| 71 | + rules_nodejs_to_rules_js_migration/** |
| 72 | + ts_project_transpiler/** |
| 73 | + # Just print the top-level directory names |
| 74 | + dir_names: true |
| 75 | + dir_names_max_depth: 1 |
| 76 | + # Print results as json to files in .github/outputs folder. |
| 77 | + json: true |
| 78 | + write_output_files: true |
47 | 79 |
|
| 80 | + # Unconditionally add the root folder. There are three cases to consider: |
| 81 | + # 1. No nested Bazel modules were touched: zero results in the all_changed_and_modified_files.json. So the changed files are in the root module. |
| 82 | + # 2. Only files in the root module were touched: run CI anyway since Aspect Workflows runs unconditionally, and we want to be able to compare. |
| 83 | + # 3. Root module AND nested module touched in the PR: we need to add the root module since it won't match any entry above. |
| 84 | + - run: (echo -n "dirs="; jq --compact-output '. + ["."]' < .github/outputs/all_changed_and_modified_files.json) >> $GITHUB_OUTPUT |
| 85 | + id: changed-toplevel-dirs |
| 86 | + outputs: |
| 87 | + # Will look like [".", "some_folder"] |
| 88 | + folder: ${{ steps.changed-toplevel-dirs.outputs.dirs }} |
| 89 | + |
| 90 | + test: |
| 91 | + # Wait for all matrix-prep jobs so we can reference the result |
48 | 92 | needs: |
| 93 | + - matrix-prep-folder |
49 | 94 | - matrix-prep-os |
50 | 95 |
|
| 96 | + # The type of runner that the job will run on |
| 97 | + runs-on: ${{ matrix.os }} |
| 98 | + |
51 | 99 | strategy: |
52 | 100 | fail-fast: false |
53 | 101 | matrix: |
54 | 102 | os: ${{ fromJSON(needs.matrix-prep-os.outputs.os) }} |
55 | | - folder: |
56 | | - # FIXME(jbedard): re-enable CI for this folder, currently failing with |
57 | | - # Error: Cannot find module 'execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/external/aspect_rules_js/npm/private/lifecycle/node_modules/node-gyp/bin/node-gyp.js' |
58 | | - # - 'angular' |
59 | | - - 'angular-ngc' |
60 | | - - 'bzlmod' |
61 | | - - 'check-npm-determinism' |
62 | | - - 'directory_path' |
63 | | - # TODO: intentionally fails |
64 | | - # - 'eager-fetch' |
65 | | - - 'git_push' |
66 | | - - 'go_workspaces' |
67 | | - - 'jest' |
68 | | - - 'nestjs' |
69 | | - - 'oci_go_image' |
70 | | - - 'oci_python_image' |
71 | | - - 'pnpm-workspaces' |
72 | | - - 'prisma' |
73 | | - - 'bufbuild' |
74 | | - # FIXME(jbedard): re-enable CI for this folder, currently failing with |
75 | | - # Unable to load package for @nodejs_darwin_arm64//:bin/node: The repository '@nodejs_darwin_arm64' could not be resolved: Repository '@nodejs_darwin_arm64' is not defined |
76 | | - # - 'rules_nodejs_to_rules_js_migration' |
77 | | - - 'ts_project_transpiler' |
| 103 | + folder: ${{ fromJSON(needs.matrix-prep-folder.outputs.folder) }} |
78 | 104 |
|
79 | 105 | steps: |
80 | | - - uses: actions/checkout@v3 |
| 106 | + - uses: actions/checkout@v4 |
| 107 | + with: |
| 108 | + # Clone the last two commits, so we can see what files were changed. |
| 109 | + fetch-depth: 2 |
| 110 | + # Get a list of top-level directories that were touched |
| 111 | + - uses: tj-actions/changed-files@v45 |
| 112 | + id: changed-toplevel-dirs |
| 113 | + with: |
| 114 | + dir_names: true |
| 115 | + dir_names_max_depth: 1 |
81 | 116 | - uses: bazel-contrib/[email protected] |
82 | 117 | with: |
83 | 118 | repository-cache: true |
|
90 | 125 |
|
91 | 126 | - name: Test Type |
92 | 127 | id: has_test_sh |
93 | | - uses: andstor/file-existence-action@v1 |
| 128 | + uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0 |
94 | 129 | with: |
95 | 130 | files: '${{ matrix.folder }}/test.sh' |
96 | 131 |
|
|
0 commit comments