|
| 1 | +name: Sandbox (Rust) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - packages/sandbox/** |
| 8 | + - .github/workflows/sandbox.yml |
| 9 | + pull_request: |
| 10 | + paths: |
| 11 | + - packages/sandbox/** |
| 12 | + - .github/workflows/sandbox.yml |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +env: |
| 16 | + REGISTRY: ghcr.io |
| 17 | + IMAGE_NAME: ${{ github.repository }}-sandbox |
| 18 | + |
| 19 | +jobs: |
| 20 | + rust-checks: |
| 21 | + name: Rust checks |
| 22 | + runs-on: ubuntu-24.04 |
| 23 | + env: |
| 24 | + CARGO_TERM_COLOR: always |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Setup Rust |
| 30 | + uses: dtolnay/rust-toolchain@stable |
| 31 | + with: |
| 32 | + components: clippy, rustfmt |
| 33 | + |
| 34 | + - name: Cache cargo registry + build |
| 35 | + uses: Swatinem/rust-cache@v2 |
| 36 | + with: |
| 37 | + workspaces: packages/sandbox |
| 38 | + |
| 39 | + - name: Format |
| 40 | + run: cargo fmt --all -- --check |
| 41 | + working-directory: packages/sandbox |
| 42 | + |
| 43 | + - name: Clippy |
| 44 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 45 | + working-directory: packages/sandbox |
| 46 | + |
| 47 | + - name: Tests |
| 48 | + run: cargo test --all-features --locked |
| 49 | + working-directory: packages/sandbox |
| 50 | + |
| 51 | + docker-build: |
| 52 | + name: Build Docker image (${{ matrix.platform }}) |
| 53 | + runs-on: ${{ matrix.runner }} |
| 54 | + needs: rust-checks |
| 55 | + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' |
| 56 | + permissions: |
| 57 | + contents: read |
| 58 | + packages: write |
| 59 | + strategy: |
| 60 | + fail-fast: false |
| 61 | + matrix: |
| 62 | + include: |
| 63 | + - platform: linux/amd64 |
| 64 | + runner: ubuntu-24.04 |
| 65 | + - platform: linux/arm64 |
| 66 | + runner: ubuntu-24.04-arm |
| 67 | + |
| 68 | + steps: |
| 69 | + - name: Checkout |
| 70 | + uses: actions/checkout@v4 |
| 71 | + |
| 72 | + - name: Set up QEMU |
| 73 | + uses: docker/setup-qemu-action@v3 |
| 74 | + |
| 75 | + - name: Set up Docker Buildx |
| 76 | + uses: docker/setup-buildx-action@v3 |
| 77 | + |
| 78 | + - name: Log in to GHCR |
| 79 | + uses: docker/login-action@v3 |
| 80 | + with: |
| 81 | + registry: ${{ env.REGISTRY }} |
| 82 | + username: ${{ github.actor }} |
| 83 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 84 | + |
| 85 | + - name: Extract metadata for Docker |
| 86 | + id: meta |
| 87 | + uses: docker/metadata-action@v5 |
| 88 | + with: |
| 89 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 90 | + tags: | |
| 91 | + type=ref,event=branch |
| 92 | + type=sha,prefix= |
| 93 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} |
| 94 | +
|
| 95 | + - name: Build and push by digest |
| 96 | + id: build |
| 97 | + uses: docker/build-push-action@v6 |
| 98 | + with: |
| 99 | + context: . |
| 100 | + file: packages/sandbox/Dockerfile |
| 101 | + platforms: ${{ matrix.platform }} |
| 102 | + labels: ${{ steps.meta.outputs.labels }} |
| 103 | + cache-from: type=gha,scope=${{ matrix.platform }} |
| 104 | + cache-to: type=gha,mode=max,scope=${{ matrix.platform }} |
| 105 | + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true |
| 106 | + |
| 107 | + - name: Export digest |
| 108 | + run: | |
| 109 | + mkdir -p /tmp/digests |
| 110 | + digest="${{ steps.build.outputs.digest }}" |
| 111 | + touch "/tmp/digests/${digest#sha256:}" |
| 112 | +
|
| 113 | + - name: Upload digest |
| 114 | + uses: actions/upload-artifact@v4 |
| 115 | + with: |
| 116 | + name: digests-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} |
| 117 | + path: /tmp/digests/* |
| 118 | + if-no-files-found: error |
| 119 | + retention-days: 1 |
| 120 | + |
| 121 | + docker-merge: |
| 122 | + name: Create multi-arch manifest |
| 123 | + runs-on: ubuntu-24.04 |
| 124 | + needs: docker-build |
| 125 | + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' |
| 126 | + permissions: |
| 127 | + contents: read |
| 128 | + packages: write |
| 129 | + steps: |
| 130 | + - name: Download digests |
| 131 | + uses: actions/download-artifact@v4 |
| 132 | + with: |
| 133 | + path: /tmp/digests |
| 134 | + pattern: digests-* |
| 135 | + merge-multiple: true |
| 136 | + |
| 137 | + - name: Set up Docker Buildx |
| 138 | + uses: docker/setup-buildx-action@v3 |
| 139 | + |
| 140 | + - name: Log in to GHCR |
| 141 | + uses: docker/login-action@v3 |
| 142 | + with: |
| 143 | + registry: ${{ env.REGISTRY }} |
| 144 | + username: ${{ github.actor }} |
| 145 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + |
| 147 | + - name: Extract metadata for Docker |
| 148 | + id: meta |
| 149 | + uses: docker/metadata-action@v5 |
| 150 | + with: |
| 151 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 152 | + tags: | |
| 153 | + type=ref,event=branch |
| 154 | + type=sha,prefix= |
| 155 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} |
| 156 | +
|
| 157 | + - name: Create manifest list and push |
| 158 | + working-directory: /tmp/digests |
| 159 | + run: | |
| 160 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 161 | + $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) |
| 162 | +
|
| 163 | + - name: Inspect image |
| 164 | + run: | |
| 165 | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} |
0 commit comments