Skip to content

Commit 348a563

Browse files
committed
ref(ci): Open a PR before releasing a new version
1 parent 76839d1 commit 348a563

File tree

3 files changed

+83
-21
lines changed

3 files changed

+83
-21
lines changed

.github/workflows/docker-build.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
description: "Docker image (e.g. docker.io/<org>/<repo>)"
88
type: string
99
required: true
10+
checkout_ref:
11+
description: "Git ref (branch, SHA, or tag) to check out"
12+
type: string
13+
required: false
1014
file:
1115
description: "Path to Dockerfile relative to the repository root"
1216
type: string
@@ -36,7 +40,14 @@ jobs:
3640
name: Build Docker Image
3741
runs-on: ubuntu-latest
3842
steps:
39-
- name: Checkout
43+
- name: Checkout (specific ref)
44+
if: inputs.checkout_ref != ''
45+
uses: actions/checkout@v4
46+
with:
47+
ref: ${{ inputs.checkout_ref }}
48+
49+
- name: Checkout (default)
50+
if: inputs.checkout_ref == ''
4051
uses: actions/checkout@v4
4152

4253
- name: Set up Docker Buildx

.github/workflows/prepare-release.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818

1919
permissions:
2020
contents: write
21+
pull-requests: write
2122

2223
jobs:
2324
prepare-release:
@@ -65,16 +66,20 @@ jobs:
6566
# and prepend it to the existing changelog.
6667
git cliff --config cliff.toml --tag "v${NEXT_VERSION}" --unreleased --prepend CHANGELOG.md
6768
68-
- name: Commit and Tag Release
69-
env:
70-
NEXT_VERSION: ${{ steps.ver.outputs.next }}
71-
run: |
72-
set -euo pipefail
73-
git config user.name "github-actions[bot]"
74-
git config user.email "github-actions[bot]@users.noreply.github.com"
75-
git add .
76-
git commit -m "chore(release): v${NEXT_VERSION}"
77-
git tag -a "v${NEXT_VERSION}" -m "Release v${NEXT_VERSION}"
78-
# Push to main and tags; assume release is performed from main.
79-
git push origin HEAD:main
80-
git push origin --tags
69+
- name: Create Release Pull Request
70+
uses: peter-evans/create-pull-request@v6
71+
with:
72+
commit-message: chore(release): v${{ steps.ver.outputs.next }}
73+
title: chore(release): v${{ steps.ver.outputs.next }}
74+
body: |
75+
This PR prepares release v${{ steps.ver.outputs.next }}.
76+
77+
- Bumps workspace versions.
78+
- Updates CHANGELOG.md with unreleased changes.
79+
80+
Merging this PR into `main` will trigger the release workflow which tags the commit, publishes Docker images, and creates the GitHub Release.
81+
branch: release/v${{ steps.ver.outputs.next }}
82+
base: main
83+
labels: |
84+
release
85+
automated

.github/workflows/release.yml

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ concurrency:
55
cancel-in-progress: false
66

77
on:
8-
push:
9-
tags:
10-
- 'v*'
8+
pull_request:
9+
types: [closed]
10+
branches: [main]
1111
workflow_dispatch:
1212
inputs:
1313
version:
@@ -25,6 +25,7 @@ jobs:
2525
outputs:
2626
tag: ${{ steps.ver.outputs.tag }}
2727
version: ${{ steps.ver.outputs.version }}
28+
is_pr_merge: ${{ steps.ver.outputs.is_pr_merge }}
2829
steps:
2930
- name: Extract Tag and Version
3031
id: ver
@@ -34,9 +35,18 @@ jobs:
3435
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
3536
RAW="${{ inputs.version }}"
3637
TAG="v${RAW#v}"
38+
PR_MERGE=false
3739
else
38-
TAG="${GITHUB_REF_NAME}"
39-
RAW="${TAG#v}"
40+
# pull_request closed event (merged into main)
41+
TITLE="${{ github.event.pull_request.title }}"
42+
if [[ "$TITLE" =~ v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
43+
RAW="${BASH_REMATCH[1]}"
44+
TAG="v${RAW}"
45+
else
46+
echo "Failed to extract version from PR title: $TITLE" >&2
47+
exit 1
48+
fi
49+
PR_MERGE="${{ github.event.pull_request.merged }}"
4050
fi
4151
CLEANED="${RAW#v}"
4252
if [[ ! "$CLEANED" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@@ -45,10 +55,45 @@ jobs:
4555
fi
4656
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
4757
echo "version=${CLEANED}" >> "$GITHUB_OUTPUT"
58+
echo "is_pr_merge=${PR_MERGE}" >> "$GITHUB_OUTPUT"
59+
60+
create-tag:
61+
name: Create Tag
62+
needs: version
63+
if: needs.version.outputs.is_pr_merge == 'true' || github.event_name == 'workflow_dispatch'
64+
runs-on: ubuntu-latest
65+
permissions:
66+
contents: write
67+
steps:
68+
- name: Checkout merge commit (PR merge)
69+
if: github.event_name == 'pull_request'
70+
uses: actions/checkout@v4
71+
with:
72+
ref: ${{ github.event.pull_request.merge_commit_sha }}
73+
74+
- name: Checkout main (manual dispatch)
75+
if: github.event_name == 'workflow_dispatch'
76+
uses: actions/checkout@v4
77+
78+
- name: Create and Push Tag
79+
shell: bash
80+
env:
81+
TAG: ${{ needs.version.outputs.tag }}
82+
run: |
83+
set -euo pipefail
84+
git fetch --tags
85+
if git rev-parse "$TAG" >/dev/null 2>&1; then
86+
echo "Tag $TAG already exists; skipping creation."
87+
exit 0
88+
fi
89+
git config user.name "github-actions[bot]"
90+
git config user.email "github-actions[bot]@users.noreply.github.com"
91+
git tag -a "$TAG" -m "Release $TAG"
92+
git push origin "$TAG"
4893
4994
build-and-push:
5095
name: Build and Push Docker Images
51-
needs: version
96+
needs: [version, create-tag]
5297
strategy:
5398
matrix:
5499
image: [etl-api, etl-replicator]
@@ -60,11 +105,12 @@ jobs:
60105
push: true
61106
tag_with_version: true
62107
version: ${{ needs.version.outputs.version }}
108+
checkout_ref: refs/tags/${{ needs.version.outputs.tag }}
63109
secrets: inherit
64110

65111
github-release:
66112
name: Create GitHub Release
67-
needs: [version, build-and-push]
113+
needs: [version, create-tag, build-and-push]
68114
runs-on: ubuntu-latest
69115
steps:
70116
- name: Generate Release Notes

0 commit comments

Comments
 (0)