feat(ci): cargo build binaries individually (#318) #1680
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 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| packages: write | |
| concurrency: | |
| # Support push/pr as event types with different behaviors each: | |
| # 1. push: queue up builds | |
| # 2. pr: only allow one run per PR | |
| group: ${{ github.workflow }}-${{ github.event_name }}${{ github.event.pull_request.number }} | |
| # If there is already a workflow running for the same pull request, cancel it | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
| env: | |
| RUST_STABLE: 1.89.0 | |
| RUST_NIGHTLY: nightly-2025-08-07 | |
| jobs: | |
| changed-files: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dorny/paths-filter@v3 | |
| id: changed | |
| with: | |
| filters: | | |
| rust: | |
| - 'crates/**' | |
| - 'Cargo.toml' | |
| - 'Cargo.lock' | |
| cargo-toml: | |
| - '**/Cargo.toml' | |
| rustfmt-toml: | |
| - 'rustfmt.toml' | |
| clippy-toml: | |
| - 'clippy.toml' | |
| deny-toml: | |
| - 'deny.toml' | |
| dockerfile: | |
| - 'Dockerfile' | |
| - 'infra/Dockerfile.*' | |
| version: | |
| - 'VERSION' | |
| outputs: | |
| rust: ${{ steps.changed.outputs.rust }} | |
| cargo-toml: ${{ steps.changed.outputs.cargo-toml }} | |
| rustfmt-toml: ${{ steps.changed.outputs.rustfmt-toml }} | |
| clippy-toml: ${{ steps.changed.outputs.clippy-toml }} | |
| deny-toml: ${{ steps.changed.outputs.deny-toml }} | |
| dockerfile: ${{ steps.changed.outputs.dockerfile }} | |
| version: ${{ steps.changed.outputs.version }} | |
| bump-version: | |
| needs: [changed-files] | |
| if: github.event_name == 'pull_request' && (needs.changed-files.outputs.rust == 'true' || needs.changed-files.outputs.dockerfile == 'true') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: "main" | |
| - id: get-current-version | |
| run: echo MAIN_VERSION=$(cat VERSION) >> $GITHUB_ENV | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| token: ${{ secrets.RELEASE_PAT }} | |
| - id: bump-version | |
| run: | | |
| MAIN_MAJOR=$(echo "$MAIN_VERSION" | cut -d. -f1) | |
| MAIN_MINOR=$(echo "$MAIN_VERSION" | cut -d. -f2) | |
| TODAY=$(date +"%y%m%d") | |
| if [[ $MAIN_MAJOR == $TODAY ]]; then | |
| NEW_VERSION=$MAIN_MAJOR.$((MAIN_MINOR + 1)) | |
| else | |
| NEW_VERSION=$TODAY.0 | |
| fi | |
| LOCAL_VERSION=$(cat VERSION) | |
| if [[ $LOCAL_VERSION == $NEW_VERSION ]]; then | |
| exit 0 | |
| fi | |
| echo "${NEW_VERSION}" > VERSION | |
| git config user.name "Github Bot" | |
| git config user.email "github@walletconnect.com" | |
| git add VERSION | |
| git commit -m "Bump VERSION to ${NEW_VERSION}" | |
| git push | |
| misspell: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: reviewdog/action-misspell@v1 | |
| cargo-build: | |
| needs: [changed-files] | |
| if: needs.changed-files.outputs.rust == 'true' | |
| runs-on: | |
| group: ubuntu-runners | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - run: bash .github/install-deps.sh | |
| - uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{ env.RUST_STABLE }} | |
| - uses: Swatinem/rust-cache@v2 | |
| - run: cargo build --workspace --all-features | |
| # Check that binaries can be built outside of the cargo workspace | |
| - run: cargo build -p wcn_node | |
| - run: cargo build -p wcn_db | |
| - run: cargo build -p wcn_operator | |
| - run: cargo build -p wcn_admin | |
| cargo-test: | |
| needs: [changed-files] | |
| if: needs.changed-files.outputs.rust == 'true' | |
| timeout-minutes: 30 | |
| runs-on: | |
| group: ubuntu-runners | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| test: [doc, unit, integration] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - run: bash .github/install-deps.sh | |
| - uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{ env.RUST_STABLE }} | |
| - uses: Swatinem/rust-cache@v2 | |
| - uses: foundry-rs/foundry-toolchain@v1 | |
| with: | |
| version: stable | |
| cache: true | |
| - run: | | |
| TEST_KIND=${{ matrix.test }} | |
| if [[ $TEST_KIND == 'doc' ]] ; then | |
| cargo test --workspace --doc --all-features | |
| elif [[ $TEST_KIND == 'unit' ]]; then | |
| RUST_LOG=info cargo test --all-features --workspace --exclude wcn_testing | |
| elif [[ $TEST_KIND == 'integration' ]]; then | |
| RUST_LOG=info,relay_rocks=warn cargo test -p wcn_testing --all-features --release | |
| else | |
| echo Unexpected test kind $TEST_KIND | |
| exit 1 | |
| fi | |
| cargo-fmt: | |
| needs: [changed-files] | |
| if: needs.changed-files.outputs.rust == 'true' || needs.changed-files.outputs.rustfmt-toml == 'true' | |
| runs-on: | |
| group: ubuntu-runners | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{ env.RUST_NIGHTLY }} | |
| components: rustfmt | |
| - uses: Swatinem/rust-cache@v2 | |
| - run: cargo fmt --all --check | |
| cargo-clippy: | |
| needs: [changed-files] | |
| if: needs.changed-files.outputs.rust == 'true' || needs.changed-files.outputs.clippy-toml == 'true' | |
| runs-on: | |
| group: ubuntu-runners | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - run: bash .github/install-deps.sh | |
| - uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{ env.RUST_NIGHTLY }} | |
| components: clippy | |
| - uses: Swatinem/rust-cache@v2 | |
| - run: cargo clippy --workspace --all-targets --all-features --tests -- -D warnings | |
| cargo-deny: | |
| needs: [changed-files] | |
| if: needs.changed-files.outputs.cargo-toml == 'true' || needs.changed-files.outputs.deny-toml == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: EmbarkStudios/cargo-deny-action@v2 | |
| with: | |
| rust-version: ${{ env.RUST_STABLE }} | |
| command: check license |