-
-
Notifications
You must be signed in to change notification settings - Fork 77
145 lines (133 loc) · 5.72 KB
/
ci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Configure plain GitHub Actions to run `bazel` commands on PRs to main as well as commits landed on main.
# This demonstrates one way to do Continuous Integration.
#
# Aspect Workflows is a more feature-rich, powerful, and cheaper approach.
# See the configuration in /.aspect/workflows for how that CI/CD system is configured.
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
# matrix-prep-* jobs dynamically generate a bit of JSON which we read later to construct a matrix of test jobs
matrix-prep-os:
# Prepares the 'os' axis of the test matrix
runs-on: ubuntu-latest
steps:
- id: linux
run: echo "os=ubuntu-latest" >> $GITHUB_OUTPUT
- id: macos
run: echo "os=macos-latest" >> $GITHUB_OUTPUT
# Only run on main branch (or branches that contain 'macos') to minimize macOS minutes (billed at 10X)
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
if: github.ref == 'refs/heads/main' || contains(github.head_ref, 'macos')
- id: windows
run: echo "os=windows-latest" >> $GITHUB_OUTPUT
# Only run on branches that contain 'windows' to minimize Windows minutes (billed at 2X) and because Windows support is spotty.
if: contains(github.head_ref, 'windows')
outputs:
# Will look like ["ubuntu-latest", "macos-latest"]
os: ${{ toJSON(steps.*.outputs.os) }}
# The goal of this matrix prep is to determine whether nested Bazel modules need to be tested.
# When they do, we create a separate "matrix" job so they are tested in parallel with the root module.
matrix-prep-folder:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Clone the last two commits, so we can see what files were changed.
fetch-depth: 2
# Get a list of nested Bazel modules that were touched
- uses: tj-actions/changed-files@v45
with:
# NB: this list must match all files that live within a nested Bazel module.
# Should match the /.bazelignore file as well.
files: |
angular/**
angular-ngc/**
jest/**
bzlmod/**
check-npm-determinism/**
directory_path/**
eager-fetch/**
git_push/**
go_workspaces/**
jest/**
nestjs/**
oci_go_image/**
oci_python_image/**
pnpm-workspaces/**
prisma/**
bufbuild/**
rules_nodejs_to_rules_js_migration/**
ts_project_transpiler/**
# Just print the top-level directory names
dir_names: true
dir_names_max_depth: 1
# Print results as json to files in .github/outputs folder.
json: true
write_output_files: true
# Unconditionally add the root folder. There are three cases to consider:
# 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.
# 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.
# 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.
- run: (echo -n "dirs="; jq --compact-output '. + ["."]' < .github/outputs/all_changed_and_modified_files.json) >> $GITHUB_OUTPUT
id: changed-toplevel-dirs
outputs:
# Will look like [".", "some_folder"]
folder: ${{ steps.changed-toplevel-dirs.outputs.dirs }}
test:
# Wait for all matrix-prep jobs so we can reference the result
needs:
- matrix-prep-folder
- matrix-prep-os
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(needs.matrix-prep-os.outputs.os) }}
folder: ${{ fromJSON(needs.matrix-prep-folder.outputs.folder) }}
steps:
- uses: actions/checkout@v4
with:
# Clone the last two commits, so we can see what files were changed.
fetch-depth: 2
# Get a list of top-level directories that were touched
- uses: tj-actions/changed-files@v45
id: changed-toplevel-dirs
with:
dir_names: true
dir_names_max_depth: 1
- uses: bazel-contrib/setup-bazel@0.8.5
with:
repository-cache: true
bazelrc: |
common --announce_rc --color=yes
common --enable_platform_specific_config
# TODO: bring up a docker or podman container on our macos runners, OR
# use our testcontainers cloud account to get a remote one.
test:macos --test_tag_filters=-requires-docker
- name: Test Type
id: has_test_sh
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
with:
files: '${{ matrix.folder }}/test.sh'
- name: test.sh
working-directory: ${{ matrix.folder }}
if: steps.has_test_sh.outputs.files_exists == 'true'
run: ./test.sh
shell: bash
- name: bazel test //...
working-directory: ${{ matrix.folder }}
if: steps.has_test_sh.outputs.files_exists != 'true'
run: |
bazel \
--bazelrc=$GITHUB_WORKSPACE/.aspect/bazelrc/ci.bazelrc \
--bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc \
test //...