name: CI on: push: pull_request: branches: [ main ] env: CARGO_TERM_COLOR: always jobs: fetch: name: Fetch Cargo dependencies runs-on: ubuntu-latest steps: - name: Checkout the code uses: actions/checkout@v2 - name: Install toolchain uses: actions-rs/toolchain@v1 with: toolchain: "1.56.0" # MSRV target: x86_64-unknown-linux-musl profile: minimal override: true - name: Setup Cargo cache uses: actions/cache@v2.1.6 with: path: | ~/.cargo/registry/index ~/.cargo/registry/cache ~/.cargo/git/db key: ${{ runner.os }}-cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-deps-msrv- - name: Fetch dependencies id: fetch uses: actions-rs/cargo@v1 continue-on-error: true with: command: fetch args: --locked - name: Fetch dependencies (retry) id: fetch-2 uses: actions-rs/cargo@v1 if: steps.fetch.outcome == 'failure' continue-on-error: true with: command: fetch args: --locked - name: Fetch dependencies (second retry) uses: actions-rs/cargo@v1 if: steps.fetch.outcome == 'failure' && steps.fetch-2.outcome == 'failure' with: command: fetch args: --locked lsif: name: Generate LSIF index and upload it to Sourcegraph needs: [fetch] runs-on: ubuntu-latest if: github.event_name == 'push' steps: - name: Checkout the code uses: actions/checkout@v2 - name: Install toolchain uses: actions-rs/toolchain@v1 with: toolchain: nightly target: x86_64-unknown-linux-musl components: rustfmt profile: minimal override: true - name: Setup Cargo cache uses: actions/cache@v2.1.6 with: path: | ~/.cargo/registry/index ~/.cargo/registry/cache ~/.cargo/git/db key: ${{ runner.os }}-cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }} - name: Generate LSIF data uses: sourcegraph/lsif-rust-action@v0.1.0 - name: Upload LSIF data uses: sourcegraph/lsif-upload-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} rustfmt: name: Check style needs: [fetch] runs-on: ubuntu-latest steps: - name: Checkout the code uses: actions/checkout@v2 - name: Install toolchain id: toolchain uses: actions-rs/toolchain@v1 with: toolchain: nightly target: x86_64-unknown-linux-musl components: rustfmt profile: minimal override: true - name: Setup Cargo cache uses: actions/cache@v2.1.6 with: path: | ~/.cargo/registry/index ~/.cargo/registry/cache ~/.cargo/git/db key: ${{ runner.os }}-cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }} - name: Setup build cache uses: actions/cache@v2.1.6 with: path: | target key: cargo-fmt-${{ hashFiles('**/Cargo.lock') }}-${{ steps.toolchain.outputs.rustc_hash }} - name: Check style uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check clippy: name: Run Clippy needs: [fetch] runs-on: ubuntu-latest steps: - name: Checkout the code uses: actions/checkout@v2 - name: Install toolchain id: toolchain uses: actions-rs/toolchain@v1 with: toolchain: stable target: x86_64-unknown-linux-musl components: clippy profile: minimal override: true - name: Setup Cargo cache uses: actions/cache@v2.1.6 with: path: | ~/.cargo/registry/index ~/.cargo/registry/cache ~/.cargo/git/db key: ${{ runner.os }}-cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }} - name: Setup build cache uses: actions/cache@v2.1.6 with: path: | target key: cargo-clippy-${{ hashFiles('**/Cargo.lock') }}-${{ steps.toolchain.outputs.rustc_hash }} - name: Run Clippy uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} test: name: Run test suite with Rust ${{ matrix.toolchain }} needs: [rustfmt, clippy, fetch] runs-on: ubuntu-latest continue-on-error: "${{ matrix.toolchain == 'beta' || matrix.toolchain == 'nightly' }}" strategy: fail-fast: false # Continue other jobs if one fails to help filling the cache matrix: toolchain: - "1.56.0" # MSRV - stable - beta - nightly steps: - name: Checkout the code uses: actions/checkout@v2 - name: Install toolchain id: toolchain uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.toolchain }} target: x86_64-unknown-linux-musl profile: minimal override: true - name: Setup Cargo cache uses: actions/cache@v2.1.6 with: path: | ~/.cargo/registry/index ~/.cargo/registry/cache ~/.cargo/git/db key: ${{ runner.os }}-cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }} - name: Setup build cache uses: actions/cache@v2.1.6 with: path: | target key: ${{ runner.os }}-cargo-build-${{ steps.toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-build-${{ steps.toolchain.outputs.rustc_hash }}- ${{ runner.os }}-cargo-build- - name: Test uses: actions-rs/cargo@v1 with: command: test args: --offline coverage: name: Code coverage needs: [rustfmt, clippy, fetch] runs-on: ubuntu-latest steps: - name: Checkout the code uses: actions/checkout@v2 - name: Install toolchain id: toolchain uses: actions-rs/toolchain@v1 with: toolchain: nightly target: x86_64-unknown-linux-musl override: true components: llvm-tools-preview - name: Setup Cargo cache uses: actions/cache@v2.1.6 with: path: | ~/.cargo/registry/index ~/.cargo/registry/cache ~/.cargo/git/db key: ${{ runner.os }}-cargo-deps-msrv-${{ hashFiles('**/Cargo.lock') }} - name: Setup build cache uses: actions/cache@v2.1.6 with: path: | target key: ${{ runner.os }}-cargo-coverage-${{ steps.toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-coverage-${{ steps.toolchain.outputs.rustc_hash }}- ${{ runner.os }}-cargo-coverage- - name: Download grcov run: | mkdir -p "${HOME}/.local/bin" curl -sL https://github.com/mozilla/grcov/releases/latest/download/grcov-linux-x86_64.tar.bz2 | tar -jxf - -C "${HOME}/.local/bin" echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Run test suite with profiling enabled uses: actions-rs/cargo@v1 with: command: test args: --all-features --no-fail-fast env: CARGO_INCREMENTAL: '0' RUSTFLAGS: '-Zinstrument-coverage' RUSTDOCFLAGS: "-Cpanic=abort -Zinstrument-coverage -Zunstable-options --persist-doctests ${{ github.workspace }}/target/debug/doctestbins" LLVM_PROFILE_FILE: "cargo-test-%p-%m.profraw" - name: Build grcov report run: | mkdir -p target/coverage grcov . --binary-path ./target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/tests.lcov grcov . --binary-path ./target/debug/doctestbins/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/doctests.lcov - name: Upload to codecov.io uses: codecov/codecov-action@v2 with: files: target/coverage/*.lcov build-image: name: Build and push Docker image needs: [rustfmt, clippy] runs-on: ubuntu-latest steps: - name: Checkout the code uses: actions/checkout@v2 - name: Docker meta id: meta uses: docker/metadata-action@v3 with: images: ghcr.io/matrix-org/matrix-authentication-service bake-target: docker-metadata-action tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha - name: Docker meta (debug variant) id: meta-debug uses: docker/metadata-action@v3 with: images: ghcr.io/matrix-org/matrix-authentication-service bake-target: docker-metadata-action-debug tags: | type=ref,event=branch,suffix=-debug type=ref,event=pr,suffix=-debug type=semver,pattern={{version}},suffix=-debug type=semver,pattern={{major}}.{{minor}},suffix=-debug type=semver,pattern={{major}},suffix=-debug type=sha,suffix=-debug - name: Merge buildx bake files run: | jq -s '.[0] * .[1]' ${{ steps.meta.outputs.bake-file }} ${{ steps.meta-debug.outputs.bake-file }} > docker-bake.override.json - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Login to GitHub Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push uses: docker/bake-action@v1 with: targets: gha push: ${{ github.event_name != 'pull_request' }}