Add new GitHub Actions job to check that examples compile and are properly formatted #1900
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Utoipa build | |
on: | |
push: | |
paths: | |
- "**.rs" | |
- "**Cargo.toml" | |
pull_request: | |
branches: [master] | |
paths: | |
- "**.rs" | |
- "**Cargo.toml" | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
test: | |
strategy: | |
matrix: | |
crate: | |
- utoipa | |
- utoipa-gen | |
- utoipa-swagger-ui | |
- utoipa-redoc | |
- utoipa-rapidoc | |
fail-fast: true | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
- uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Resolve changed paths | |
id: changes | |
run: | | |
changes=false | |
while read -r change; do | |
if [[ "$change" == "utoipa-gen" && "${{ matrix.crate }}" == "utoipa-gen" && $changes == false ]]; then | |
changes=true | |
elif [[ "$change" == "utoipa-swagger-ui" && "${{ matrix.crate }}" == "utoipa-swagger-ui" && $changes == false ]]; then | |
changes=true | |
elif [[ "$change" == "utoipa" && "${{ matrix.crate }}" == "utoipa" && $changes == false ]]; then | |
changes=true | |
elif [[ "$change" == "utoipa-redoc" && "${{ matrix.crate }}" == "utoipa-redoc" && $changes == false ]]; then | |
changes=true | |
elif [[ "$change" == "utoipa-rapidoc" && "${{ matrix.crate }}" == "utoipa-rapidoc" && $changes == false ]]; then | |
changes=true | |
fi | |
done < <(git diff --name-only ${{ github.sha }}~ ${{ github.sha }} | grep .rs | awk -F \/ '{print $1}') | |
echo "${{ matrix.crate }} changes: $changes" | |
echo "changes=$changes" >> $GITHUB_OUTPUT | |
- name: Check format | |
run: | | |
if [[ ${{ steps.changes.outputs.changes }} == true ]]; then | |
cargo fmt --check --package ${{ matrix.crate }} | |
fi | |
- name: Check clippy | |
run: | | |
if [[ ${{ steps.changes.outputs.changes }} == true ]]; then | |
cargo clippy --quiet --package ${{ matrix.crate }} | |
fi | |
- name: Run tests | |
run: | | |
if [[ ${{ steps.changes.outputs.changes }} == true ]]; then | |
./scripts/test.sh ${{ matrix.crate }} | |
fi | |
test-examples-compile: | |
name: "test (examples)" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
- uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
examples/**/target/ | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}_examples | |
- name: Test that examples compile | |
run: | | |
./scripts/validate-examples.sh |