Skip to content

Commit 6374178

Browse files
committed
Add workflow to prepare for the next release
include - updating version files - generating release notes
1 parent efc1ad8 commit 6374178

File tree

2 files changed

+86
-17
lines changed

2 files changed

+86
-17
lines changed

.github/scripts/generate_release_notes.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
# get the last release tag from git, and use it to find all merged PRs since
5-
# that tag. extract their titles, labels and PR numbers and classify them into
6-
# break changes, new # features, enhancements, bug fixes, and others based on
7-
# their labels.
5+
# that tag. Since their titles might not following the same format, we use
6+
# gh cli to search merged PR by commit SHA.
7+
#
8+
# Once having those PRs' information, extract their titles, labels and PR
9+
# numbers and classify them into break changes, new features, enhancements,
10+
# bug fixes, and others based on their labels.
811
#
912
# The release version is generated based on the last release tag. The tag
1013
# should be in the format of "WAMR-major.minor.patch", where major, minor,
@@ -56,25 +59,25 @@ def get_last_release_tag():
5659

5760
def get_merged_prs_since(tag):
5861
# Get commits since the last release tag
59-
log_cmd = f'git log {tag}..HEAD --pretty=format:"%s"'
62+
log_cmd = f'git log {tag}..HEAD --pretty=format:"%s %H"'
6063
logs = run_cmd(log_cmd).splitlines()
6164

6265
print(f"Found {len(logs)} merge commits since last tag '{tag}'.")
6366

6467
pr_numbers = []
6568
for line in logs:
66-
# assume the commit message ends with "(#PR_NUMBER)"
67-
if not line.endswith(")"):
68-
continue
69-
70-
# Extract PR number
71-
parts = line.split("(#")
72-
if len(parts) < 2:
73-
continue
74-
75-
# PR_NUMBER) -> PR_NUMBER
76-
pr_num = parts[1][:-1]
77-
pr_numbers.append(pr_num)
69+
_, sha = line.rsplit(" ", 1)
70+
# Use SHA to find merged PRs
71+
pr_cmd = f"gh pr list --search {sha} --state merged --json number,title"
72+
pr_json = run_cmd(pr_cmd)
73+
pr_data = json.loads(pr_json)
74+
75+
for pr in pr_data:
76+
pr_number = pr.get("number")
77+
print(f"Found PR #{pr_number} {pr['title']}")
78+
if pr_number and pr_number not in pr_numbers:
79+
pr_numbers.append(f"{pr_number}")
80+
7881
return pr_numbers
7982

8083

@@ -145,7 +148,7 @@ def format_release_notes(version, sections):
145148
else:
146149
notes.append("")
147150
notes.append("")
148-
return "\n".join(notes)
151+
return "\n".join(notes) + "\n"
149152

150153

151154
def insert_release_notes(notes, RELEASE_NOTES_FILE):

.github/workflows/prepare_release.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
# It includes:
5+
# - add new content into the RELEASE_NOTES.md
6+
# - update the version in build-scripts/version.cmake and core/version.h
7+
#
8+
# The new content is added to the beginning of the RELEASE_NOTES.md file.
9+
# It includes all merged PR titles since the last release(tag).
10+
# Based on every PR's label, it will be categorized into different sections.
11+
#
12+
# The version number is updated to the next version.
13+
# Based on new content in the RELEASE_NOTES.md, it will be determined
14+
# 1. if there is breaking change or new features, the next version will be a minor version
15+
# 2. if there is no breaking change and new features, the next version will be a patch version
16+
#
17+
# At the end, file a PR to update the files.
18+
19+
name: preparation for a release.
20+
21+
on:
22+
workflow_dispatch:
23+
24+
# Cancel any in-flight jobs for the same PR/branch so there's only one active
25+
# at a time
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
cancel-in-progress: true
29+
30+
jobs:
31+
prepare_release:
32+
permissions:
33+
contents: write # update files
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: prepare the release note
39+
id: generate_release_notes
40+
run: |
41+
python3 ./.github/scripts/generate_release_notes.py ./RELEASE_NOTES.md"
42+
43+
- name: extract next version from previous step's output
44+
id: extract_version
45+
run: |
46+
echo "next_version=${{ steps.generate_release_notes.outputs.next_version }}" >> $GITHUB_ENV
47+
48+
- name: update version files
49+
run: |
50+
python3 ./.github/scripts/update_version_files.py ${{ env.next_version }}
51+
52+
- name: file a PR
53+
id: file_pr
54+
uses: peter-evans/create-pull-request@v4
55+
with:
56+
token: ${{ secrets.GITHUB_TOKEN }}
57+
title: "Prepare for the next release"
58+
body: |
59+
This PR prepares for the next release.
60+
It updates the version files and adds new content to the RELEASE_NOTES.md.
61+
commit-message: "prepare for the next release"
62+
branch: prepare-release-${{ github.run_id }}
63+
paths: |
64+
RELEASE_NOTES.md
65+
build-scripts/version.cmake
66+
core/version.h

0 commit comments

Comments
 (0)