-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): Auto-create Github Releases
Fixes #303
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: post-release | ||
on: | ||
push: | ||
tags: | ||
- "v*" | ||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
create-release: | ||
permissions: | ||
contents: write # for actions/create-release to create a release | ||
name: create-release | ||
runs-on: ubuntu-latest | ||
outputs: | ||
upload_url: ${{ steps.release.outputs.upload_url }} | ||
release_version: ${{ env.RELEASE_VERSION }} | ||
steps: | ||
- name: Get the release version from the tag | ||
shell: bash | ||
if: env.RELEASE_VERSION == '' | ||
run: | | ||
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 | ||
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | ||
echo "version is: ${{ env.RELEASE_VERSION }}" | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
- name: Generate Release Notes | ||
run: | | ||
./.github/workflows/release-notes.py --tag ${{ env.RELEASE_VERSION }} --output notes-${{ env.RELEASE_VERSION }}.md | ||
cat notes-${{ env.RELEASE_VERSION }}.md | ||
- name: Create GitHub release | ||
id: release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ env.RELEASE_VERSION }} | ||
release_name: ${{ env.RELEASE_VERSION }} | ||
body_path: notes-${{ env.RELEASE_VERSION }}.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import re | ||
import pathlib | ||
import sys | ||
|
||
|
||
_STDIO = pathlib.Path("-") | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-i", "--input", type=pathlib.Path, default="CHANGELOG.md") | ||
parser.add_argument("--tag", required=True) | ||
parser.add_argument("-o", "--output", type=pathlib.Path, required=True) | ||
args = parser.parse_args() | ||
|
||
if args.input == _STDIO: | ||
lines = sys.stdin.readlines() | ||
else: | ||
with args.input.open() as fh: | ||
lines = fh.readlines() | ||
version = args.tag.lstrip("v") | ||
|
||
note_lines = [] | ||
for line in lines: | ||
if line.startswith("## ") and version in line: | ||
note_lines.append(line) | ||
elif note_lines and line.startswith("## "): | ||
break | ||
elif note_lines: | ||
note_lines.append(line) | ||
|
||
notes = "".join(note_lines).strip() | ||
if args.output == _STDIO: | ||
print(notes) | ||
else: | ||
args.output.write_text(notes) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |