Skip to content

Commit f010ca9

Browse files
authored
Add a github actions workflow to create a release PR (#1437)
The action runs the existing create_release.py script in a new mode created for github actions. Rather than using local git commands, it uses a public action for creating a PR in the repository. The action can be triggered from the website or via the CLI tool, for example gh workflow run create-release.yml -R emscripten-core/emsdk -F lto-sha=abc123 -F nonlto-sha=234567
1 parent 3eb3e02 commit f010ca9

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

.github/workflows/create-release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Create Release PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
lto-sha:
7+
required: true
8+
type: string
9+
nonlto-sha:
10+
required: true
11+
type: string
12+
13+
jobs:
14+
create-release-pr:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@v4
19+
- name: Run create_release.py
20+
run: python3 scripts/create_release.py ${{ inputs.lto-sha }} ${{ inputs.nonlto-sha }} --action
21+
- name: Create PR
22+
id: cpr
23+
uses: peter-evans/create-pull-request@v6
24+
with:
25+
title: Release ${{ env.RELEASE_VERSION }}
26+
commit-message: Release ${{ env.RELEASE_VERSION }}
27+
delete-branch: true

scripts/create_release.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ def main(args):
3131

3232
new_version = '.'.join(str(part) for part in new_version)
3333
asserts_hash = None
34+
is_github_runner = False
3435
if args:
3536
new_hash = args[0]
3637
if len(args) > 1:
3738
asserts_hash = args[1]
39+
if len(args) > 2 and args[2] == '--action':
40+
is_github_runner = True
3841
else:
3942
new_hash = emsdk.get_emscripten_releases_tot()
4043
print('Creating new release: %s -> %s' % (new_version, new_hash))
@@ -59,16 +62,21 @@ def main(args):
5962

6063
branch_name = 'version_' + new_version
6164

62-
# Create a new git branch
63-
subprocess.check_call(['git', 'checkout', '-b', branch_name, 'origin/main'], cwd=root_dir)
65+
if is_github_runner: # For GitHub Actions workflows
66+
with open(os.environ['GITHUB_ENV'], 'a') as f:
67+
f.write(f'RELEASE_VERSION={new_version}')
68+
else: # Local use
69+
# Create a new git branch
70+
subprocess.check_call(['git', 'checkout', '-b', branch_name, 'origin/main'], cwd=root_dir)
6471

65-
# Create auto-generated changes to the new git branch
66-
subprocess.check_call(['git', 'add', '-u', '.'], cwd=root_dir)
67-
subprocess.check_call(['git', 'commit', '-m', new_version], cwd=root_dir)
68-
print('New release created in branch: `%s`' % branch_name)
72+
# Create auto-generated changes to the new git branch
73+
subprocess.check_call(['git', 'add', '-u', '.'], cwd=root_dir)
74+
subprocess.check_call(['git', 'commit', '-m', new_version], cwd=root_dir)
75+
print('New release created in branch: `%s`' % branch_name)
76+
77+
# Push new branch to origin
78+
subprocess.check_call(['git', 'push', 'origin', branch_name], cwd=root_dir)
6979

70-
# Push new branch to origin
71-
subprocess.check_call(['git', 'push', 'origin', branch_name], cwd=root_dir)
7280
return 0
7381

7482

0 commit comments

Comments
 (0)