diff --git a/.github/changelog-processor.py b/.github/changelog-processor.py new file mode 100755 index 0000000000..b005c620d8 --- /dev/null +++ b/.github/changelog-processor.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import os +import sys +import argparse + +parser = argparse.ArgumentParser(description="Process the CHANGELOG.md") +parser.add_argument( + "changelog", + metavar="CHANGELOG", + help="Path to the CHANGELOG.md file", + default="CHANGELOG.md", + nargs='?' +) + +group = parser.add_mutually_exclusive_group() +group.add_argument( + "--print-latest-version", + dest="print_latest_version", + help="Print the latest version (first in the file) found in the CHANGELOG.md", + action="store_true" +) +group.add_argument( + "--should-release", + dest="should_release", + help="Should a release be made? Prints `1` or `0`.", + action="store_true" +) + +args = parser.parse_args() + +with open(args.changelog, "r") as changelog: + lines = changelog.readlines() + + # Find the latest version + for line in lines: + if not line.startswith("## ["): + continue + + version = line.strip().removeprefix("## [").split("]")[0] + break + + if args.print_latest_version: + print(version, end = "") + sys.exit(0) + elif args.should_release: + if version.lower() == "unreleased": + print("0", end = "") + sys.exit(-1) + elif version.count(".") != 2: + print("0", end = "") + sys.exit(-1) + + stream = os.popen("git tag -l v" + version) + output = stream.read() + + # Empty output means that the tag doesn't exist and that we should release. + if output.strip() == "": + print("1", end = "") + else: + print("0", end = "") + + sys.exit(0) + else: + parser.print_help() diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2b31d3608a..72b361b62e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,21 @@ on: workflow_dispatch: jobs: + collect-release-information: + runs-on: ubuntu-latest + outputs: + should-release: ${{ steps.run.outputs.should-release }} + version: ${{ steps.run.outputs.version }} + steps: + - uses: actions/checkout@v2 + - id: run + run: | + echo "should-release=$(.github/changelog-processor.py CHANGELOG.md --should-release)" >> $GITHUB_OUTPUT + echo "version=$(.github/changelog-processor.py CHANGELOG.md --print-latest-version)" >> $GITHUB_OUTPUT + cat $GITHUB_OUTPUT runtime-matrix: + needs: [ collect-release-information ] + if: needs.collect-release-information.outputs.should-release == '1' runs-on: ubuntu-latest outputs: runtime: ${{ steps.runtime.outputs.runtime }} @@ -66,9 +80,9 @@ jobs: path: | ${{ steps.srtool_build.outputs.wasm_compressed }} - publish-draft-release: + publish-release: runs-on: ubuntu-latest - needs: [ build-runtimes ] + needs: [ build-runtimes, collect-release-information ] outputs: release_url: ${{ steps.create-release.outputs.html_url }} asset_upload_url: ${{ steps.create-release.outputs.upload_url }} @@ -92,7 +106,6 @@ jobs: SRTOOL() { <$(<<<$CONTEXT head -n1) jq -r .$1; } WASM() { <${JSON} jq -r ".runtimes.compressed.subwasm.$1"; } tee -a DRAFT <<-EOF - ## Changelog EOF tee -a DRAFT