Add composite action for setting up Rust environment and create test workflow
Some checks failed
Test / verify-generated-code (pull_request) Has been cancelled
Test / test (pull_request) Has been cancelled
Test / lint (pull_request) Has been cancelled

This commit is contained in:
GW_MC
2025-11-15 11:26:40 +08:00
parent d05d660198
commit 467e6bfcf5
2 changed files with 130 additions and 0 deletions

77
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,77 @@
# this workflow runs tests on pull request and push events targeting master branch
# it also verify the generated code is up to date and valid
name: Test
on:
pull_request:
branches:
- master
push:
branches:
- master
jobs:
# setup is now handled by a composite action used by downstream jobs to keep
# the workflow DRY. The composite action performs checkout, cache restore and
# toolchain setup.
verify-generated-code:
# no need to depend on a separate setup job; the composite action runs in
# this job and restores caches/toolchain here.
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Rust, checkout and restore caches
uses: ./.github/actions/setup-rust
- name: generate entities from migration files
run: |
cd apps/cli
cargo run -- db:migrate_and_generate --output-path ../../public/database/src/generated/entities
- name: Check for uncommitted changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "Generated code is not up to date. Please run the code generation locally and commit the changes."
git status --porcelain
exit 1
else
echo "Generated code is up to date."
fi
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Rust, checkout and restore caches
uses: ./.github/actions/setup-rust
- name: Run tests
run: cargo test --all-features
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Rust, checkout and restore caches
uses: ./.github/actions/setup-rust
with:
components: clippy, rustfmt
- name: Run clippy
run: cargo clippy --all-features -- -D warnings
- name: Check code formatting
run: cargo fmt --all -- --check