build: add semver releases for main docker tags #255
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: Build and Push Multi-Arch Image | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [ main, dev, qbit-session ] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [ main, dev, qbit-session ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| PLATFORMS: linux/amd64,linux/arm64 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| issues: write | |
| packages: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: npm | |
| - name: Install release tooling | |
| if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | |
| run: npm ci | |
| - name: Preview next semantic release | |
| id: release_preview | |
| if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| output="$(npx semantic-release --dry-run --no-ci 2>&1 || true)" | |
| printf '%s\n' "$output" | |
| if printf '%s\n' "$output" | grep -q "There are no relevant changes, so no new version is released."; then | |
| echo "release_needed=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| version="$(printf '%s\n' "$output" | sed -nE 's/.*The next release version is ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' | tail -n 1)" | |
| if [ -z "$version" ]; then | |
| echo "Unable to determine the next release version from semantic-release output." >&2 | |
| exit 1 | |
| fi | |
| echo "release_needed=true" >> "$GITHUB_OUTPUT" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| - name: Prepare automated release tags | |
| id: release_tags | |
| if: steps.release_preview.outputs.release_needed == 'true' | |
| run: | | |
| version="${{ steps.release_preview.outputs.version }}" | |
| major="${version%%.*}" | |
| minor="${version#*.}" | |
| minor="${minor%%.*}" | |
| { | |
| echo "tags<<EOF" | |
| echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${version}" | |
| echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${major}.${minor}" | |
| echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${major}" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to GitHub Container Registry | |
| if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Gather Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} | |
| type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }} | |
| type=raw,value=qbit-session,enable=${{ github.ref == 'refs/heads/qbit-session' }} | |
| type=sha,format=short,enable=${{ startsWith(github.ref, 'refs/heads/') }} | |
| type=ref,event=pr | |
| type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} | |
| type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} | |
| type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: ${{ env.PLATFORMS }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: | | |
| ${{ steps.meta.outputs.tags }} | |
| ${{ steps.release_tags.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| GIT_COMMIT=${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Create semantic release | |
| if: steps.release_preview.outputs.release_needed == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: npx semantic-release |