Repository navigation
123 lines (108 loc) · 5.18 KB
/
Copy pathexamples.yml
File metadata and controls
123 lines (108 loc) · 5.18 KB
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
name: Examples
# Checks every example: the Rust crates among them (members of the
# workspace under `examples/`: their lints and tests, such as the Rust
# gallery's black-box tests, which run every demo through the engine,
# headless) and every app entry (a top-level `.tsx` of an example that calls
# `mount`, and the `nsh.json` of a Rust app, one declaring a `"root"`),
# built with `nsh build`. All are found, so a new example is checked
# without a change here. The other workflows only run for
# `crates/**`, so a change to the examples alone was never built.
on:
# Pull requests test every change before it merges; main runs every three
# hours when it moved, instead of on every push, which only tested again what its pull request
# had, and saves the dependencies' caches pull requests restore.
schedule:
- cron: "0 */3 * * *"
pull_request:
# `closed` runs nothing, but it takes the pull request's concurrency group
# and so cancels its runs still queued or running once it merges or closes.
types: [opened, synchronize, reopened, ready_for_review, closed]
paths:
- "examples/**"
- ".github/workflows/examples.yml"
- ".github/actions/cargo/**"
merge_group:
types: [checks_requested]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: examples-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
# CI builds each crate once: no incremental state and no debug info
# (faster builds, smaller caches; panics still name their file and line).
CARGO_INCREMENTAL: "0"
CARGO_PROFILE_DEV_DEBUG: "0"
# The toolchain file's iOS and Android targets are only the release's.
RUSTUP_TOOLCHAIN: stable
jobs:
# Scheduled runs: only when main moved since the last one.
changed:
if: github.event_name == 'schedule'
permissions:
actions: read
uses: ./.github/workflows/changed.yml
check:
needs: changed
# Nothing for drafts or a pull request being closed, nor for a scheduled
# run when main has not changed since the last one.
if: ${{ !cancelled() && needs.changed.outputs.run != 'false' && (github.event_name != 'pull_request' || (github.event.action != 'closed' && !github.event.pull_request.draft)) }}
# Debounce (AGENTS.md "CI"): waits without a runner, so a newer
# push cancels this run before it takes one.
environment:
name: ci-debounce
deployment: false
# Pull requests from forks and the scheduled runs (which save the
# dependencies' caches forks restore) run on GitHub's runners, everything
# else on the self-hosted ones (docs/dev/tooling.md "Runners").
runs-on: ${{ (github.event_name == 'schedule' || (github.event.pull_request && github.event.pull_request.head.repo.full_name != github.repository)) && 'ubuntu-24.04' || fromJSON('["public", "Linux", "X64"]') }}
steps:
- uses: actions/checkout@v6
# QuickJS is C (bindgen needs libclang). The Rust gallery also
# links GTK through its native desktop entry's dependencies.
- name: Install clang, GTK 4 and GStreamer
run: sudo apt-get update && sudo apt-get install -y clang libclang-dev libgtk-4-dev libwebkitgtk-6.0-dev jq
- name: Setup Rust
if: runner.environment == 'github-hosted'
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
# The self-hosted runners are shared: install the toolchain without
# making it the machine's default (RUSTUP_TOOLCHAIN picks it).
- name: Setup Rust (self-hosted)
if: runner.environment == 'self-hosted'
run: |
bin="${CARGO_HOME:-$HOME/.cargo}/bin"
export PATH="$bin:$PATH"
command -v rustup || curl -fsSL https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain none
rustup toolchain install stable --profile minimal -c clippy
echo "$bin" >> "$GITHUB_PATH"
# huacnlee/cargo, and the dependencies' builds: on GitHub's runners
# main's runs save them and pull requests restore them; the
# self-hosted runners keep their own and skip the caches.
- name: Cargo
uses: ./.github/actions/cargo
with:
cache: examples
- name: Find the Rust examples
id: crates
run: >
echo "packages=$(cargo metadata --no-deps --format-version 1
| jq -r '[.packages[] | select(.manifest_path | contains("/examples/")) | "-p " + .name] | join(" ")')"
>> "$GITHUB_OUTPUT"
- name: Clippy
if: steps.crates.outputs.packages != ''
run: cargo clippy --all-targets ${{ steps.crates.outputs.packages }} -- -D warnings
- name: Test
if: steps.crates.outputs.packages != ''
run: cargo test ${{ steps.crates.outputs.packages }}
# An app with a Rust crate (`nsh.json` "rust") builds its own command
# line with the crate first; a Rust app has no bundle, its build
# gathers what it ships besides its runners.
- name: Build the apps
run: |
cargo build -p nsh-cli
for entry in $(grep -l "mount(" examples/*/*.tsx) $(grep -l '"root"' examples/*/nsh.json); do
./target/debug/nsh build "$entry" -o "$RUNNER_TEMP/bundles/${entry//\//_}"
done