Skip to content

Commit 9b346af

Browse files
authored
Merge pull request #60 from mfa777/develop #skip-docker
Use release tags for Docker image publishing and add Docker skip markers
2 parents 999efa1 + 8a68885 commit 9b346af

3 files changed

Lines changed: 55 additions & 12 deletions

File tree

.github/workflows/build-and-push.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
name: Build and push Docker images
22

33
on:
4-
push:
5-
branches: [ 'master' ]
4+
workflow_call:
5+
inputs:
6+
release_tag:
7+
description: Generated release tag used for Docker image tags
8+
required: true
9+
type: string
10+
source_ref:
11+
description: Commit SHA or ref to build from
12+
required: true
13+
type: string
14+
skip_docker:
15+
description: Skip Docker image build and push when true
16+
required: false
17+
default: false
18+
type: boolean
619

720
jobs:
821
build-and-push:
22+
if: ${{ !inputs.skip_docker }}
923
runs-on: ubuntu-latest
1024
permissions:
1125
contents: read
1226

1327
steps:
1428
- name: Checkout repo
1529
uses: actions/checkout@v4
30+
with:
31+
ref: ${{ inputs.source_ref }}
1632

1733
- name: Set up QEMU
1834
uses: docker/setup-qemu-action@v3
@@ -35,7 +51,7 @@ jobs:
3551
push: true
3652
tags: |
3753
${{ secrets.DOCKERHUB_USERNAME }}/pg-with-backup:latest
38-
${{ secrets.DOCKERHUB_USERNAME }}/pg-with-backup:${{ github.sha }}
54+
${{ secrets.DOCKERHUB_USERNAME }}/pg-with-backup:${{ inputs.release_tag }}
3955
cache-from: type=gha
4056
cache-to: type=gha,mode=max
4157

@@ -47,6 +63,6 @@ jobs:
4763
push: true
4864
tags: |
4965
${{ secrets.DOCKERHUB_USERNAME }}/pg-backup-walg:latest
50-
${{ secrets.DOCKERHUB_USERNAME }}/pg-backup-walg:${{ github.sha }}
66+
${{ secrets.DOCKERHUB_USERNAME }}/pg-backup-walg:${{ inputs.release_tag }}
5167
cache-from: type=gha
5268
cache-to: type=gha,mode=max

.github/workflows/release-on-master-merge.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
outputs:
1616
release_tag: ${{ steps.tag_version.outputs.new_tag }}
17+
skip_docker: ${{ steps.docker_policy.outputs.skip_docker }}
1718

1819
steps:
1920
- name: Checkout merged master commit
@@ -22,6 +23,17 @@ jobs:
2223
ref: ${{ github.event.pull_request.merge_commit_sha }}
2324
fetch-depth: 0
2425

26+
- name: Detect docker publish policy
27+
id: docker_policy
28+
run: |
29+
commit_message="$(git log -1 --pretty=%B)"
30+
if grep -Eq '(#skip-docker|:noimage)' <<<"$commit_message"; then
31+
echo "skip_docker=true" >> "$GITHUB_OUTPUT"
32+
echo "Docker image publishing disabled for this release via #skip-docker / :noimage."
33+
else
34+
echo "skip_docker=false" >> "$GITHUB_OUTPUT"
35+
fi
36+
2537
- name: Create semantic version tag
2638
id: tag_version
2739
uses: anothrNick/github-tag-action@1.75.0
@@ -34,9 +46,21 @@ jobs:
3446
TAG_PREFIX: v
3547
INITIAL_VERSION: 2.3.0
3648

37-
publish-github-release:
49+
build-and-push-images:
3850
needs: create-semver-tag
3951
if: needs.create-semver-tag.outputs.release_tag != ''
52+
uses: ./.github/workflows/build-and-push.yml
53+
with:
54+
release_tag: ${{ needs.create-semver-tag.outputs.release_tag }}
55+
source_ref: ${{ github.event.pull_request.merge_commit_sha }}
56+
skip_docker: ${{ needs.create-semver-tag.outputs.skip_docker == 'true' }}
57+
secrets: inherit
58+
59+
publish-github-release:
60+
needs:
61+
- create-semver-tag
62+
- build-and-push-images
63+
if: needs.create-semver-tag.outputs.release_tag != '' && (needs.build-and-push-images.result == 'success' || needs.build-and-push-images.result == 'skipped')
4064
runs-on: ubuntu-latest
4165
permissions:
4266
contents: write
@@ -53,6 +77,7 @@ jobs:
5377
echo "Commit: ${{ github.event.pull_request.merge_commit_sha }}"
5478
echo "Merged PR: #${{ github.event.pull_request.number }}"
5579
echo "Merged by: ${{ github.event.pull_request.merged_by.login }}"
80+
echo "Docker images: ${{ needs.create-semver-tag.outputs.skip_docker == 'true' && 'skipped (#skip-docker / :noimage)' || 'published' }}"
5681
} > "$release_asset"
5782
echo "release_asset=$release_asset" >> "$GITHUB_OUTPUT"
5883

docs/BUILD_AND_PUSH.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
This repository contains GitHub Actions workflows that:
44

5-
- build and push Docker images to Docker Hub when commits are pushed to the `master` branch
6-
- create a semantic version tag and publish a GitHub Release when a pull request is merged into `master`
5+
- create a semantic version tag when a pull request is merged into `master`
6+
- build and push Docker images to Docker Hub using that generated release tag
7+
- publish a GitHub Release for the generated tag
78

89
## What the workflow does
9-
- On push to `master`, it builds two images:
10-
- `Dockerfile.postgres-walg``DOCKERHUB_USERNAME/pg-with-backup` (tags: `latest`, `commit-sha`)
11-
- `Dockerfile.backup``DOCKERHUB_USERNAME/pg-backup-walg` (tags: `latest`, `commit-sha`)
12-
- Pushes the images to Docker Hub using the provided credentials.
1310
- On merged pull requests to `master`, it:
1411
- calculates the next semantic version tag from the latest repository tag (current baseline: `v2.3.0`)
1512
- defaults to a patch bump, unless the merge commit message includes `#major`, `#minor`, `#patch`, or `#none`
13+
- skips Docker image build/push when the merge commit message includes `#skip-docker` (`:noimage`)
1614
- creates the new Git tag with `anothrNick/github-tag-action`
15+
- builds two images and pushes them to Docker Hub with tags `latest` and the generated semantic version tag:
16+
- `Dockerfile.postgres-walg``DOCKERHUB_USERNAME/pg-with-backup`
17+
- `Dockerfile.backup``DOCKERHUB_USERNAME/pg-backup-walg`
1718
- publishes a GitHub Release with autogenerated release notes and a small metadata asset
1819

1920
## Required GitHub repository secrets
@@ -55,8 +56,9 @@ Notes:
5556

5657
## Customizing image names/tags
5758
- The workflow uses `${{ secrets.DOCKERHUB_USERNAME }}` as the user/org for image tags. If you prefer different names, update `.github/workflows/build-and-push.yml`.
58-
- The release workflow lives in `.github/workflows/release-on-master-merge.yml`.
59+
- The release workflow lives in `.github/workflows/release-on-master-merge.yml` and calls `.github/workflows/build-and-push.yml` as a reusable workflow.
5960
- To change default semantic bump behavior, update `DEFAULT_BUMP` in the release workflow.
61+
- To change the Docker skip marker, update the `#skip-docker` check in the release workflow.
6062
- To start release numbering from a different baseline when there are no tags yet, update `INITIAL_VERSION` in the release workflow.
6163

6264
## Troubleshooting

0 commit comments

Comments
 (0)