|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + tags: [ '*' ] |
| 7 | + pull_request: |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + target: |
| 20 | + - x86_64-unknown-linux-gnu |
| 21 | + - aarch64-unknown-linux-gnu |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - uses: actions/cache@v4 |
| 27 | + with: |
| 28 | + path: | |
| 29 | + ~/.cargo/bin/ |
| 30 | + ~/.cargo/registry/index/ |
| 31 | + ~/.cargo/registry/cache/ |
| 32 | + ~/.cargo/git/db/ |
| 33 | + target/ |
| 34 | + key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} |
| 35 | + restore-keys: | |
| 36 | + ${{ runner.os }}-cargo-${{ matrix.target }}- |
| 37 | +
|
| 38 | + - uses: dtolnay/rust-toolchain@stable |
| 39 | + |
| 40 | + - name: Install cross |
| 41 | + run: wget -cO - https://github.com/cross-rs/cross/releases/latest/download/cross-x86_64-unknown-linux-gnu.tar.gz | tar -xz |
| 42 | + |
| 43 | + - name: Build |
| 44 | + run: ./cross build --release --target ${{ matrix.target }} |
| 45 | + |
| 46 | + - name: Rename binary |
| 47 | + run: | |
| 48 | + mv target/${{ matrix.target }}/release/sflow_exporter sflow_exporter_${{ matrix.target }} |
| 49 | +
|
| 50 | + - uses: actions/upload-artifact@v3 |
| 51 | + with: |
| 52 | + name: sflow_exporter_${{ matrix.target }} |
| 53 | + path: sflow_exporter_${{ matrix.target }} |
| 54 | + |
| 55 | + - uses: crazy-max/ghaction-github-release@v2 |
| 56 | + if: startsWith(github.ref, 'refs/tags/') |
| 57 | + with: |
| 58 | + files: sflow_exporter_${{ matrix.target }} |
| 59 | + |
| 60 | + nix: |
| 61 | + needs: build |
| 62 | + runs-on: ubuntu-latest |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - uses: cachix/install-nix-action@v25 |
| 67 | + |
| 68 | + - run: nix build -L |
| 69 | + - run: nix flake check -L |
| 70 | + |
| 71 | + docker: |
| 72 | + needs: build |
| 73 | + runs-on: ubuntu-latest |
| 74 | + |
| 75 | + permissions: |
| 76 | + packages: write |
| 77 | + |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - name: Docker meta |
| 82 | + id: meta |
| 83 | + uses: docker/metadata-action@v5 |
| 84 | + with: |
| 85 | + images: ghcr.io/${{ github.repository }} |
| 86 | + tags: | |
| 87 | + type=edge |
| 88 | + type=ref,event=pr |
| 89 | + type=semver,pattern={{version}} |
| 90 | + type=semver,pattern={{major}}.{{minor}} |
| 91 | + type=semver,pattern={{major}} |
| 92 | +
|
| 93 | + - uses: docker/setup-qemu-action@v3 |
| 94 | + - uses: docker/setup-buildx-action@v3 |
| 95 | + |
| 96 | + - name: Cache Docker layers |
| 97 | + uses: actions/cache@v4 |
| 98 | + with: |
| 99 | + path: /tmp/.buildx-cache |
| 100 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 101 | + restore-keys: | |
| 102 | + ${{ runner.os }}-buildx- |
| 103 | +
|
| 104 | + - name: Login to GitHub Container Registry |
| 105 | + uses: docker/login-action@v3 |
| 106 | + if: github.event_name != 'pull_request' |
| 107 | + with: |
| 108 | + registry: ghcr.io |
| 109 | + username: ${{ github.actor }} |
| 110 | + password: ${{ github.token }} |
| 111 | + |
| 112 | + - name: Build |
| 113 | + uses: docker/build-push-action@v5 |
| 114 | + with: |
| 115 | + platforms: linux/amd64,linux/arm64/v8 |
| 116 | + push: ${{ github.event_name != 'pull_request' }} |
| 117 | + tags: ${{ steps.meta.outputs.tags }} |
| 118 | + labels: ${{ steps.meta.outputs.labels }} |
| 119 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 120 | + cache-to: type=local,dest=/tmp/.buildx-cache-new |
| 121 | + |
| 122 | + - name: Move cache |
| 123 | + run: | |
| 124 | + rm -rf /tmp/.buildx-cache |
| 125 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments