|
| 1 | +name: Rust CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check_changes: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + # exec only when PR is merged |
| 11 | + if: github.event.pull_request.merged == true |
| 12 | + outputs: |
| 13 | + rust_changed: ${{ steps.check_rust_changes.outputs.rust_changed }} |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Check for Rust file changes |
| 20 | + id: check_rust_changes |
| 21 | + run: | |
| 22 | + git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} > changes.txt |
| 23 | + if grep -qE '\.rs$|Cargo\.toml' changes.txt; then |
| 24 | + echo "rust_changed=true" >> $GITHUB_OUTPUT |
| 25 | + else |
| 26 | + echo "rust_changed=false" >> $GITHUB_OUTPUT |
| 27 | + fi |
| 28 | +
|
| 29 | + rust_ci: |
| 30 | + needs: check_changes |
| 31 | + if: needs.check_changes.outputs.rust_changed == 'true' |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: read |
| 35 | + packages: write |
| 36 | + strategy: |
| 37 | + matrix: |
| 38 | + target: [x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl] |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Set up Rust |
| 43 | + uses: actions-rs/toolchain@v1 |
| 44 | + with: |
| 45 | + toolchain: 1.80.0 |
| 46 | + profile: minimal |
| 47 | + override: true |
| 48 | + target: ${{ matrix.target }} |
| 49 | + |
| 50 | + - name: Install cross |
| 51 | + run: cargo install cross |
| 52 | + |
| 53 | + - name: Build with cross |
| 54 | + run: cross build --target ${{ matrix.target }} --release |
| 55 | + |
| 56 | + - name: Set up Docker Buildx |
| 57 | + uses: docker/setup-buildx-action@v3 |
| 58 | + |
| 59 | + - name: Log in to GitHub Container Registry |
| 60 | + uses: docker/login-action@v3 |
| 61 | + with: |
| 62 | + registry: ghcr.io |
| 63 | + username: ${{ github.actor }} |
| 64 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + |
| 66 | + - name: Build and push Docker image |
| 67 | + uses: docker/build-push-action@v5 |
| 68 | + with: |
| 69 | + context: . |
| 70 | + push: true |
| 71 | + tags: ghcr.io/${{ github.repository }}:latest-${{ matrix.target }} |
| 72 | + file: docker/${{ matrix.target }}/Dockerfile |
| 73 | + no_changes: |
| 74 | + needs: check_changes |
| 75 | + if: needs.check_changes.outputs.rust_changed == 'false' |
| 76 | + runs-on: ubuntu-latest |
| 77 | + steps: |
| 78 | + - name: No Rust changes |
| 79 | + run: echo "No changes to Rust files or Cargo.toml, skipping CI." |
0 commit comments