Skip to content

Commit 122b38f

Browse files
authored
Automatically dispatch emscripten release tag action (#1442)
This PR add several features to release automation: 1. The existing tag-release job has an output that indicates whether the triggering commit is a release (i.e. whether it matches the regex) 2. The new followup job runs a new script which fetches the recent emscripten-releases revisions, reads the DEPS file from the 'latest' release in emscripten-releases-tags.json to find the corresponding emscripten revision and writes it into the environment 2. The final step reads the emscripten revision from the environment and creates a workflow_dispatch event to run the tag-release.yml job on the emscripten repo
1 parent d09b3c3 commit 122b38f

File tree

3 files changed

+115
-28
lines changed

3 files changed

+115
-28
lines changed

.github/workflows/create-release.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,10 @@ jobs:
2323
uses: peter-evans/create-pull-request@v6
2424
with:
2525
title: Release ${{ env.RELEASE_VERSION }}
26-
commit-message: Release ${{ env.RELEASE_VERSION }}
26+
commit-message: |
27+
Release ${{ env.RELEASE_VERSION }}
28+
body: |
29+
With emscripten-releases revisions:
30+
https://chromium.googlesource.com/emscripten-releases/+/${{ inputs.lto-sha }} (LTO)
31+
https://chromium.googlesource.com/emscripten-releases/+/${{ inputs.nonlto-sha }} (asserts)
2732
delete-branch: true

.github/workflows/tag-release.yml

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,74 @@ name: Create release tag
44

55
on:
66
push:
7-
paths: [ emscripten-releases-tags.json, .github/workflows/tag-release.yml ]
7+
paths:
8+
- emscripten-releases-tags.json
9+
- .github/workflows/tag-release.yml
10+
branches:
11+
- main
812
workflow_dispatch:
913

1014
jobs:
11-
tag-release:
12-
# Only activate for commits created by the create-release.yml workflow.
13-
# The assumption is that when manual changes happen, we want to handle
14-
# tagging manually too.
15-
if: github.event.head_commit.author.username == 'github-actions[bot]'
16-
runs-on: ubuntu-latest
17-
steps:
18-
- name: Match message and create tag
19-
uses: actions/github-script@v7
20-
with:
21-
script: |
22-
const message = `${{ github.event.head_commit.message }}`
23-
const regex = /Release ([0-9]+.[0-9]+.[0-9]+)/
24-
const match = message.match(regex)
25-
if (match) {
26-
const release = match[1]
27-
console.log(`Matched release ${release}`)
28-
await github.rest.git.createRef({
29-
owner: context.repo.owner,
30-
repo: context.repo.repo,
31-
ref: `refs/tags/${release}`,
32-
sha: context.sha
33-
})
34-
} else {
35-
console.log(`Commit message: ${message} did not match pattern`)
36-
}
15+
tag-release:
16+
# Only activate for commits created by the create-release.yml workflow.
17+
# The assumption is that when manual changes happen, we want to handle
18+
# tagging manually too.
19+
name: Check for release commit and create tag
20+
if: github.event.head_commit.author.username == 'github-actions[bot]'
21+
runs-on: ubuntu-latest
22+
outputs:
23+
is_release: ${{ steps.create-tag.outputs.result }}
24+
steps:
25+
- name: Match message and create tag
26+
id: create-tag
27+
uses: actions/github-script@v7
28+
with:
29+
github-token: ${{ secrets.TEST_TOKEN }}
30+
# A commit with the message of the form 'Release X.Y.Z' is expected
31+
# to have been created by create_release.py and update the latest
32+
# release in emscripten-releases-tags.json
33+
script: |
34+
const message = `${{ github.event.head_commit.message }}`
35+
const regex = /Release ([0-9]+.[0-9]+.[0-9]+)/;
36+
const match = message.match(regex);
37+
let is_release = false;
38+
if (match) {
39+
const release = match[1];
40+
console.log(`Matched release ${release}`);
41+
await github.rest.git.createRef({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
ref: `refs/tags/${release}`,
45+
sha: context.sha
46+
});
47+
is_release = true;
48+
} else {
49+
console.log(`Commit message: '${message}' did not match pattern`);
50+
}
51+
return is_release;
52+
53+
dispatch-emscripten-tag:
54+
name: Dispatch workflow to tag emscripten repo
55+
runs-on: ubuntu-latest
56+
needs: tag-release
57+
if: ${{ needs.tag-release.outputs.is_release == 'true' }}
58+
steps:
59+
- name: Checkout repo
60+
uses: actions/checkout@v4
61+
- name: Find emscripten revision
62+
# get_emscripten_revision_info.py sets env.EMSCRIPTEN_HASH to the
63+
# emscripten hash associated with the latest release in
64+
# emscripten-releases-tags.json
65+
run: python3 scripts/get_emscripten_revision_info.py
66+
- name: Dispatch emscripten workflow
67+
uses: actions/github-script@v7
68+
with:
69+
github-token: ${{ secrets.TEST_TOKEN }}
70+
script: |
71+
await github.rest.actions.createWorkflowDispatch({
72+
owner: context.repo.owner,
73+
repo: 'emscripten',
74+
workflow_id: 'tag-release.yml',
75+
ref: 'main',
76+
inputs: { 'release-sha': '${{ env.EMSCRIPTEN_HASH }}' }
77+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import os
5+
import subprocess
6+
import sys
7+
8+
EMSCRIPTEN_RELEASES_GIT = 'https://chromium.googlesource.com/emscripten-releases'
9+
TAGFILE = 'emscripten-releases-tags.json'
10+
11+
def get_latest_hash(tagfile):
12+
with open(tagfile) as f:
13+
versions = json.load(f)
14+
latest = versions['aliases']['latest']
15+
return versions['releases'][latest]
16+
17+
def get_latest_emscripten(tagfile):
18+
latest = get_latest_hash(tagfile)
19+
if not os.path.isdir('emscripten-releases'):
20+
subprocess.run(['git', 'clone', EMSCRIPTEN_RELEASES_GIT, '--depth',
21+
'100'], check=True)
22+
# This will fail if the 'latest' revision is not within the most recent
23+
# 100 commits; but that shouldn't happen because this script is intended
24+
# to be run right after a release is added.
25+
info = subprocess.run(['emscripten-releases/src/release-info.py',
26+
'emscripten-releases', latest],
27+
stdout=subprocess.PIPE, check=True, text=True).stdout
28+
for line in info.split('\n'):
29+
tokens = line.split()
30+
if len(tokens) and tokens[0] == 'emscripten':
31+
return tokens[2]
32+
33+
if __name__ == '__main__':
34+
emscripten_hash = get_latest_emscripten(TAGFILE)
35+
print('Emscripten revision ' + emscripten_hash)
36+
if 'GITHUB_ENV' in os.environ:
37+
with open(os.environ['GITHUB_ENV'], 'a') as f:
38+
f.write(f'EMSCRIPTEN_HASH={emscripten_hash}')
39+
sys.exit(0)
40+
print('Not a GitHub Action')
41+
sys.exit(1)

0 commit comments

Comments
 (0)