Skip to content

Commit

Permalink
build: automatically extract release note from NEWS upon releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetf committed Jun 15, 2022
1 parent 22e70c5 commit c01257d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# The way this works is a little weird. But basically, the create-release job
# runs purely to initialize the GitHub release itself. Once done, the upload
# URL of the release is saved as an artifact.
#
# The build-release job runs only once create-release is finished. It gets
# the release upload URL by downloading the corresponding artifact (which was
# uploaded by create-release). It then builds the release executables for each
# supported platform and attaches them as release assets to the previously
# created release.
#
# The key here is that we create the release only once.
#
# Adapted from: https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml

name: release
on:
push:
Expand All @@ -36,8 +22,11 @@ jobs:
- name: Create source distribution
# no unit tests yet
run: meson dist -C builddir/ --no-tests
- name: Create release note
run: tools/extract_release_note.py NEWS ${{ github.workspace }}-release-note.txt
- name: Release
uses: softprops/action-gh-release@v1
with:
files: builddir/meson-dist/*
body_path: ${{ github.workspace }}-release-note.txt

47 changes: 47 additions & 0 deletions tools/extract_release_note.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2022 Aetf <aetf@unlimited-code.works>
#
# SPDX-License-Identifier: MIT
import re
import inspect

PTN_RELEASE_NOTE = re.compile(r'^CHANGES WITH.+$([\s\S]+?)^CHANGES WITH.+$', re.MULTILINE)


def extract(src: str) -> str:
"""Find section between the first and the next 'CHANGES WITH xx:' lines,
and strip common prefix whitespace
"""
m = PTN_RELEASE_NOTE.search(src)
if m is not None:
return inspect.cleandoc(m.group(1)) + '\n'
else:
return ''


def main():
import argparse
import sys

parser = argparse.ArgumentParser()
parser.add_argument(
'src',
type=argparse.FileType('r'),
nargs='?',
help='input NEWS',
default=sys.stdin,
)
parser.add_argument(
'dest',
type=argparse.FileType('w'),
nargs='?',
help='output',
default=sys.stdout,
)
args = parser.parse_args()

args.dest.write(extract(args.src.read()))


if __name__ == '__main__':
main()

0 comments on commit c01257d

Please sign in to comment.