feat: dockerhub release #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: docker | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Release tag (e.g. v1.2.3)" | |
| required: true | |
| type: string | |
| jobs: | |
| linux: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| env: | |
| IMAGE: ${{ github.repository_owner }}/diff-coverage | |
| ALPINE_VERSION: "3.20" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set version | |
| run: | | |
| TAG="${{ inputs.tag }}" | |
| if [ -z "$TAG" ]; then TAG="$GITHUB_REF_NAME"; fi | |
| VERSION="${TAG#v}" | |
| echo "TAG=$TAG" >> "$GITHUB_ENV" | |
| echo "VERSION=$VERSION" >> "$GITHUB_ENV" | |
| - name: Wait for release binaries | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -euo pipefail | |
| for i in {1..60}; do | |
| assets="$(gh release view "$TAG" --json assets --jq '.assets[].name' || true)" | |
| if echo "$assets" | grep -q "diff-coverage-$TAG-x86_64-unknown-linux-musl" \ | |
| && echo "$assets" | grep -q "diff-coverage-$TAG-aarch64-unknown-linux-musl"; then | |
| exit 0 | |
| fi | |
| echo "Waiting for release assets for $TAG..." | |
| sleep 10 | |
| done | |
| echo "Release assets not found for $TAG" | |
| exit 1 | |
| - name: Download release binaries | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| mkdir -p dist | |
| gh release download "$TAG" --pattern "diff-coverage-$TAG-x86_64-unknown-linux-musl" --dir dist | |
| gh release download "$TAG" --pattern "diff-coverage-$TAG-aarch64-unknown-linux-musl" --dir dist | |
| mv "dist/diff-coverage-$TAG-x86_64-unknown-linux-musl" "dist/diff-coverage-x86_64-unknown-linux-musl" | |
| mv "dist/diff-coverage-$TAG-aarch64-unknown-linux-musl" "dist/diff-coverage-aarch64-unknown-linux-musl" | |
| chmod +x dist/diff-coverage-x86_64-unknown-linux-musl dist/diff-coverage-aarch64-unknown-linux-musl | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/login-action@v3 | |
| with: | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE }} | |
| tags: | | |
| type=raw,value=latest | |
| type=semver,pattern={{version}},value=${{ env.VERSION }} | |
| type=semver,pattern={{major}},value=${{ env.VERSION }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }} | |
| type=raw,value=alpine | |
| type=raw,value=alpine-${{ env.ALPINE_VERSION }} | |
| type=semver,pattern={{version}},value=${{ env.VERSION }},suffix=-alpine | |
| type=semver,pattern={{major}},value=${{ env.VERSION }},suffix=-alpine | |
| type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }},suffix=-alpine | |
| type=semver,pattern={{version}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }} | |
| type=semver,pattern={{major}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }} | |
| - name: Build and push (linux) | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile.release | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| build-args: | | |
| ALPINE_VERSION=${{ env.ALPINE_VERSION }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} |