summaryrefslogtreecommitdiff
path: root/.github/workflows/rust.yml
blob: 071dc47e56357c80e1e2cbcaadde362b211682e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Rust CI

on:
  push:
    branches: ["release"]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-D warnings"

jobs:
  setup:
    runs-on: ubuntu-latest
    outputs:
      cache-key: ${{ steps.cache-key.outputs.value }}
    steps:
      - uses: actions/checkout@v4
      - name: Install Rust toolchain
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable
          targets: x86_64-unknown-linux-musl
      - name: Install musl development tools
        run: sudo apt-get update && sudo apt-get install -y musl-tools
      - name: Generate cache key
        id: cache-key
        run: echo "value=cargo-$(rustc -V | sed 's/.*(\(.*\))/\1/')-$(sha256sum Cargo.lock | cut -d' ' -f1)" >> $GITHUB_OUTPUT

  lint:
    runs-on: ubuntu-latest
    needs: setup
    steps:
      - uses: actions/checkout@v4
      - name: Restore cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ needs.setup.outputs.cache-key }}-lint
      - name: Install Rust toolchain
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable
          components: clippy, rustfmt
      - name: Run clippy
        run: cargo clippy --workspace --all-targets -- -D warnings

  test:
    runs-on: ubuntu-latest
    needs: setup
    env:
      CARGO_BUILD_TARGET: x86_64-unknown-linux-musl
    steps:
      - uses: actions/checkout@v4
      - name: Restore cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ needs.setup.outputs.cache-key }}-test
      - name: Install musl target and tools
        run: |
          rustup target add x86_64-unknown-linux-musl
          sudo apt-get update && sudo apt-get install -y musl-tools
      - name: Build
        run: cargo build --workspace --verbose
      - name: Run tests
        run: cargo test --workspace --verbose
      - name: Check binary compatibility
        run: |
          cargo build --workspace --release
          find target/x86_64-unknown-linux-musl/release -maxdepth 1 -executable -type f 2>/dev/null | head -5 | xargs -I {} sh -c 'file {} | grep -q "statically linked" && echo "✓ {} is statically linked" || echo "✗ {} is not statically linked"'

  release:
    runs-on: ubuntu-latest
    needs: [lint, test]
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    env:
      CARGO_BUILD_TARGET: x86_64-unknown-linux-musl
    steps:
      - uses: actions/checkout@v4
      - name: Restore cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ needs.setup.outputs.cache-key }}-release
      - name: Build release binaries
        run: cargo build --workspace --release
      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: release-binaries
          path: target/x86_64-unknown-linux-musl/release/