|
| 1 | +name: docker |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: "Release tag (e.g. v1.2.3)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +jobs: |
| 15 | + linux: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + env: |
| 20 | + IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/diff-coverage |
| 21 | + ALPINE_VERSION: "3.20" |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + - name: Set version |
| 25 | + run: | |
| 26 | + TAG="${{ inputs.tag }}" |
| 27 | + if [ -z "$TAG" ]; then TAG="$GITHUB_REF_NAME"; fi |
| 28 | + VERSION="${TAG#v}" |
| 29 | + echo "TAG=$TAG" >> "$GITHUB_ENV" |
| 30 | + echo "VERSION=$VERSION" >> "$GITHUB_ENV" |
| 31 | + - name: Wait for release binaries |
| 32 | + env: |
| 33 | + GH_TOKEN: ${{ github.token }} |
| 34 | + run: | |
| 35 | + set -euo pipefail |
| 36 | + for i in {1..60}; do |
| 37 | + assets="$(gh release view "$TAG" --json assets --jq '.assets[].name' || true)" |
| 38 | + if echo "$assets" | grep -q "diff-coverage-$TAG-x86_64-unknown-linux-musl" \ |
| 39 | + && echo "$assets" | grep -q "diff-coverage-$TAG-aarch64-unknown-linux-musl"; then |
| 40 | + exit 0 |
| 41 | + fi |
| 42 | + echo "Waiting for release assets for $TAG..." |
| 43 | + sleep 10 |
| 44 | + done |
| 45 | + echo "Release assets not found for $TAG" |
| 46 | + exit 1 |
| 47 | + - name: Download release binaries |
| 48 | + env: |
| 49 | + GH_TOKEN: ${{ github.token }} |
| 50 | + run: | |
| 51 | + mkdir -p dist |
| 52 | + gh release download "$TAG" --pattern "diff-coverage-$TAG-x86_64-unknown-linux-musl" --dir dist |
| 53 | + gh release download "$TAG" --pattern "diff-coverage-$TAG-aarch64-unknown-linux-musl" --dir dist |
| 54 | + mv "dist/diff-coverage-$TAG-x86_64-unknown-linux-musl" "dist/diff-coverage-amd64" |
| 55 | + mv "dist/diff-coverage-$TAG-aarch64-unknown-linux-musl" "dist/diff-coverage-arm64" |
| 56 | + chmod +x dist/diff-coverage-amd64 dist/diff-coverage-arm64 |
| 57 | + - uses: docker/setup-buildx-action@v3 |
| 58 | + - uses: docker/login-action@v3 |
| 59 | + with: |
| 60 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 61 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 62 | + - name: Docker meta |
| 63 | + id: meta |
| 64 | + uses: docker/metadata-action@v5 |
| 65 | + with: |
| 66 | + images: ${{ env.IMAGE }} |
| 67 | + tags: | |
| 68 | + type=raw,value=latest |
| 69 | + type=semver,pattern={{version}},value=${{ env.VERSION }} |
| 70 | + type=semver,pattern={{major}},value=${{ env.VERSION }} |
| 71 | + type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }} |
| 72 | + type=raw,value=alpine |
| 73 | + type=raw,value=alpine-${{ env.ALPINE_VERSION }} |
| 74 | + type=semver,pattern={{version}},value=${{ env.VERSION }},suffix=-alpine |
| 75 | + type=semver,pattern={{major}},value=${{ env.VERSION }},suffix=-alpine |
| 76 | + type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }},suffix=-alpine |
| 77 | + type=semver,pattern={{version}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }} |
| 78 | + type=semver,pattern={{major}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }} |
| 79 | + type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }} |
| 80 | + - name: Build and push (linux) |
| 81 | + uses: docker/build-push-action@v5 |
| 82 | + with: |
| 83 | + context: . |
| 84 | + file: Dockerfile.release |
| 85 | + platforms: linux/amd64,linux/arm64 |
| 86 | + push: true |
| 87 | + build-args: | |
| 88 | + ALPINE_VERSION=${{ env.ALPINE_VERSION }} |
| 89 | + tags: ${{ steps.meta.outputs.tags }} |
| 90 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments