diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe9f3d8..3d92537 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,42 @@ env: CARGO_INCREMENTAL: 0 jobs: + # Whether the change is more than documentation. A pull request that only + # changes Markdown files and the pictures under docs/ skips the jobs that + # build and run the code; the lint job still checks the documents' figures and + # copies. A push to main runs everything. + changes: + name: what changed + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + code: ${{ steps.diff.outputs.code }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: false + - id: diff + env: + EVENT: ${{ github.event_name }} + BASE: ${{ github.event.pull_request.base.sha }} + HEAD: ${{ github.event.pull_request.head.sha }} + run: | + if [ "$EVENT" != pull_request ]; then + echo "code=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + # Everything that is not a Markdown file or a picture of docs/. + other=$(git diff --name-only "$BASE...$HEAD" | grep -v -E '(\.md$|^docs/images/)' || true) + if [ -n "$other" ]; then + echo "code=true" >> "$GITHUB_OUTPUT" + echo "changed beyond the documentation:" + echo "$other" + else + echo "code=false" >> "$GITHUB_OUTPUT" + echo "documentation only" + fi + lint: name: fmt + clippy runs-on: ubuntu-latest @@ -41,6 +77,8 @@ jobs: - run: python3 -B scripts/readme_figures.py && git diff --exit-code docs/images msrv: + needs: changes + if: ${{ needs.changes.outputs.code == 'true' }} name: oldest Rust (1.87) runs-on: ubuntu-latest timeout-minutes: 30 @@ -58,6 +96,8 @@ jobs: - run: cargo check --workspace --all-targets --locked wasm: + needs: changes + if: ${{ needs.changes.outputs.code == 'true' }} name: browser build (wasm32) runs-on: ubuntu-latest timeout-minutes: 30 @@ -92,6 +132,8 @@ jobs: - run: node scripts/check_web.mjs build-test: + needs: changes + if: ${{ needs.changes.outputs.code == 'true' }} name: build + test (${{ matrix.os }}) runs-on: ${{ matrix.os }} timeout-minutes: 45 @@ -148,6 +190,8 @@ jobs: run: scripts/check_c_example.sh target/debug xcframework: + needs: changes + if: ${{ needs.changes.outputs.code == 'true' }} name: XCFramework (iOS Simulator, macOS) runs-on: macos-latest timeout-minutes: 45