Skip to content

Commit a48216d

Browse files
authored
chore: don't kick off github actions jobs for unchanged top-level dirs (#348)
1 parent 76edf94 commit a48216d

File tree

3 files changed

+77
-41
lines changed

3 files changed

+77
-41
lines changed

.aspect/cli/rules_cc.star

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""This Starlark file sets up the aspect rules in this example
2-
repository to automatically generate several types of rules for C code."""
2+
repository to automatically generate several types of rules for C code.
3+
"""
34

45
aspect.register_rule_kind("cc_binary", {
56
"From": "@rules_cc//cc:defs.bzl",

.github/workflows/ci.yaml

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#
44
# Aspect Workflows is a more feature-rich, powerful, and cheaper approach.
55
# 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.
86
name: CI
97

108
# Controls when the action will run.
@@ -19,65 +17,102 @@ on:
1917
workflow_dispatch:
2018

2119
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
2821
matrix-prep-os:
2922
# Prepares the 'os' axis of the test matrix
3023
runs-on: ubuntu-latest
3124
steps:
32-
- uses: actions/checkout@v3
3325
- id: linux
3426
run: echo "os=ubuntu-latest" >> $GITHUB_OUTPUT
3527
- id: macos
3628
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)
3830
# 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')
4036
outputs:
4137
# Will look like ["ubuntu-latest", "macos-latest"]
4238
os: ${{ toJSON(steps.*.outputs.os) }}
4339

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
4779

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
4892
needs:
93+
- matrix-prep-folder
4994
- matrix-prep-os
5095

96+
# The type of runner that the job will run on
97+
runs-on: ${{ matrix.os }}
98+
5199
strategy:
52100
fail-fast: false
53101
matrix:
54102
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) }}
78104

79105
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
81116
- uses: bazel-contrib/[email protected]
82117
with:
83118
repository-cache: true
@@ -90,7 +125,7 @@ jobs:
90125
91126
- name: Test Type
92127
id: has_test_sh
93-
uses: andstor/file-existence-action@v1
128+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
94129
with:
95130
files: '${{ matrix.folder }}/test.sh'
96131

jest/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Example of using jest_test from rules_js
22

3-
TypeScript sources are transpiled by ts_project with SWC
3+
TypeScript sources are transpiled by ts_project with SWC.

0 commit comments

Comments
 (0)