|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ['v*'] |
| 7 | + pull_request: |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +env: |
| 11 | + CARGO_TERM_COLOR: always |
| 12 | + |
| 13 | +jobs: |
| 14 | + test: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + services: |
| 18 | + postgres: |
| 19 | + image: postgres:13.4 |
| 20 | + env: |
| 21 | + POSTGRES_USER: postgres |
| 22 | + POSTGRES_PASSWORD: postgres |
| 23 | + options: >- |
| 24 | + --health-cmd pg_isready |
| 25 | + --health-interval 10s |
| 26 | + --health-timeout 5s |
| 27 | + --health-retries 5 |
| 28 | + ports: |
| 29 | + - 5432:5432 |
| 30 | + |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Install Nix |
| 35 | + uses: cachix/install-nix-action@v27 |
| 36 | + with: |
| 37 | + github_access_token: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + |
| 39 | + - name: Cache Nix store |
| 40 | + uses: DeterminateSystems/magic-nix-cache-action@v7 |
| 41 | + |
| 42 | + - name: Cache Rust dependencies |
| 43 | + uses: Swatinem/rust-cache@v2 |
| 44 | + with: |
| 45 | + shared-key: "rust-deps" |
| 46 | + cache-on-failure: true |
| 47 | + |
| 48 | + - name: Check formatting |
| 49 | + run: nix develop --command cargo fmt -- --check |
| 50 | + |
| 51 | + - name: Run clippy |
| 52 | + run: nix develop --command cargo clippy --all-targets --all-features -- -D warnings |
| 53 | + |
| 54 | + - name: Run tests |
| 55 | + run: nix develop --command cargo test |
| 56 | + env: |
| 57 | + DATABASE_URL: postgresql://postgres:postgres@localhost |
| 58 | + |
| 59 | + build-linux: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: test |
| 62 | + |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - name: Install Nix |
| 67 | + uses: cachix/install-nix-action@v27 |
| 68 | + with: |
| 69 | + github_access_token: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + |
| 71 | + - name: Cache Nix store |
| 72 | + uses: DeterminateSystems/magic-nix-cache-action@v7 |
| 73 | + |
| 74 | + - name: Cache Rust dependencies |
| 75 | + uses: Swatinem/rust-cache@v2 |
| 76 | + with: |
| 77 | + shared-key: "rust-deps" |
| 78 | + cache-on-failure: true |
| 79 | + |
| 80 | + - name: Build Linux binary (musl) |
| 81 | + run: | |
| 82 | + nix build .#anonymiser-musl |
| 83 | + cp result/bin/anonymiser anonymiser-x86_64-unknown-linux-musl |
| 84 | +
|
| 85 | + - name: Upload artifact |
| 86 | + uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: anonymiser-linux |
| 89 | + path: anonymiser-x86_64-unknown-linux-musl |
| 90 | + |
| 91 | + test-alpine: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: build-linux |
| 94 | + container: |
| 95 | + image: alpine:3.18 |
| 96 | + |
| 97 | + services: |
| 98 | + postgres: |
| 99 | + image: postgres:13.4 |
| 100 | + env: |
| 101 | + POSTGRES_USER: postgres |
| 102 | + POSTGRES_PASSWORD: postgres |
| 103 | + options: >- |
| 104 | + --health-cmd pg_isready |
| 105 | + --health-interval 10s |
| 106 | + --health-timeout 5s |
| 107 | + --health-retries 5 |
| 108 | +
|
| 109 | + steps: |
| 110 | + - name: Download Linux binary |
| 111 | + uses: actions/download-artifact@v4 |
| 112 | + with: |
| 113 | + name: anonymiser-linux |
| 114 | + |
| 115 | + - name: Make binary executable |
| 116 | + run: chmod +x anonymiser-x86_64-unknown-linux-musl |
| 117 | + |
| 118 | + - name: Test binary on Alpine |
| 119 | + run: | |
| 120 | + ./anonymiser-x86_64-unknown-linux-musl generate-strategies --db-url postgresql://postgres:postgres@postgres |
| 121 | + env: |
| 122 | + DATABASE_URL: postgresql://postgres:postgres@postgres |
| 123 | + |
| 124 | + test-amazon-linux: |
| 125 | + runs-on: ubuntu-latest |
| 126 | + needs: build-linux |
| 127 | + container: |
| 128 | + image: public.ecr.aws/amazonlinux/amazonlinux:latest |
| 129 | + |
| 130 | + services: |
| 131 | + postgres: |
| 132 | + image: postgres:13.4 |
| 133 | + env: |
| 134 | + POSTGRES_USER: postgres |
| 135 | + POSTGRES_PASSWORD: postgres |
| 136 | + options: >- |
| 137 | + --health-cmd pg_isready |
| 138 | + --health-interval 10s |
| 139 | + --health-timeout 5s |
| 140 | + --health-retries 5 |
| 141 | +
|
| 142 | + steps: |
| 143 | + - name: Download Linux binary |
| 144 | + uses: actions/download-artifact@v4 |
| 145 | + with: |
| 146 | + name: anonymiser-linux |
| 147 | + |
| 148 | + - name: Make binary executable |
| 149 | + run: chmod +x anonymiser-x86_64-unknown-linux-musl |
| 150 | + |
| 151 | + - name: Test binary on Amazon Linux |
| 152 | + run: | |
| 153 | + ./anonymiser-x86_64-unknown-linux-musl generate-strategies --db-url postgresql://postgres:postgres@postgres |
| 154 | + env: |
| 155 | + DATABASE_URL: postgresql://postgres:postgres@postgres |
| 156 | + |
| 157 | + build-macos: |
| 158 | + strategy: |
| 159 | + matrix: |
| 160 | + include: |
| 161 | + - runner: macos-13 |
| 162 | + target: x86_64-apple-darwin |
| 163 | + name: Intel Mac |
| 164 | + - runner: macos-14 |
| 165 | + target: aarch64-apple-darwin |
| 166 | + name: Apple silicon mac |
| 167 | + |
| 168 | + runs-on: ${{ matrix.runner }} |
| 169 | + needs: test |
| 170 | + |
| 171 | + steps: |
| 172 | + - uses: actions/checkout@v4 |
| 173 | + |
| 174 | + - name: Install Nix |
| 175 | + uses: cachix/install-nix-action@v27 |
| 176 | + with: |
| 177 | + github_access_token: ${{ secrets.GITHUB_TOKEN }} |
| 178 | + |
| 179 | + - name: Cache Nix store |
| 180 | + uses: DeterminateSystems/magic-nix-cache-action@v7 |
| 181 | + |
| 182 | + - name: Cache Rust dependencies |
| 183 | + uses: Swatinem/rust-cache@v2 |
| 184 | + with: |
| 185 | + shared-key: "rust-deps" |
| 186 | + cache-on-failure: true |
| 187 | + |
| 188 | + - name: Build macOS binary |
| 189 | + run: | |
| 190 | + nix build .#anonymiser |
| 191 | + cp result/bin/anonymiser anonymiser-${{ matrix.target }} |
| 192 | +
|
| 193 | + - name: Test binary |
| 194 | + run: ./anonymiser-${{ matrix.target }} --help |
| 195 | + |
| 196 | + - name: Upload artifact |
| 197 | + uses: actions/upload-artifact@v4 |
| 198 | + with: |
| 199 | + name: anonymiser-${{ matrix.target }} |
| 200 | + path: anonymiser-${{ matrix.target }} |
| 201 | + |
| 202 | + release: |
| 203 | + runs-on: ubuntu-latest |
| 204 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 205 | + needs: [test-alpine, test-amazon-linux, build-macos] |
| 206 | + permissions: |
| 207 | + contents: write |
| 208 | + |
| 209 | + steps: |
| 210 | + - uses: actions/checkout@v4 |
| 211 | + |
| 212 | + - name: Download Linux binary |
| 213 | + uses: actions/download-artifact@v4 |
| 214 | + with: |
| 215 | + name: anonymiser-linux |
| 216 | + |
| 217 | + - name: Download macOS x86_64 binary |
| 218 | + uses: actions/download-artifact@v4 |
| 219 | + with: |
| 220 | + name: anonymiser-x86_64-apple-darwin |
| 221 | + |
| 222 | + - name: Download macOS ARM64 binary |
| 223 | + uses: actions/download-artifact@v4 |
| 224 | + with: |
| 225 | + name: anonymiser-aarch64-apple-darwin |
| 226 | + |
| 227 | + - name: Create GitHub Release |
| 228 | + env: |
| 229 | + GH_TOKEN: ${{ github.token }} |
| 230 | + run: | |
| 231 | + gh release create --draft --generate-notes "${{ github.ref_name }}" \ |
| 232 | + './anonymiser-x86_64-unknown-linux-musl#Linux' \ |
| 233 | + './anonymiser-x86_64-apple-darwin#Intel Mac' \ |
| 234 | + './anonymiser-aarch64-apple-darwin#Apple silicon mac' |
0 commit comments