Skip to content

Commit

Permalink
Automatically dispatch emscripten release tag action (#1442)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dschuff authored Aug 30, 2024
1 parent d09b3c3 commit 122b38f
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 28 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ jobs:
uses: peter-evans/create-pull-request@v6
with:
title: Release ${{ env.RELEASE_VERSION }}
commit-message: Release ${{ env.RELEASE_VERSION }}
commit-message: |
Release ${{ env.RELEASE_VERSION }}
body: |
With emscripten-releases revisions:
https://chromium.googlesource.com/emscripten-releases/+/${{ inputs.lto-sha }} (LTO)
https://chromium.googlesource.com/emscripten-releases/+/${{ inputs.nonlto-sha }} (asserts)
delete-branch: true
95 changes: 68 additions & 27 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,74 @@ name: Create release tag

on:
push:
paths: [ emscripten-releases-tags.json, .github/workflows/tag-release.yml ]
paths:
- emscripten-releases-tags.json
- .github/workflows/tag-release.yml
branches:
- main
workflow_dispatch:

jobs:
tag-release:
# Only activate for commits created by the create-release.yml workflow.
# The assumption is that when manual changes happen, we want to handle
# tagging manually too.
if: github.event.head_commit.author.username == 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- name: Match message and create tag
uses: actions/github-script@v7
with:
script: |
const message = `${{ github.event.head_commit.message }}`
const regex = /Release ([0-9]+.[0-9]+.[0-9]+)/
const match = message.match(regex)
if (match) {
const release = match[1]
console.log(`Matched release ${release}`)
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${release}`,
sha: context.sha
})
} else {
console.log(`Commit message: ${message} did not match pattern`)
}
tag-release:
# Only activate for commits created by the create-release.yml workflow.
# The assumption is that when manual changes happen, we want to handle
# tagging manually too.
name: Check for release commit and create tag
if: github.event.head_commit.author.username == 'github-actions[bot]'
runs-on: ubuntu-latest
outputs:
is_release: ${{ steps.create-tag.outputs.result }}
steps:
- name: Match message and create tag
id: create-tag
uses: actions/github-script@v7
with:
github-token: ${{ secrets.TEST_TOKEN }}
# A commit with the message of the form 'Release X.Y.Z' is expected
# to have been created by create_release.py and update the latest
# release in emscripten-releases-tags.json
script: |
const message = `${{ github.event.head_commit.message }}`
const regex = /Release ([0-9]+.[0-9]+.[0-9]+)/;
const match = message.match(regex);
let is_release = false;
if (match) {
const release = match[1];
console.log(`Matched release ${release}`);
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${release}`,
sha: context.sha
});
is_release = true;
} else {
console.log(`Commit message: '${message}' did not match pattern`);
}
return is_release;
dispatch-emscripten-tag:
name: Dispatch workflow to tag emscripten repo
runs-on: ubuntu-latest
needs: tag-release
if: ${{ needs.tag-release.outputs.is_release == 'true' }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Find emscripten revision
# get_emscripten_revision_info.py sets env.EMSCRIPTEN_HASH to the
# emscripten hash associated with the latest release in
# emscripten-releases-tags.json
run: python3 scripts/get_emscripten_revision_info.py
- name: Dispatch emscripten workflow
uses: actions/github-script@v7
with:
github-token: ${{ secrets.TEST_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: 'emscripten',
workflow_id: 'tag-release.yml',
ref: 'main',
inputs: { 'release-sha': '${{ env.EMSCRIPTEN_HASH }}' }
});
41 changes: 41 additions & 0 deletions scripts/get_emscripten_revision_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

import json
import os
import subprocess
import sys

EMSCRIPTEN_RELEASES_GIT = 'https://chromium.googlesource.com/emscripten-releases'
TAGFILE = 'emscripten-releases-tags.json'

def get_latest_hash(tagfile):
with open(tagfile) as f:
versions = json.load(f)
latest = versions['aliases']['latest']
return versions['releases'][latest]

def get_latest_emscripten(tagfile):
latest = get_latest_hash(tagfile)
if not os.path.isdir('emscripten-releases'):
subprocess.run(['git', 'clone', EMSCRIPTEN_RELEASES_GIT, '--depth',
'100'], check=True)
# This will fail if the 'latest' revision is not within the most recent
# 100 commits; but that shouldn't happen because this script is intended
# to be run right after a release is added.
info = subprocess.run(['emscripten-releases/src/release-info.py',
'emscripten-releases', latest],
stdout=subprocess.PIPE, check=True, text=True).stdout
for line in info.split('\n'):
tokens = line.split()
if len(tokens) and tokens[0] == 'emscripten':
return tokens[2]

if __name__ == '__main__':
emscripten_hash = get_latest_emscripten(TAGFILE)
print('Emscripten revision ' + emscripten_hash)
if 'GITHUB_ENV' in os.environ:
with open(os.environ['GITHUB_ENV'], 'a') as f:
f.write(f'EMSCRIPTEN_HASH={emscripten_hash}')
sys.exit(0)
print('Not a GitHub Action')
sys.exit(1)

0 comments on commit 122b38f

Please sign in to comment.