Skip to content

Commit

Permalink
ci: Dynamically determine job size. (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Feb 25, 2025
1 parent f802aaa commit 726fd60
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 21 deletions.
32 changes: 25 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ on:
pull_request:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For setup-rust
NEXTEST_TEST_THREADS: 3
NEXTEST_RETRIES: 2
PROTO_LOG: trace
# For setup-rust
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
# format:
Expand Down Expand Up @@ -58,28 +59,45 @@ jobs:
# moon-version: latest
# - uses: moonrepo/build-wasm-plugin@v0
# - run: cargo nextest run --no-default-features
plan:
name: Plan
runs-on: ubuntu-latest
outputs:
job-total: ${{ steps.plan.outputs.job-total }}
jobs-array: ${{ steps.plan.outputs.jobs-array }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: moonrepo/setup-toolchain@v0
with:
auto-install: true
- id: plan
run: bash ./scripts/computeCiJobs.sh
ci:
name: Checks
needs:
- plan
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
job: [0, 1, 2]
job: ${{ fromJson(needs.plan.outputs.jobs-array) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: moonrepo/setup-toolchain@v0
with:
auto-install: true
- uses: moonrepo/setup-rust@v1
with:
bins: cargo-nextest
cache: false # Runs out of disk space
components: clippy, rustfmt
targets: wasm32-wasip1
- uses: moonrepo/setup-toolchain@v0
with:
auto-install: true
- run: moon ci --color --log debug --job ${{ matrix.job }} --jobTotal 3
- run: moon ci --color --log debug --job ${{ matrix.job }} --jobTotal ${{ needs.plan.outputs.job-total }}
- uses: moonrepo/run-report-action@v1
if: success() || failure()
with:
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions backends/asdf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

#### 🐞 Fixes

- Ensure an executable is always returned, even if invalid.

## 0.1.2

#### 🐞 Fixes
Expand Down
8 changes: 8 additions & 0 deletions backends/asdf/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ pub fn locate_executables(
}
}

// Return at least something!
if output.exes.is_empty() {
output.exes.insert(
id.clone(),
ExecutableConfig::new_primary(format!("bin/{id}")),
);
}

Ok(Json(output))
}

Expand Down
2 changes: 1 addition & 1 deletion backends/asdf/tests/download_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
mod asdf_backend {
use proto_pdk_test_utils::*;

generate_native_install_tests!("asdf:act", "asdf:0.2.70");
generate_native_install_tests!("asdf:zig", "asdf:0.13.0");
}
12 changes: 6 additions & 6 deletions backends/asdf/tests/metadata_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ mod asdf_backend {
#[tokio::test(flavor = "multi_thread")]
async fn registers_metadata() {
let sandbox = create_empty_proto_sandbox();
let plugin = sandbox.create_plugin("act").await;
let plugin = sandbox.create_plugin("zig").await;

let metadata = plugin
.register_tool(RegisterToolInput { id: "act".into() })
.register_tool(RegisterToolInput { id: "zig".into() })
.await;

assert_eq!(metadata.name, "asdf:act");
assert_eq!(metadata.name, "asdf:zig");
assert_eq!(
metadata.plugin_version.unwrap().to_string(),
env!("CARGO_PKG_VERSION")
Expand All @@ -21,16 +21,16 @@ mod asdf_backend {
#[tokio::test(flavor = "multi_thread")]
async fn registers_backend() {
let sandbox = create_empty_proto_sandbox();
let plugin = sandbox.create_plugin("act").await;
let plugin = sandbox.create_plugin("zig").await;

let metadata = plugin
.register_backend(RegisterBackendInput::default())
.await;

assert_eq!(metadata.backend_id, "asdf-act");
assert_eq!(metadata.backend_id, "asdf-zig");

if let SourceLocation::Git(git) = metadata.source.unwrap() {
assert_eq!(git.url, "https://github.com/gr1m0h/asdf-act");
assert_eq!(git.url, "https://github.com/cheetah/asdf-zig");
}
}
}
2 changes: 1 addition & 1 deletion backends/asdf/tests/shims_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
mod asdf_backend {
use proto_pdk_test_utils::*;

generate_shims_test!("asdf:act", ["act"]);
generate_shims_test!("asdf:zig", ["zig"]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ source: backends/asdf/tests/shims_test.rs
expression: "std :: fs ::\nread_to_string(sandbox.path().join(\".proto/shims/registry.json\")).unwrap()"
---
{
"act": {}
"zig": {}
}
7 changes: 4 additions & 3 deletions backends/asdf/tests/versions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
mod asdf_backend {
use proto_pdk_test_utils::*;

generate_resolve_versions_tests!("asdf:act", {
"asdf:0.2.70" => "0.2.70",
generate_resolve_versions_tests!("asdf:zig", {
"asdf:0.12" => "0.12.1",
"asdf:0.13.0" => "0.13.0",
});

#[tokio::test(flavor = "multi_thread")]
async fn loads_versions_from_git() {
let sandbox = create_empty_proto_sandbox();
let plugin = sandbox
.create_plugin_with_backend("act", Backend::Asdf)
.create_plugin_with_backend("zig", Backend::Asdf)
.await;

let output = plugin.load_versions(LoadVersionsInput::default()).await;
Expand Down
42 changes: 42 additions & 0 deletions scripts/computeCiJobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash


raw=$(moon query tasks --affected --upstream deep --downstream deep)

echo "Tasks:"
echo "$raw"
echo ""

data=$(moon query tasks --affected --upstream deep --downstream deep --json)
taskCount=$(echo "$data" | jq '.tasks | length')
taskPerJob=15
jobTotal=1

if [[ $taskCount == 0 ]]; then
jobTotal=0
elif [[ $taskCount -gt 15 ]]; then
((jobTotal = (taskCount + taskPerJob - 1) / taskPerJob))
fi

jobsArray="["

if [[ $jobTotal -gt 0 ]]; then
for i in $(seq 1 $jobTotal);
do
jobIndex=$((i - 1))
jobsArray+="$jobIndex"

if [[ $i -ne $jobTotal ]]; then
jobsArray+=","
fi
done
fi

jobsArray+="]"

echo "Task count: $taskCount"
echo "Job total: $jobTotal"
echo "Job array: $jobsArray"

echo "job-total=$jobTotal" >> "$GITHUB_OUTPUT"
echo "jobs-array=$jobsArray" >> "$GITHUB_OUTPUT"

0 comments on commit 726fd60

Please # to comment.