Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .cargo/moon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
$schema: 'https://moonrepo.dev/schemas/project.json'

# Rust lint, fix and test run once for the whole Cargo workspace instead of per
# crate. Separate per-crate cargo invocations resolve different feature sets and
# recompile shared dependencies for each crate, while waiting on each other's
# build directory lock. All Rust test tasks use identical cargo arguments so they
# share build artifacts, and only differ in the nextest filter. Clippy uses its
# own target directory so it doesn't wait on the test build's lock in CI.

workspace:
inheritedTasks:
include: []

fileGroups:
rust:
- '/Cargo.lock'
- '/rust-toolchain.toml'
- '/clippy.toml'
- '/rustfmt.toml'
- '/.cargo/config.toml'
- '/**/Cargo.toml'
- '/**/*.rs'
- '/**/.sqlx/**/*'
- '/**/migrations/**/*'
- '/apps/app/**/*'
- '/apps/labrinth/**/*'
- '/packages/app-lib/**/*'
- '!/**/node_modules/**'
- '/packages/app-lib/.env'
- '$CARGO_*'
- '$RUST_*'
- '$RUSTFLAGS'
- '$SQLX_OFFLINE'
- '$DATABASE_URL'

# Tauri embeds the app frontend at compile time
tasks:
lint:
script: |
set -e
cargo fmt --all --check
cargo clippy --workspace --all-targets --features sqlx-tracing/sqlite
cargo clippy --workspace --all-targets --features sqlx-tracing/sqlite,theseus_gui/updater
deps:
- 'app-frontend:build'
inputs:
- '@group(rust)'
env:
CARGO_TARGET_DIR: 'target/clippy'
options:
runFromWorkspaceRoot: true

fix:
script: |
set -e
cargo clippy --workspace --all-targets --features sqlx-tracing/sqlite,theseus_gui/updater --fix --allow-dirty
cargo fmt --all
deps:
- 'app-frontend:build'
env:
CARGO_TARGET_DIR: 'target/clippy'
options:
cache: false
runInCI: false
runFromWorkspaceRoot: true

# Labrinth's tests need Docker services, so they run in `labrinth:test`
test:
command: "cargo nextest run --workspace --all-targets --features sqlx-tracing/sqlite --no-fail-fast -E 'not package(labrinth)'"
deps:
- 'app-frontend:build'
inputs:
- '@group(rust)'
- '!/apps/labrinth/**/*'
- '$REDIS_*'
- '$NEXTEST_*'
options:
runFromWorkspaceRoot: true
58 changes: 58 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Setup
description: Set up Node.js, pnpm and caches (Namespace cache volume, or GitHub caches elsewhere)

inputs:
namespace:
description: Whether the job runs on Namespace, which enables cache volumes
default: 'true'
cache:
description: Cache modes for nscloud-cache-action, in addition to the moon cache
default: pnpm

runs:
using: composite
steps:
- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc

- name: Enable Corepack
shell: bash
run: corepack enable

- name: Force colored moon output
shell: bash
run: echo "MOON_COLOR=3" >> "$GITHUB_ENV"

- name: Set up caches
if: inputs.namespace == 'true'
uses: namespacelabs/nscloud-cache-action@c5f8dab7560444c4bf8dbc64f1b203431873c547 # v1.6.1
with:
cache: ${{ inputs.cache }}
path: |
${{ github.workspace }}/.moon/cache

- name: Get pnpm store path
if: inputs.namespace != 'true'
id: pnpm-store
shell: bash
run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"

- name: Cache pnpm store
if: inputs.namespace != 'true'
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ steps.pnpm-store.outputs.path }}
key: pnpm-store-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
pnpm-store-${{ runner.os }}-

- name: Cache moon outputs
if: inputs.namespace != 'true'
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .moon/cache
key: moon-${{ runner.os }}-${{ github.sha }}
restore-keys: |
moon-${{ runner.os }}-
1 change: 1 addition & 0 deletions .github/workflows/api-client-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
timeout-minutes: 2
with:
fetch-depth: 0

Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/check-generic.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/check-rust.yml

This file was deleted.

85 changes: 40 additions & 45 deletions .github/workflows/turbo-ci.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,37 @@ jobs:
REDIS_URL: redis://127.0.0.1:7000,redis://127.0.0.1:7001,redis://127.0.0.1:7002,redis://127.0.0.1:7003,redis://127.0.0.1:7004,redis://127.0.0.1:7005
# Avoid stack overflows in tests
RUST_MIN_STACK: 134217728
# Namespace's sccache backend is only available to internal runs
SCCACHE_CACHE_SIZE: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && '20G' || '' }}
RUSTC_WRAPPER: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 'sccache' || '' }}

steps:
- name: Check out code
if: env.INTERNAL != 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
timeout-minutes: 2
with:
fetch-depth: 2
# moon compares against main in CI, which needs full history.
# Skipping blobs keeps the clone small on GitHub-hosted runners
fetch-depth: 0
filter: blob:none

- name: Check out code (Namespace)
if: env.INTERNAL == 'true'
uses: namespacelabs/nscloud-checkout-action@66f2dc6f6c42a8ac6c4e53473c4840006822831e # v9.0.1
timeout-minutes: 2
with:
fetch-depth: 2
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc

- name: Enable Corepack
run: corepack enable

- name: Set up caches
if: env.INTERNAL == 'true'
uses: namespacelabs/nscloud-cache-action@c5f8dab7560444c4bf8dbc64f1b203431873c547 # v1.6.1
- name: Setup Node and caches
uses: ./.github/actions/setup
with:
namespace: ${{ env.INTERNAL }}
cache: |
rust
pnpm
apt

- name: Set up Turborepo caching
if: env.INTERNAL == 'true'
uses: namespace-actions/setup-turbocache@f96bd6befa13ae74b2858a5be49573640d4636f5 # v0.0.2

- name: Install apt dependencies
run: |
sudo apt-get update
Expand All @@ -83,14 +79,33 @@ jobs:
components: clippy, rustfmt
cache: false

# External contributors run on GitHub runners without the Namespace cache volume.
# Pushes to main save their Rust build to GitHub's cache (only when dependencies
# change, without restoring it over the Namespace cache) so those runs start warm.
# RUSTC_WRAPPER is left out of the key since only Namespace runs use sccache.
- name: Set up GitHub Rust cache
if: env.INTERNAL != 'true' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
env-vars: CARGO CC CFLAGS CXX CMAKE RUSTFLAGS RUST_
lookup-only: ${{ env.INTERNAL == 'true' }}
save-if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}

- name: Setup mold
uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 # v1 / Mold 2.41.0

- name: Setup binstall
uses: cargo-bins/cargo-binstall@ead08b90bd7b2e6d81963fb9cf0b7239f66d5db4 # v1.21.0
- name: Setup sccache
if: env.INTERNAL == 'true'
uses: mozilla-actions/sccache-action@9e7fa8a12102821edf02ca5dbea1acd0f89a2696 # v0.0.10

- name: Configure sccache
if: env.INTERNAL == 'true'
run: nsc cache sccache setup --cache_name default >> "$GITHUB_ENV"

- name: Setup nextest
run: cargo binstall --no-confirm --secure --locked cargo-nextest@0.9.133
- name: Setup Rust tools
uses: taiki-e/install-action@b6ff580856c41316412a0b9b60540fbc6f8c82cc # v2.86.7
with:
tool: cargo-nextest@0.9.133,typos@1.48.0,tombi@1.4.1,cargo-shear

# cargo-binstall does not have pre-built binaries for sqlx-cli, so we fall
# back to a cached cargo install
Expand All @@ -109,34 +124,14 @@ jobs:
working-directory: packages/app-lib
run: cp .env.staging .env

# check if labrinth tests will actually run (cache miss)
- name: Check if labrinth tests need to run
id: check-labrinth
run: |
LABRINTH_TEST_STATUS=$(pnpm turbo run test --filter=@modrinth/labrinth --dry-run=json | jq -r '.tasks[] | select(.task == "test") | .cache.status')
echo "Labrinth test cache status: $LABRINTH_TEST_STATUS"
if [ "$LABRINTH_TEST_STATUS" = "HIT" ]; then
echo "needs_services=false" >> $GITHUB_OUTPUT
else
echo "needs_services=true" >> $GITHUB_OUTPUT
fi

- name: Start services
if: steps.check-labrinth.outputs.needs_services == 'true'
run: docker compose --profile clustered-redis up --wait

- name: Setup labrinth environment and database
if: steps.check-labrinth.outputs.needs_services == 'true'
working-directory: apps/labrinth
run: |
cp .env.local .env
sqlx database setup

- name: Lint and test
run: pnpm run ci
env:
# "Re-run jobs" with debug logging enabled also turns on moon's debug output
MOON_LOG: ${{ runner.debug == '1' && 'debug' || 'info' }}

- name: Verify intl:extract has been run
run: |
pnpm turbo run intl:extract --force
pnpm moon run :intl-extract --force
pnpm scripts i18n-icu-contract prune-local --check
git diff --exit-code --color */*/src/locales/*/index.json
Loading
Loading