diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 8f750f0..1ba27bd 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -5,10 +5,19 @@ ### Overview This workflow builds a Docker image and pushes it to GitHub Container Registry (ghcr.io). -### Trigger -The workflow is manually triggered via `workflow_dispatch`. +### Triggers -### Usage +The workflow is triggered in two ways: + +1. **Automatically**: When a pull request is merged to the `main` branch + - The image is automatically built and tagged as `latest` + - Also includes a SHA-based tag with branch prefix + +2. **Manually**: Via `workflow_dispatch` in the GitHub Actions UI + - Allows specifying a custom tag + - Default tag is `latest` if not specified + +### Manual Usage 1. Go to the "Actions" tab in the GitHub repository 2. Select "Build and Push Docker Image" from the workflows list @@ -17,7 +26,7 @@ The workflow is manually triggered via `workflow_dispatch`. 5. Click "Run workflow" to start the build ### Parameters -- **tag**: Docker image tag (e.g., `v1.0.0`, `latest`, `dev`). Default: `latest` +- **tag**: Docker image tag (e.g., `v1.0.0`, `latest`, `dev`). Default: `latest` (only for manual triggers) ### Features - Multi-platform builds (linux/amd64, linux/arm64) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 837d225..2756f48 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -8,6 +8,11 @@ on: required: false default: 'latest' type: string + pull_request: + types: + - closed + branches: + - main env: REGISTRY: ghcr.io @@ -16,6 +21,8 @@ env: jobs: build-and-push: runs-on: ubuntu-latest + # Only run on workflow_dispatch OR when a PR is merged (not just closed) + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) permissions: contents: read packages: write @@ -42,7 +49,11 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=raw,value=${{ inputs.tag }} + # For workflow_dispatch: use the input tag or default to 'latest' + type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} + # For merged PRs: always tag as 'latest' + type=raw,value=latest,enable=${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true }} + # For all events: add SHA-based tag with branch prefix type=sha,prefix={{branch}}- - name: Build and push Docker image