name: Rust CI on: workflow_call: permissions: contents: read pull-requests: write issues: write jobs: lint: name: Lint Rust Code runs-on: blacksmith-4vcpu-ubuntu-2404 steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Rust uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - name: Cache Rust dependencies uses: useblacksmith/rust-cache@v3 with: workspaces: tty-fwd - name: Check formatting id: fmt working-directory: tty-fwd continue-on-error: true run: | cargo fmt -- --check 2>&1 | tee fmt-output.txt echo "result=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT - name: Run Clippy id: clippy working-directory: tty-fwd continue-on-error: true run: | cargo clippy -- -D warnings 2>&1 | tee clippy-output.txt echo "result=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT - name: Read Formatting Output if: always() id: fmt-output working-directory: tty-fwd run: | if [ -f fmt-output.txt ]; then echo 'content<> $GITHUB_OUTPUT cat fmt-output.txt >> $GITHUB_OUTPUT echo 'EOF' >> $GITHUB_OUTPUT else echo "content=No output" >> $GITHUB_OUTPUT fi - name: Read Clippy Output if: always() id: clippy-output working-directory: tty-fwd run: | if [ -f clippy-output.txt ]; then echo 'content<> $GITHUB_OUTPUT cat clippy-output.txt >> $GITHUB_OUTPUT echo 'EOF' >> $GITHUB_OUTPUT else echo "content=No output" >> $GITHUB_OUTPUT fi - name: Report Formatting Results if: always() uses: ./.github/actions/lint-reporter with: title: 'Rust Formatting (cargo fmt)' lint-result: ${{ steps.fmt.outputs.result == '0' && 'success' || 'failure' }} lint-output: ${{ steps.fmt-output.outputs.content }} github-token: ${{ secrets.GITHUB_TOKEN }} - name: Report Clippy Results if: always() uses: ./.github/actions/lint-reporter with: title: 'Rust Clippy' lint-result: ${{ steps.clippy.outputs.result == '0' && 'success' || 'failure' }} lint-output: ${{ steps.clippy-output.outputs.content }} github-token: ${{ secrets.GITHUB_TOKEN }} build-and-test: name: Build and Test (${{ matrix.name }}) strategy: matrix: include: - os: blacksmith-4vcpu-ubuntu-2404 target: x86_64-unknown-linux-gnu name: Linux x86_64 binary-name: tty-fwd - os: macos-latest target: x86_64-apple-darwin name: macOS x86_64 binary-name: tty-fwd - os: macos-latest target: aarch64-apple-darwin name: macOS ARM64 binary-name: tty-fwd runs-on: ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Rust uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - name: Cache Rust dependencies uses: useblacksmith/rust-cache@v3 with: workspaces: tty-fwd key: ${{ matrix.target }} - name: Build working-directory: tty-fwd run: cargo build --release --target ${{ matrix.target }} - name: Run tests # Only run tests on native architectures if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'x86_64-apple-darwin' || matrix.target == 'x86_64-pc-windows-msvc' working-directory: tty-fwd run: cargo test --release - name: Upload binary uses: actions/upload-artifact@v4 with: name: rust-${{ matrix.target }} path: tty-fwd/target/${{ matrix.target }}/release/${{ matrix.binary-name }} coverage: name: Code Coverage runs-on: blacksmith-4vcpu-ubuntu-2404 steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Rust uses: dtolnay/rust-toolchain@stable - name: Install tarpaulin run: cargo install cargo-tarpaulin - name: Cache Rust dependencies uses: useblacksmith/rust-cache@v3 with: workspaces: tty-fwd - name: Run coverage working-directory: tty-fwd run: cargo tarpaulin --verbose --out Xml - name: Upload coverage reports uses: codecov/codecov-action@v4 with: file: ./tty-fwd/cobertura.xml flags: rust name: rust-coverage