@@ -18,81 +18,117 @@ concurrency:
18
18
cancel-in-progress : ${{ github.ref_name != 'main' }}
19
19
20
20
jobs :
21
- # matrix-prep-* steps dynamically generate a bit of JSON depending on whether our action has
22
- # access to repository secrets. When running on a pull_request from a fork, the author is
23
- # untrusted so the secret will be absent. Insanely complex for how simple this requirement is...
24
- # inspired from
25
- # https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional
26
-
27
- matrix-prep-bazelversion :
28
- # Prepares the 'bazelversion' axis of the test matrix
21
+ # Prepares dynamic test matrix values
22
+ matrix-prep :
29
23
runs-on : ubuntu-latest
30
24
steps :
31
25
- uses : actions/checkout@v4
32
- - id : bazel_7
33
- run : echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT
26
+ - id : bazel-version
27
+ name : Prepare 'bazel-version' matrix axis
28
+ run : |
29
+ v=$(head -n 1 .bazelversion)
30
+ m=${v::1}
31
+ a=(
32
+ "major:$m, version:\"$v\""
33
+ "major:6, version:\"6.5.0\""
34
+ )
35
+ printf -v j '{%s},' "${a[@]}"
36
+ echo "res=[${j%,}]" | tee -a $GITHUB_OUTPUT
37
+ - id : os
38
+ name : Prepare 'os' matrix axis
39
+ # Only run MacOS and Windows on main branch (not PRs) to minimize minutes (billed at 10X and 2X respectively)
40
+ # https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
41
+ run : |
42
+ a=( ubuntu )
43
+ if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"macos"* ]]; then
44
+ a+=( macos )
45
+ fi
46
+ if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"windows"* ]]; then
47
+ a+=( windows )
48
+ fi
49
+ printf -v j '"%s",' "${a[@]}"
50
+ echo "res=[${j%,}]" | tee -a $GITHUB_OUTPUT
34
51
outputs :
35
- # Will look like ["< version from .bazelversion>", ...]
36
- bazelversions : ${{ toJSON( steps.* .outputs.bazelversion) }}
52
+ bazel- version: ${{ steps.bazel-version.outputs.res }}
53
+ os : ${{ steps.os .outputs.res }}
37
54
38
55
test :
39
- # The type of runner that the job will run on
40
- runs-on : ubuntu-latest
41
-
56
+ runs-on : ${{ matrix.os }}-latest
42
57
needs :
43
- - matrix-prep-bazelversion
44
-
45
- # Run bazel test in each workspace
58
+ - matrix-prep
46
59
strategy :
47
60
fail-fast : false
48
61
matrix :
49
- bazelversion : ${{ fromJSON(needs.matrix-prep-bazelversion .outputs.bazelversions ) }}
62
+ bazel-version : ${{ fromJSON(needs.matrix-prep.outputs.bazel-version ) }}
50
63
bzlmod : [1, 0]
64
+ os : ${{ fromJSON(needs.matrix-prep.outputs.os) }}
51
65
folder :
52
66
- " ."
53
67
- " e2e/workspace"
68
+ exclude :
69
+ # Don't test MacOS and Windows against secondary bazel version to minimize minutes (billed at 10X and 2X respectively)
70
+ # https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
71
+ - os : macos
72
+ bazel-version :
73
+ major : 6
74
+ - os : windows
75
+ bazel-version :
76
+ major : 6
77
+ # TODO: fix toolchain issue on Windows in e2e/workspace
78
+ # //module_test:module_test (54772d7): No matching toolchains found for types @@aspect_rules_cypress//cypress:toolchain_type.
79
+ - os : windows
80
+ folder : e2e/workspace
81
+ # Don't test with bzlmod on Bazel 6 since we're using use_repo_rule which was added in Bazel 7
82
+ - bzlmod : 1
83
+ bazel-version :
84
+ major : 6
54
85
55
- # Steps represent a sequence of tasks that will be executed as part of the job
56
86
steps :
57
- # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
58
87
- uses : actions/checkout@v4
59
88
60
- # Cache build and external artifacts so that the next ci build is incremental.
61
- # Because github action caches cannot be updated after a build, we need to
62
- # store the contents of each build in a unique cache key, then fall back to loading
63
- # it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
64
- # the prefix to load the most recent cache for the branch on a cache miss. You
65
- # should customize the contents of hashFiles to capture any bazel input sources,
66
- # although this doesn't need to be perfect. If none of the input sources change
67
- # then a cache hit will load an existing cache and bazel won't have to do any work.
68
- # In the case of a cache miss, you want the fallback cache to contain most of the
69
- # previously built artifacts to minimize build time. The more precise you are with
70
- # hashFiles sources the less work bazel will have to do.
71
89
- name : Mount bazel caches
72
90
uses : actions/cache@v3
73
91
with :
74
92
path : |
75
- "~/.cache/bazel"
76
- "~/.cache/bazel-repo"
77
- key : bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
78
- restore-keys : bazel-cache-
93
+ ~/.cache/bazel-disk-cache
94
+ ~/.cache/bazel-repository-cache
95
+ ~/.cache/xdg-cache
96
+ key : bazel-cache-${{ matrix.bazel-version.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-${{ hashFiles('.bazelrc', '.bazelversion', '.bazeliskrc', '**/BUILD', '**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel', 'WORKSPACE.bzlmod', 'MODULE.bazel') }}
97
+ restore-keys : bazel-cache-${{ matrix.bazel-version.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-
79
98
80
99
- name : Configure Bazel version
81
100
working-directory : ${{ matrix.folder }}
82
- # Overwrite the .bazelversion instead of using USE_BAZEL_VERSION so that Bazelisk
83
- # still bootstraps Aspect CLI from configuration in .bazeliskrc. Aspect CLI will
84
- # then use .bazelversion to determine which Bazel version to use
85
- run : echo "${{ matrix.bazelversion }}" > .bazelversion
101
+ shell : bash
102
+ run : |
103
+ # Overwrite the .bazelversion instead of using USE_BAZEL_VERSION so that Bazelisk
104
+ # still bootstraps Aspect CLI from configuration in .bazeliskrc. Aspect CLI will
105
+ # then use .bazelversion to determine which Bazel version to use.
106
+ echo "${{ matrix.bazel-version.version }}" > .bazelversion
107
+ # Delete all the version specific bazelrc files that are used for local development
108
+ # since the version we're testing against is dynamic. These are just symlinks and the
109
+ # root .bazelrc brings these in with try-imports. In this CI workflows, we explicitly
110
+ # bring in the version specific bazelrc file with --bazelrc when we invoke bazel.
111
+ rm ${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/bazel*.bazelrc
112
+
113
+ # TODO: remove this block once we have Aspect CLI Windows releases
114
+ - name : Don't use Aspect CLI on Windows
115
+ if : matrix.os == 'windows'
116
+ working-directory : ${{ matrix.folder }}
117
+ shell : bash
118
+ run : rm -f .bazeliskrc
86
119
87
120
- name : bazel test //...
88
- env :
89
- # Bazelisk will download bazel to here, ensure it is cached between runs.
90
- XDG_CACHE_HOME : ~/.cache/bazel-repo
91
121
working-directory : ${{ matrix.folder }}
122
+ shell : bash
92
123
run : |
93
124
bazel \
94
- --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc \
95
- --bazelrc=.bazelrc \
125
+ --bazelrc=${GITHUB_WORKSPACE//\\/\/}/.github/workflows/bazel${{ matrix.bazel-version.major }}.bazelrc \
126
+ --bazelrc=${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/ci.bazelrc \
127
+ --bazelrc=${GITHUB_WORKSPACE//\\/\/}/.github/workflows/ci.bazelrc \
96
128
test \
129
+ --test_tag_filters=-skip-on-bazel${{ matrix.bazel-version.major }} \
130
+ --build_tag_filters=-skip-on-bazel${{ matrix.bazel-version.major }} \
97
131
--enable_bzlmod=${{ matrix.bzlmod }} \
98
132
//...
133
+ env :
134
+ XDG_CACHE_HOME : ~/.cache/xdg-cache # bazelisk will download bazel to here
0 commit comments