Docker #7
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: | |
| # Automatically run after the Release workflow completes successfully. | |
| # (Events created by GITHUB_TOKEN don't trigger "release: published" in | |
| # other workflows, so we use workflow_run instead.) | |
| workflow_run: | |
| workflows: ["Release"] | |
| types: [completed] | |
| # Manual trigger with an explicit tag. | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Tag to build (e.g., v1.0.0)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| docker: | |
| name: Build and Push Docker Image | |
| runs-on: ubuntu-latest | |
| # Only run if the Release workflow succeeded (skip on failure/cancelled), | |
| # or if this was triggered manually. | |
| if: >- | |
| github.event_name == 'workflow_dispatch' || | |
| github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine tag | |
| id: get_tag | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| TAG="${{ inputs.tag }}" | |
| else | |
| # workflow_run: find the latest semver tag pointing at HEAD | |
| TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| fi | |
| if [ -z "$TAG" ]; then | |
| echo "::error::Could not determine release tag" | |
| exit 1 | |
| fi | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "Using tag: $TAG" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ghcr.io/didstopia/githubby | |
| tags: | | |
| type=semver,pattern={{version}},value=${{ steps.get_tag.outputs.tag }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ steps.get_tag.outputs.tag }} | |
| type=semver,pattern={{major}},value=${{ steps.get_tag.outputs.tag }} | |
| type=raw,value=latest | |
| - name: Build and push | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ steps.get_tag.outputs.tag }} | |
| COMMIT=${{ github.sha }} | |
| BUILD_DATE=${{ github.event.repository.updated_at }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |