Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve release process #63

Merged
merged 12 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/changelog-processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/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='?'
)
parser.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"
)
parser.add_argument(
"--should-release",
dest="should_release",
help="Should a release be made? Prints `1` or `0`.",
action="store_true"
)

args = parser.parse_args()

ggwpez marked this conversation as resolved.
Show resolved Hide resolved
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(1)
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
bkchr marked this conversation as resolved.
Show resolved Hide resolved
elif args.should_release:
if version.lower() == "unreleased":
print("0", end = "")
sys.exit(1)
bkchr marked this conversation as resolved.
Show resolved Hide resolved
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(1)
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
bkchr marked this conversation as resolved.
Show resolved Hide resolved
else:
parser.print_help()
29 changes: 21 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 <CHANGELOG.md
tee -a DRAFT <<-EOF
Expand All @@ -115,19 +128,19 @@ jobs:
EOF
done

- name: Create draft release
- name: Create release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Runtimes ${{ github.sha }}
tag_name: ${{ format('v{0}', needs.collect-release-information.outputs.version) }}
release_name: Runtimes ${{ needs.collect-release-information.outputs.version }}
body_path: DRAFT
draft: true
draft: false

publish-runtimes:
needs: [ runtime-matrix, publish-draft-release ]
needs: [ runtime-matrix, publish-release ]
continue-on-error: true
runs-on: ubuntu-latest
env:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

Changelog for the runtimes governed by the Polkadot Fellowship.

## [1.0.0]
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Changed

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ To use it, write a comment in a PR that says:
This will enable [`auto-merge`](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/automatically-merging-a-pull-request) in the Pull Request (or merge it if it is ready to merge).

The automation can be triggered by the author of the PR or any fellow whose GitHub handle is part of their identity.

# Release process

Releases are automatically pushed on commits merged to master that fulfill the following requirements:

- The [`CHANGELOG.md`](CHANGELOG.md) file was modified.
- The latest version (the version at the top of the file) in [`CHANGELOG.md`](CHANGELOG.md) has no tag in the repository.

The release process is building all runtimes and then puts them into a release in this github repository.

The format of [`CHANGELOG.md`](CHANGELOG.md) is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
Loading