| 1 |
name: Release |
| 2 |
# On a merged `release`-labelled PR: tag the merge commit with the version from |
| 3 |
# the top of CHANGELOG.md, build on the tag, and create a draft GitHub Release |
| 4 |
# with the archives attached. A maintainer publishes the draft by hand. |
| 5 |
on: |
| 6 |
pull_request: |
| 7 |
types: [closed] |
| 8 |
workflow_dispatch: |
| 9 |
jobs: |
| 10 |
prepare: |
| 11 |
name: Prepare tag |
| 12 |
if: >- |
| 13 |
github.repository == 'libmbd/libmbd' && |
| 14 |
(github.event_name == 'workflow_dispatch' || |
| 15 |
(github.event.pull_request.merged == true && |
| 16 |
contains(github.event.pull_request.labels.*.name, 'release'))) |
| 17 |
runs-on: ubuntu-latest |
| 18 |
permissions: |
| 19 |
contents: write |
| 20 |
outputs: |
| 21 |
version: ${{ steps.version.outputs.version }} |
| 22 |
tag: ${{ steps.version.outputs.version }} |
| 23 |
steps: |
| 24 |
- uses: actions/checkout@v6 |
| 25 |
with: |
| 26 |
# The exact merge commit, not the ephemeral refs/pull/N/merge ref. |
| 27 |
ref: ${{ github.event.pull_request.merge_commit_sha || github.ref }} |
| 28 |
fetch-depth: 0 |
| 29 |
- name: Read version from changelog |
| 30 |
id: version |
| 31 |
run: echo "version=$(bash devtools/changelog.sh version)" >>"$GITHUB_OUTPUT" |
| 32 |
- name: Extract release notes |
| 33 |
run: bash devtools/changelog.sh notes "${{ steps.version.outputs.version }}" >release-notes.md |
| 34 |
# A merge must not reuse an existing tag; workflow_dispatch may, to resume. |
| 35 |
- name: Guard against re-releasing an existing tag |
| 36 |
if: github.event_name == 'pull_request' |
| 37 |
run: | |
| 38 |
tag="${{ steps.version.outputs.version }}" |
| 39 |
if git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null 2>&1; then |
| 40 |
echo "::error::Tag $tag already exists. Add a new '## [X.Y.Z]' section to CHANGELOG.md before releasing." >&2 |
| 41 |
exit 1 |
| 42 |
fi |
| 43 |
- name: Create and push tag |
| 44 |
run: | |
| 45 |
tag="${{ steps.version.outputs.version }}" |
| 46 |
if git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null 2>&1; then |
| 47 |
echo "Tag $tag already exists; reusing it." |
| 48 |
else |
| 49 |
git tag "$tag" |
| 50 |
git push origin "refs/tags/$tag" |
| 51 |
fi |
| 52 |
- name: Upload release notes |
| 53 |
uses: actions/upload-artifact@v4 |
| 54 |
with: |
| 55 |
name: release-notes |
| 56 |
path: release-notes.md |
| 57 |
build: |
| 58 |
name: Build |
| 59 |
needs: prepare |
| 60 |
permissions: |
| 61 |
contents: read |
| 62 |
uses: ./.github/workflows/build-dist.yaml |
| 63 |
with: |
| 64 |
ref: ${{ needs.prepare.outputs.tag }} |
| 65 |
draft: |
| 66 |
name: Create draft GitHub Release |
| 67 |
needs: [prepare, build] |
| 68 |
runs-on: ubuntu-latest |
| 69 |
permissions: |
| 70 |
contents: write |
| 71 |
steps: |
| 72 |
- name: Download pyMBD sdist |
| 73 |
uses: actions/download-artifact@v4 |
| 74 |
with: |
| 75 |
name: pymbd-sdist |
| 76 |
path: dist |
| 77 |
- name: Download libMBD source archive |
| 78 |
uses: actions/download-artifact@v4 |
| 79 |
with: |
| 80 |
name: libmbd-sdist |
| 81 |
path: dist |
| 82 |
- name: Download release notes |
| 83 |
uses: actions/download-artifact@v4 |
| 84 |
with: |
| 85 |
name: release-notes |
| 86 |
# Attach both archives to a draft; an existing draft is updated in place. |
| 87 |
- name: Create or update draft GitHub Release |
| 88 |
env: |
| 89 |
GH_TOKEN: ${{ github.token }} |
| 90 |
GH_REPO: ${{ github.repository }} |
| 91 |
TAG: ${{ needs.prepare.outputs.tag }} |
| 92 |
run: | |
| 93 |
if gh release view "$TAG" >/dev/null 2>&1; then |
| 94 |
gh release upload "$TAG" dist/*.tar.gz --clobber |
| 95 |
else |
| 96 |
gh release create "$TAG" \ |
| 97 |
--draft \ |
| 98 |
--title "$TAG" \ |
| 99 |
--notes-file release-notes.md \ |
| 100 |
dist/*.tar.gz |
| 101 |
fi |