Skip to content

Commit 5462a6e

Browse files
authored
chore: Improve CI/CD further (#199)
* chore: make CI/CD compile * update commit parsers for release plz * print the output * fix line issues * Print a bit more * fix jq command * fix command * Improve display names for actions and fix short name for subcommand * fix invalid default feature, and remove short option for subcommand * don't print matrix anymore * remove short options * try build docker image * fix tag * leave docker for now * fix into command not taking into account features * fix various problems * fix luau compile error * fix luau and try docker again * typo * try without windows platform * move docker image creation to its own action
1 parent a61e9c6 commit 5462a6e

File tree

7 files changed

+137
-21
lines changed

7 files changed

+137
-21
lines changed

.github/workflows/bevy_mod_scripting.yml

+22-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ on:
1313

1414
name: Check and Lint - bevy_mod_scripting
1515

16+
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: bevy-mod-scripting
20+
1621
concurrency:
1722
# Use github.run_id on main branch
1823
# Use github.event.pull_request.number on pull requests, so it's unique per pull request
@@ -23,20 +28,29 @@ concurrency:
2328
jobs:
2429
generate-job-matrix:
2530
runs-on: ubuntu-latest
31+
# container: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
2632
outputs:
2733
matrix: ${{ steps.generate-matrix.outputs.matrix }}
2834
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
2937
- name: Generate matrix
3038
id: generate-matrix
3139
run: |
32-
echo "matrix=$(cargo xtask ci-matrix)" >> $GITHUB_OUTPUT
40+
cargo xtask ci-matrix > matrix.json
41+
cat matrix.json
42+
echo "Convert to single line JSON"
43+
jq -c . matrix.json > matrix-one-line.json
44+
echo "matrix=$(cat matrix-one-line.json)" >> $GITHUB_OUTPUT
3345
3446
check:
3547
permissions:
3648
pull-requests: write
3749
name: Check - ${{ matrix.run_args.name }}
3850
runs-on: ${{ matrix.run_args.os }}
39-
needs: generate-job-matrix
51+
# container: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
52+
needs:
53+
- generate-job-matrix
4054
strategy:
4155
matrix:
4256
run_args: ${{fromJson(needs.generate-job-matrix.outputs.matrix)}}
@@ -54,7 +68,9 @@ jobs:
5468
override: true
5569
- name: Rust Cache
5670
uses: Swatinem/[email protected]
57-
- uses: actions-rs/cargo@v1
58-
with:
59-
command: ${{ matrix.run_args.command }}
60-
args: ci-check
71+
- name: Setup
72+
run: |
73+
cargo xtask init
74+
- name: Check
75+
run: |
76+
${{ matrix.run_args.command }}

.github/workflows/build-ci-image.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
on:
2+
workflow_dispatch:
3+
4+
5+
env:
6+
REGISTRY: ghcr.io
7+
IMAGE_NAME: bevy-mod-scripting
8+
9+
jobs:
10+
build-runner-image:
11+
permissions:
12+
contents: read
13+
packages: write
14+
runs-on: ubuntu-latest
15+
name: Build multi-platform Docker image
16+
outputs:
17+
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: docker/setup-qemu-action@v3
21+
- uses: docker/setup-buildx-action@v3
22+
- name: Docker meta
23+
id: meta
24+
uses: docker/metadata-action@v5
25+
with:
26+
images: |
27+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
28+
- name: Login to GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
- uses: docker/build-push-action@v5
35+
with:
36+
context: .
37+
file: ./crates/xtask/Dockerfile
38+
platforms: linux/amd64,linux/arm64
39+
cache-from: type=gha
40+
cache-to: type=gha,mode=max
41+
tags: ${{ steps.meta.outputs.tags }}
42+
labels: ${{ steps.meta.outputs.labels }}

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ path = "src/lib.rs"
2020
features = ["lua54"]
2121

2222
[features]
23-
default = ["core_functions", "bevy_bindings", "unsafe_lua_modules"]
23+
default = ["core_functions", "bevy_bindings"]
2424

2525
## lua
26-
lua = ["bevy_mod_scripting_lua"]
26+
lua = ["bevy_mod_scripting_lua", "unsafe_lua_modules"]
2727
# one of these must be selected
2828
lua51 = ["bevy_mod_scripting_lua/lua51", "lua"]
2929
lua52 = ["bevy_mod_scripting_lua/lua52", "lua"]

crates/languages/bevy_mod_scripting_lua/src/bindings/script_value.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ impl FromLua for LuaScriptValue {
4141
Value::Nil => ScriptValue::Unit,
4242
Value::Boolean(b) => ScriptValue::Bool(b),
4343
// Value::LightUserData(light_user_data) => todo!(),
44+
#[cfg(not(feature = "luau"))]
4445
Value::Integer(i) => ScriptValue::Integer(i),
46+
#[cfg(feature = "luau")]
47+
Value::Integer(i) => ScriptValue::Integer(i as i64),
4548
Value::Number(n) => ScriptValue::Float(n),
4649
Value::String(s) => ScriptValue::String(s.to_str()?.to_owned().into()),
4750
Value::Table(table) => {
@@ -86,7 +89,10 @@ impl IntoLua for LuaScriptValue {
8689
Ok(match self.0 {
8790
ScriptValue::Unit => Value::Nil,
8891
ScriptValue::Bool(b) => Value::Boolean(b),
92+
#[cfg(not(feature = "luau"))]
8993
ScriptValue::Integer(i) => Value::Integer(i),
94+
#[cfg(feature = "luau")]
95+
ScriptValue::Integer(i) => Value::Integer(i as i32),
9096
ScriptValue::Float(f) => Value::Number(f),
9197
ScriptValue::String(s) => Value::String(lua.create_string(s.as_ref())?),
9298
ScriptValue::Reference(r) => LuaReflectReference::from(r).into_lua(lua)?,

crates/xtask/Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM rust:latest AS base
2+
RUN cargo install sccache --version ^0.7
3+
RUN cargo install cargo-chef --version ^0.1
4+
ENV RUSTC_WRAPPER=sccache SCCACHE_DIR=/sccache
5+
6+
FROM base AS planner
7+
WORKDIR /app
8+
COPY . .
9+
RUN --mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
10+
cargo chef prepare --recipe-path recipe.json
11+
12+
FROM base as builder
13+
WORKDIR /app
14+
COPY --from=planner /app/recipe.json recipe.json
15+
RUN --mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
16+
cargo chef cook --release --recipe-path recipe.json
17+
COPY . .
18+
RUN --mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
19+
cargo xtask init

crates/xtask/src/main.rs

+36-13
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ impl IntoFeatureGroup for Feature {
107107
#[derive(Debug, Clone, PartialEq, Eq)]
108108
struct Features(HashSet<Feature>);
109109

110+
impl Default for Features {
111+
fn default() -> Self {
112+
Features::new(vec![Feature::Lua54])
113+
}
114+
}
115+
110116
impl Features {
111117
fn new<I: IntoIterator<Item = Feature>>(features: I) -> Self {
112118
Self(features.into_iter().collect())
@@ -161,9 +167,6 @@ impl Features {
161167

162168
impl std::fmt::Display for Features {
163169
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
164-
if &Self::all_features() == self {
165-
return write!(f, "all");
166-
}
167170
for (i, feature) in self.0.iter().sorted().enumerate() {
168171
if i > 0 {
169172
write!(f, ",")?;
@@ -207,6 +210,16 @@ impl App {
207210
fn into_command(self) -> Command {
208211
let mut cmd = Command::new("cargo");
209212
cmd.arg("xtask");
213+
214+
if self.global_args.features != Features::default() {
215+
cmd.arg("--features")
216+
.arg(self.global_args.features.to_string());
217+
}
218+
219+
if let Some(profile) = self.global_args.profile {
220+
cmd.arg("--profile").arg(profile);
221+
}
222+
210223
match self.subcmd {
211224
Xtasks::Macros { macro_name } => {
212225
cmd.arg("macros").arg(macro_name.as_ref());
@@ -281,15 +294,24 @@ impl App {
281294
pub(crate) fn into_ci_row(self, os: String) -> CiMatrixRow {
282295
CiMatrixRow {
283296
command: self.clone().into_command_string().into_string().unwrap(),
284-
name: format!("{} - {}", self.subcmd.as_ref(), self.global_args.features),
297+
name: format!(
298+
"{}({}) - {}",
299+
self.subcmd.as_ref(),
300+
os,
301+
if self.global_args.features == Features::all_features() {
302+
"all features".to_owned()
303+
} else {
304+
self.global_args.features.to_string()
305+
}
306+
),
285307
os,
286308
}
287309
}
288310
}
289311

290312
#[derive(Debug, Parser, Clone)]
291313
struct GlobalArgs {
292-
#[clap(long, short, global = true, value_parser=clap::value_parser!(Features), value_name=Features::to_placeholder(), default_value="lua54",required = false)]
314+
#[clap(long, short, global = true, value_parser=clap::value_parser!(Features), value_name=Features::to_placeholder(), default_value=Features::default().to_string(),required = false)]
293315
features: Features,
294316

295317
#[clap(
@@ -355,15 +377,13 @@ enum Xtasks {
355377
Check {
356378
#[clap(
357379
long,
358-
short,
359380
default_value = "false",
360381
help = "Run in the expected format for rust-analyzer's override check command"
361382
)]
362383
ide_mode: bool,
363384

364385
#[clap(
365386
long,
366-
short,
367387
default_value = "all",
368388
value_parser=clap::value_parser!(CheckKind),
369389
value_name=CheckKind::to_placeholder(),
@@ -375,25 +395,25 @@ enum Xtasks {
375395
Docs {
376396
/// Open in browser
377397
/// This will open the generated docs in the default browser
378-
#[clap(long, short)]
398+
#[clap(long)]
379399
open: bool,
380400

381401
/// Skip building rust docs
382-
#[clap(long, short)]
402+
#[clap(long)]
383403
no_rust_docs: bool,
384404
},
385405
/// Build the main workspace, and then run all tests
386406
Test {
387407
/// Run tests containing the given name only
388-
#[clap(long, short)]
408+
#[clap(long)]
389409
name: Option<String>,
390410

391411
/// Run tests in the given package only
392-
#[clap(long, short)]
412+
#[clap(long)]
393413
package: Option<String>,
394414

395415
/// Run tests without coverage
396-
#[clap(long, short)]
416+
#[clap(long)]
397417
no_coverage: bool,
398418
},
399419
/// Perform a full check as it would be done in CI, except not parallelised
@@ -454,22 +474,25 @@ impl Xtasks {
454474
// we don't need to verify all feature flags on all platforms, this is mostly a "does it compile" check
455475
// for finding out missing compile time logic or bad imports
456476
multi_os_steps
457-
.retain(|e| !e.command.contains("build") && !e.command.contains("docs"));
477+
.retain(|e| !e.command.contains(" build") && !e.command.contains(" docs"));
458478

459479
let mut macos_matrix = multi_os_steps.clone();
460480
let mut windows_matrix = multi_os_steps.clone();
461481

462482
for row in macos_matrix.iter_mut() {
463483
row.os = "macos-latest".to_owned();
484+
row.name = row.name.replace("ubuntu-latest", "macos-latest");
464485
}
465486

466487
for row in windows_matrix.iter_mut() {
467488
row.os = "windows-latest".to_owned();
489+
row.name = row.name.replace("ubuntu-latest", "windows-latest");
468490
}
469491

470492
matrix.extend(macos_matrix);
471493
matrix.extend(windows_matrix);
472494

495+
matrix.sort_by_key(|e| e.name.to_owned());
473496
let json = serde_json::to_string_pretty(&matrix)?;
474497
return Ok(json);
475498
}

release-plz.toml

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ dependencies_update = false
33
publish_timeout = "30m"
44
git_release_enable = false
55
git_tag_enable = false
6+
commit_parsers = [
7+
{ message = "^feat", group = "added" },
8+
{ message = "^changed", group = "changed" },
9+
{ message = "^deprecated", group = "deprecated" },
10+
{ message = "^fix", group = "fixed" },
11+
{ message = "^security", group = "security" },
12+
{ message = "^.*", group = "other" },
13+
# dont include chore changes in changelog
14+
{ message = "^chore.*", skip = true },
15+
]
616

717
[[package]]
818
name = "bevy_mod_scripting"

0 commit comments

Comments
 (0)