Skip to content

Commit f0d95b9

Browse files
wphillipmoorewphillipmoore-claude
andauthored
refactor(ci): use shared composite actions for publish and release gates (#333)
Replace inline tag/release, version bump PR, and version divergence gate logic with reusable composite actions from standard-actions. - publish.yml: use tag-and-release and version-bump-pr actions - ci.yml: use version-divergence action for release gates Co-authored-by: wphillipmoore-claude <255925739+wphillipmoore-claude@users.noreply.github.com>
1 parent 41b8ed6 commit f0d95b9

2 files changed

Lines changed: 33 additions & 147 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,10 @@ jobs:
108108

109109
- name: Version divergence gate (PRs targeting develop)
110110
if: github.event_name == 'pull_request' && github.base_ref == 'develop'
111-
run: |
112-
git fetch origin main --depth=1
113-
main_version=$(python3 -c "
114-
import tomllib, subprocess
115-
text = subprocess.run(
116-
['git', 'show', 'origin/main:pyproject.toml'],
117-
capture_output=True, text=True, check=True
118-
).stdout
119-
print(tomllib.loads(text)['project']['version'])
120-
")
121-
head_version=$(python3 -c "
122-
import tomllib
123-
from pathlib import Path
124-
print(tomllib.loads(Path('pyproject.toml').read_text())['project']['version'])
125-
")
126-
if [ "$main_version" = "$head_version" ]; then
127-
echo "FAIL: PR version ($head_version) must differ from main ($main_version)."
128-
exit 1
129-
fi
130-
echo "OK: PR version ($head_version) differs from main ($main_version)."
111+
uses: wphillipmoore/standard-actions/actions/release-gates/version-divergence@develop
112+
with:
113+
head-version-command: python3 -c "import tomllib; from pathlib import Path; print(tomllib.loads(Path('pyproject.toml').read_text())['project']['version'])"
114+
main-version-command: git show origin/main:pyproject.toml | python3 -c "import sys, tomllib; print(tomllib.loads(sys.stdin.read())['project']['version'])"
131115

132116
test-and-validate:
133117
name: test-and-validate

.github/workflows/publish.yml

Lines changed: 29 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -91,142 +91,44 @@ jobs:
9191
scan-type: sbom
9292
output-file: dist/pymqrest-${{ steps.version.outputs.version }}.cdx.json
9393

94-
- name: Configure git identity
94+
- name: Tag and release
9595
if: steps.tag_check.outputs.exists == 'false'
96-
run: |
97-
git config user.name "github-actions[bot]"
98-
git config user.email "github-actions[bot]@users.noreply.github.com"
99-
100-
- name: Create git tag
101-
if: steps.tag_check.outputs.exists == 'false'
102-
run: |
103-
git tag -a "${{ steps.version.outputs.tag }}" \
104-
-m "Release ${{ steps.version.outputs.version }}"
105-
git push origin "${{ steps.version.outputs.tag }}"
106-
107-
- name: Tag develop for changelog boundaries
108-
if: steps.tag_check.outputs.exists == 'false'
109-
run: |
110-
git fetch origin develop
111-
git tag "develop-${{ steps.version.outputs.tag }}" origin/develop
112-
git push origin "develop-${{ steps.version.outputs.tag }}"
113-
114-
- name: Create GitHub Release
115-
if: steps.tag_check.outputs.exists == 'false'
116-
env:
117-
GH_TOKEN: ${{ github.token }}
118-
run: |
119-
gh release create "${{ steps.version.outputs.tag }}" \
120-
--title "pymqrest ${{ steps.version.outputs.version }}" \
121-
--notes "$(cat <<'EOF'
122-
## Installation
96+
uses: wphillipmoore/standard-actions/actions/publish/tag-and-release@develop
97+
with:
98+
version: ${{ steps.version.outputs.version }}
99+
release-title: pymqrest
100+
release-notes: |
101+
## Installation
123102
124-
```bash
125-
pip install pymqrest==${{ steps.version.outputs.version }}
126-
```
103+
```bash
104+
pip install pymqrest==${{ steps.version.outputs.version }}
105+
```
127106
128-
## Links
107+
## Links
129108
130-
- [PyPI](https://pypi.org/project/pymqrest/${{ steps.version.outputs.version }}/)
131-
- [Documentation](https://wphillipmoore.github.io/mq-rest-admin-python/)
132-
EOF
133-
)" \
134-
dist/*
135-
136-
- name: Compute next patch version
137-
id: next_version
138-
run: |
139-
next=$(python3 -c "
140-
v = '${{ steps.version.outputs.version }}'.split('.')
141-
v[2] = str(int(v[2]) + 1)
142-
print('.'.join(v))
143-
")
144-
echo "version=$next" >> "$GITHUB_OUTPUT"
145-
echo "branch=chore/bump-version-$next" >> "$GITHUB_OUTPUT"
146-
147-
- name: Check if develop already has next version
148-
id: bump_check
149-
run: |
150-
git fetch origin develop
151-
current=$(git show origin/develop:pyproject.toml | python3 -c "
152-
import sys, tomllib
153-
print(tomllib.loads(sys.stdin.read())['project']['version'])
154-
")
155-
if [ "$current" = "${{ steps.next_version.outputs.version }}" ]; then
156-
echo "needed=false" >> "$GITHUB_OUTPUT"
157-
else
158-
echo "needed=true" >> "$GITHUB_OUTPUT"
159-
fi
109+
- [PyPI](https://pypi.org/project/pymqrest/${{ steps.version.outputs.version }}/)
110+
- [Documentation](https://wphillipmoore.github.io/mq-rest-admin-python/)
111+
release-artifacts: dist/*
160112

161113
- name: Generate app token for bump PR
162-
if: steps.bump_check.outputs.needed == 'true'
114+
if: steps.tag_check.outputs.exists == 'false'
163115
id: app-token
164116
uses: actions/create-github-app-token@v1
165117
with:
166118
app-id: ${{ secrets.APP_ID }}
167119
private-key: ${{ secrets.APP_PRIVATE_KEY }}
168120

169-
- name: Create version bump PR
170-
if: steps.bump_check.outputs.needed == 'true'
171-
env:
172-
GH_TOKEN: ${{ steps.app-token.outputs.token }}
173-
run: |
174-
git checkout -b "${{ steps.next_version.outputs.branch }}" origin/develop
175-
git merge origin/main --no-edit
176-
177-
python3 -c "
178-
from pathlib import Path
179-
import re
180-
p = Path('pyproject.toml')
181-
content = p.read_text()
182-
content = re.sub(
183-
r'^(version\s*=\s*\").*(\"\s*)$',
184-
r'\g<1>${{ steps.next_version.outputs.version }}\2',
185-
content,
186-
count=1,
187-
flags=re.MULTILINE,
188-
)
189-
p.write_text(content)
190-
"
191-
192-
uv lock --upgrade
193-
uv export --no-hashes -o requirements.txt
194-
uv export --no-hashes --group dev -o requirements-dev.txt
195-
196-
git add pyproject.toml uv.lock requirements.txt requirements-dev.txt
197-
git commit -m "chore: bump version to ${{ steps.next_version.outputs.version }}"
198-
git push origin "${{ steps.next_version.outputs.branch }}"
199-
200-
pr_url=$(gh pr create \
201-
--base develop \
202-
--head "${{ steps.next_version.outputs.branch }}" \
203-
--title "chore: bump version to ${{ steps.next_version.outputs.version }}" \
204-
--body "Automated patch version bump after publishing ${{ steps.version.outputs.version }}.
205-
206-
This merges \`main\` back into \`develop\` to pick up the changelog and any
207-
other release-branch artifacts, then sets the working version to the next
208-
expected patch release. Change this to a minor or major bump if the next
209-
release warrants it.
210-
211-
Dependencies are refreshed to their latest compatible versions
212-
via \`uv lock --upgrade\`.")
213-
214-
pr_number="${pr_url##*/}"
215-
gh pr edit "$pr_number" --body "Automated patch version bump after publishing ${{ steps.version.outputs.version }}.
216-
217-
This merges \`main\` back into \`develop\` to pick up the changelog and any
218-
other release-branch artifacts, then sets the working version to the next
219-
expected patch release. Change this to a minor or major bump if the next
220-
release warrants it.
221-
222-
Dependencies are refreshed to their latest compatible versions
223-
via \`uv lock --upgrade\`.
224-
225-
Ref #${pr_number}"
226-
227-
gh pr close "$pr_number"
228-
gh pr reopen "$pr_number"
229-
230-
gh pr merge \
231-
--auto --merge --delete-branch \
232-
"${{ steps.next_version.outputs.branch }}"
121+
- name: Version bump PR
122+
if: steps.tag_check.outputs.exists == 'false'
123+
uses: wphillipmoore/standard-actions/actions/publish/version-bump-pr@develop
124+
with:
125+
current-version: ${{ steps.version.outputs.version }}
126+
version-file: pyproject.toml
127+
version-regex: '^(version\s*=\s*\").*(\"\s*)$'
128+
version-replacement: '\g<1>{version}\2'
129+
version-regex-multiline: "true"
130+
develop-version-command: python3 -c "import sys, tomllib; print(tomllib.loads(sys.stdin.read())['project']['version'])"
131+
post-bump-command: uv lock --upgrade && uv export --no-hashes -o requirements.txt && uv export --no-hashes --group dev -o requirements-dev.txt
132+
extra-files: uv.lock requirements.txt requirements-dev.txt
133+
app-token: ${{ steps.app-token.outputs.token }}
134+
pr-body-extra: Dependencies are refreshed to their latest compatible versions via `uv lock --upgrade`.

0 commit comments

Comments
 (0)