Add CI job to check copyright headers in Rust files #7
Workflow file for this run
This file contains hidden or 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: CI — fmt, clippy, build, test | ||
| on: | ||
| push: - name: Check copyright headers | ||
| run: | | ||
| EXPECTED_HEADER=$(tail -n +3 tools/copyright_header.txt) | ||
| find . -name "*.rs" -type f | while read -r file; do | ||
| if [[ "$file" == *"/target/"* ]] || [[ "$file" == *"/envoy-data-plane-api/"* ]]; then | ||
| continue | ||
| fi | ||
| header=$(head -n 16 "$file") | ||
| if [[ "$header" != "$EXPECTED_HEADER" ]]; then | ||
| echo "Incorrect copyright header in: $file" | ||
| exit 1 | ||
| fi | ||
| done | ||
| echo "All Rust files have correct copyright headers." [ main, master ] | ||
| pull_request: | ||
| branches: [ main, master ] | ||
| env: | ||
| CARGO_CACHE_PATH: ~/.cargo/registry | ||
| CARGO_GIT_PATH: ~/.cargo/git | ||
| TARGET_DIR: target | ||
| jobs: | ||
| # Fast checks that run in parallel (no build artifacts needed) | ||
| checks: | ||
| name: fmt + clippy | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Initialize git submodules | ||
| run: git submodule update --init --recursive | ||
| - name: Cache cargo | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ${{ env.CARGO_CACHE_PATH }} | ||
| ${{ env.CARGO_GIT_PATH }} | ||
| key: ${{ runner.os }}-cargo-checks-${{ hashFiles('**/Cargo.lock', 'envoy-data-plane-api/build.rs') }} | ||
| - name: Install protoc | ||
| run: sudo apt-get update && sudo apt-get install -y protobuf-compiler | ||
| - name: Setup Rust | ||
| uses: actions-rs/toolchain@v1 | ||
| with: | ||
| toolchain: stable | ||
| components: rustfmt, clippy | ||
| profile: minimal | ||
| - name: Check formatting | ||
| run: cargo fmt --all -- --check | ||
| - name: Run clippy (fail on warnings) | ||
| run: cargo clippy --all-targets --all-features | ||
| - name: Check copyright headers | ||
| run: | | ||
| EXPECTED_HEADER=$(cat tools/copyright_header.txt) | ||
| find . -name "*.rs" -type f | while read -r file; do | ||
| if [[ "$file" == *"/target/"* ]] || [[ "$file" == *"/envoy-data-plane-api/"* ]]; then | ||
| continue | ||
| fi | ||
| header=$(head -n 16 "$file") | ||
| if [[ "$header" != "$EXPECTED_HEADER" ]]; then | ||
| echo "Incorrect copyright header in: $file" | ||
| exit 1 | ||
| fi | ||
| done | ||
| echo "All Rust files have correct copyright headers." | ||
| # Build and test that share artifacts | ||
| build-and-test: | ||
| name: build + test | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Initialize git submodules | ||
| run: git submodule update --init --recursive | ||
| - name: Cache cargo | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ${{ env.CARGO_CACHE_PATH }} | ||
| ${{ env.CARGO_GIT_PATH }} | ||
| ${{ env.TARGET_DIR }} | ||
| key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock', 'envoy-data-plane-api/build.rs') }} | ||
| - name: Install protoc | ||
| run: sudo apt-get update && sudo apt-get install -y protobuf-compiler | ||
| - name: Setup Rust | ||
| uses: actions-rs/toolchain@v1 | ||
| with: | ||
| toolchain: stable | ||
| profile: minimal | ||
| - name: Build (release) | ||
| run: cargo build --workspace --release --locked | ||
| - name: Run tests | ||
| run: cargo test --workspace --release --locked | ||