Skip to content

Commit 9ca2c1a

Browse files
committed
ci: comment predicted release version on PRs into main
1 parent 508e843 commit 9ca2c1a

1 file changed

Lines changed: 63 additions & 9 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ jobs:
1919
steps:
2020
- name: Check out
2121
uses: actions/checkout@v4
22-
with:
23-
# deep clone incl. tags so hatch-vcs can derive the version
24-
fetch-depth: 0
2522

2623
- uses: actions/cache@v4
2724
with:
@@ -58,9 +55,6 @@ jobs:
5855
steps:
5956
- name: Check out
6057
uses: actions/checkout@v4
61-
with:
62-
# deep clone incl. tags so hatch-vcs can derive the version
63-
fetch-depth: 0
6458

6559
- name: Set up the environment
6660
uses: ./.github/actions/setup-python-env
@@ -85,12 +79,72 @@ jobs:
8579
steps:
8680
- name: Check out
8781
uses: actions/checkout@v4
88-
with:
89-
# deep clone incl. tags so hatch-vcs can derive the version
90-
fetch-depth: 0
9182

9283
- name: Set up the environment
9384
uses: ./.github/actions/setup-python-env
9485

9586
- name: Check if documentation can be built
9687
run: uv run zensical build -s
88+
89+
version-preview:
90+
# Show contributors what a merge would release, based on the conventional
91+
# commits on the branch. Pull requests only; informational.
92+
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
93+
runs-on: ubuntu-latest
94+
permissions:
95+
contents: read
96+
pull-requests: write
97+
steps:
98+
- name: Check out
99+
uses: actions/checkout@v4
100+
with:
101+
fetch-depth: 0 # PSR needs full history + tags to compute the bump
102+
ref: ${{ github.event.pull_request.head.sha }}
103+
104+
- name: Set up the environment
105+
uses: ./.github/actions/setup-python-env
106+
107+
- name: Compute release preview
108+
id: preview
109+
run: |
110+
# PSR only computes a release on the main branch; name the checked-out
111+
# PR head 'main' so the preview reflects what a merge would release.
112+
git checkout -B main >/dev/null 2>&1 || true
113+
current=$(uv version --short 2>/dev/null || echo "unknown")
114+
next=$(uv run semantic-release version --print 2>/dev/null || echo "")
115+
if [ -n "$next" ] && [ "$next" != "$current" ]; then
116+
echo "released=true" >> "$GITHUB_OUTPUT"
117+
else
118+
echo "released=false" >> "$GITHUB_OUTPUT"
119+
fi
120+
echo "current=$current" >> "$GITHUB_OUTPUT"
121+
echo "next=$next" >> "$GITHUB_OUTPUT"
122+
# Stamp the upcoming changelog section locally (no commit/tag/push/build)
123+
# so the preview shows the notes this merge would add.
124+
if [ -n "$next" ] && [ "$next" != "$current" ]; then
125+
uv run semantic-release version --no-commit --no-tag --no-push --no-vcs-release --skip-build >/dev/null 2>&1 || true
126+
fi
127+
{
128+
echo "changelog<<PSR_EOF"
129+
git --no-pager diff HEAD -- CHANGELOG.md | awk '/^\+/ && !/^\+\+\+/ {sub(/^\+/,""); print}' | head -80
130+
echo "PSR_EOF"
131+
} >> "$GITHUB_OUTPUT"
132+
133+
- name: Post release preview comment
134+
uses: marocchino/sticky-pull-request-comment@v2
135+
with:
136+
header: version-preview
137+
message: |
138+
## Release preview
139+
140+
${{ steps.preview.outputs.released == 'true' && format('Merging this PR would release **v{0}** (current: `v{1}`).', steps.preview.outputs.next, steps.preview.outputs.current) || format('No version bump from the current commits (stays at `v{0}`). Use conventional commit types (`feat`, `fix`, ...) to trigger a release.', steps.preview.outputs.current) }}
141+
142+
<details><summary>Changelog preview (truncated)</summary>
143+
144+
```markdown
145+
${{ steps.preview.outputs.changelog }}
146+
```
147+
148+
</details>
149+
150+
<sub>Preview via python-semantic-release and conventional commits.</sub>

0 commit comments

Comments
 (0)