Skip to content

Commit b31ec28

Browse files
committed
Only run linux by default on PRs.
1 parent ca1b14d commit b31ec28

File tree

1 file changed

+85
-43
lines changed

1 file changed

+85
-43
lines changed

.github/workflows/ci.yml

Lines changed: 85 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
name: CI
22

33
# TODO: Remove this before merging.
4-
on: [push, pull_request]
4+
on:
5+
push:
6+
pull_request:
7+
types: [opened, synchronize, reopened, labeled]
58

69
# TODO: Uncomment before merging
710
# on:
811
# push:
912
# branches: [main]
1013
# pull_request:
1114
# branches: [main]
15+
# types: [opened, synchronize, reopened, labeled]
1216

1317
concurrency:
1418
group: ci-${{ github.ref }}
@@ -62,28 +66,99 @@ jobs:
6266
- name: Run format checks
6367
run: just fmt
6468

65-
check:
69+
# Linux runs on every PR and push to main.
70+
check-linux:
71+
runs-on: ubuntu-24.04
72+
name: check (linux)
73+
steps:
74+
- uses: actions/checkout@v4
75+
with:
76+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
77+
78+
- name: Restore cargo cache
79+
uses: actions/cache@v4
80+
with:
81+
path: |
82+
~/.cargo/registry/index
83+
~/.cargo/registry/cache
84+
~/.cargo/git/db
85+
~/.cargo/bin
86+
~/.cargo/.crates.toml
87+
~/.cargo/.crates2.json
88+
key: cargo-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
89+
restore-keys: cargo-${{ runner.os }}-
90+
91+
- name: Restore build output cache
92+
uses: actions/cache/restore@v4
93+
with:
94+
path: out
95+
key: build-Linux-${{ github.event.pull_request.number || 'main' }}-${{ github.run_id }}
96+
restore-keys: |
97+
build-Linux-${{ github.event.pull_request.number || 'main' }}-
98+
build-Linux-main-
99+
build-Linux-
100+
101+
- name: Setup build environment
102+
uses: ./.github/actions/setup-anki
103+
104+
- name: Install just
105+
uses: extractions/setup-just@v3
106+
107+
- name: Symlink node_modules
108+
run: |
109+
ln -sf out/node_modules .
110+
rm -f out/build.ninja
111+
112+
- name: Build, lint, and test
113+
env:
114+
ONLINE_TESTS: "1"
115+
run: |
116+
just build
117+
just lint
118+
just test
119+
120+
- name: Ensure libs importable
121+
env:
122+
SKIP_RUN: "1"
123+
run: ./run
124+
125+
- name: Check Rust dependencies
126+
run: |
127+
cargo install cargo-deny@0.19.0
128+
cargo deny check
129+
130+
- name: Save build output cache
131+
if: always()
132+
uses: actions/cache/save@v4
133+
with:
134+
path: out
135+
key: build-Linux-${{ github.event.pull_request.number || 'main' }}-${{ github.run_id }}
136+
137+
# macOS and Windows run on pushes to main and on PRs with the
138+
# corresponding label (check:macos or check:windows).
139+
check-other-platforms:
140+
if: >-
141+
github.event_name == 'push'
142+
|| contains(github.event.pull_request.labels.*.name, matrix.label)
66143
strategy:
67144
fail-fast: false
68145
matrix:
69146
include:
70-
- platform: linux
71-
runner: ubuntu-24.04
72147
- platform: macos
73148
runner: macos-latest
149+
label: check:macos
74150
- platform: windows
75151
runner: windows-latest
152+
label: check:windows
76153

77154
runs-on: ${{ matrix.runner }}
78155
name: check (${{ matrix.platform }})
79156

80157
steps:
81-
# Check out the PR head commit (not the merge ref) so that
82-
# check:minilints can verify the commit author is in CONTRIBUTORS.
83-
# The default merge ref author is GitHub, not the PR author.
84158
- uses: actions/checkout@v4
85159
with:
86-
ref: ${{ github.event.pull_request.head.sha || github.sha }}
160+
ref: ${{ github.sha }}
161+
87162
- name: Restore cargo cache
88163
uses: actions/cache@v4
89164
with:
@@ -97,16 +172,12 @@ jobs:
97172
key: cargo-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
98173
restore-keys: cargo-${{ runner.os }}-
99174

100-
# Fallback order for new PRs:
101-
# 1. build-{OS}-main (seed from latest main cache)
102-
# 2. build-{OS}- (any prior cache for this OS)
103175
- name: Restore build output cache
104176
uses: actions/cache/restore@v4
105177
with:
106178
path: out
107-
key: build-${{ runner.os }}-${{ github.event.pull_request.number || 'main' }}-${{ github.run_id }}
179+
key: build-${{ runner.os }}-main-${{ github.run_id }}
108180
restore-keys: |
109-
build-${{ runner.os }}-${{ github.event.pull_request.number || 'main' }}-
110181
build-${{ runner.os }}-main-
111182
build-${{ runner.os }}-
112183
@@ -116,27 +187,10 @@ jobs:
116187
- name: Install just
117188
uses: extractions/setup-just@v3
118189

119-
- name: Symlink node_modules (Linux)
120-
if: matrix.platform == 'linux'
121-
run: |
122-
ln -sf out/node_modules .
123-
rm -f out/build.ninja
124-
125190
- name: Symlink node_modules (macOS)
126191
if: matrix.platform == 'macos'
127192
run: ln -sf out/node_modules .
128193

129-
# Linting and type checking on Linux only (formatting is separate job).
130-
# Tests run on all platforms to catch platform-specific issues.
131-
- name: Build, lint, and test (Linux)
132-
if: matrix.platform == 'linux'
133-
env:
134-
ONLINE_TESTS: "1"
135-
run: |
136-
just build
137-
just lint
138-
just test
139-
140194
- name: Build and test (macOS)
141195
if: matrix.platform == 'macos'
142196
run: |
@@ -150,21 +204,9 @@ jobs:
150204
just build
151205
just test
152206
153-
- name: Ensure libs importable (Linux)
154-
if: matrix.platform == 'linux'
155-
env:
156-
SKIP_RUN: "1"
157-
run: ./run
158-
159-
- name: Check Rust dependencies (Linux)
160-
if: matrix.platform == 'linux'
161-
run: |
162-
cargo install cargo-deny@0.19.0
163-
cargo deny check
164-
165207
- name: Save build output cache
166208
if: always()
167209
uses: actions/cache/save@v4
168210
with:
169211
path: out
170-
key: build-${{ runner.os }}-${{ github.event.pull_request.number || 'main' }}-${{ github.run_id }}
212+
key: build-${{ runner.os }}-main-${{ github.run_id }}

0 commit comments

Comments
 (0)