Skip to content

Commit

Permalink
version update bot changes st. it works for multiple branches (#1535)
Browse files Browse the repository at this point in the history
* version bot for emscripten-3.1.73 bot

* version bot for emscripten-3.1.73
  • Loading branch information
DerThorsten authored Jan 14, 2025
1 parent c39d98a commit 4e7bbee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/new_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ on:

jobs:
update_versions:
strategy:
matrix:
branch: [main, emscripten-3.1.73]


if: (github.event_name == 'schedule' && github.repository == 'emscripten-forge/recipes') || (github.event_name != 'schedule')
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}

- name: Install micromamba
uses: mamba-org/setup-micromamba@v1
Expand Down
26 changes: 22 additions & 4 deletions emci/bot/bump_recipes_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def update_recipe_version(recipe_file, new_version, new_sha256, is_ratler):
def make_pr_title(name, old_version, new_version):
return f"Update {name} from {old_version} to {new_version}"

def bump_recipe_version(recipe_dir):
def bump_recipe_version(recipe_dir, target_pr_branch_name):

recipe_locations = [ ("recipe.yaml", True)]

Expand Down Expand Up @@ -164,7 +164,9 @@ def bump_recipe_version(recipe_dir):
# commit the changes and make a PR
pr_title = make_pr_title(name, current_version, new_version)
print(f"Making PR for {name} with title: {pr_title}")
make_pr_for_recipe(recipe_dir=recipe_dir, pr_title=pr_title, branch_name=branch_name, automerge=automerge)
make_pr_for_recipe(recipe_dir=recipe_dir, pr_title=pr_title, branch_name=branch_name,
target_branch_name=target_pr_branch_name,
automerge=automerge)

return True , current_version, new_version

Expand Down Expand Up @@ -248,11 +250,27 @@ def empty_context_manager():
# get all opened PRs
with user_ctx():

# get current branch name
current_branch_name = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8').strip()

print(f"Current branch name: {current_branch_name}")

# Check for opened PRs and merge them if the CI passed
print("Checking opened PRs and merge them if green!")
prs = subprocess.check_output(
all_prs = subprocess.check_output(
['gh', 'pr', 'list', '--author', 'emscripten-forge-bot'],
).decode('utf-8').split('\n')
prs = []
for pr in all_prs:

# gh pr view #1479 --json baseRefName -q '.baseRefName'
target_branch_name = subprocess.check_output(
['gh', 'pr', 'view', pr, '--json', 'baseRefName', '-q', '.baseRefName']
).decode('utf-8').strip()
if target_branch_name == current_branch_name:
prs.append(pr)
else:
print(f"skip PR {pr} [ current branch {current_branch_name} but PR is for {target_branch_name}]")

all_recipes = [recipe for recipe in Path(recipe_dir).iterdir() if recipe.is_dir()]
# map from folder names to recipe-dir
Expand Down Expand Up @@ -282,7 +300,7 @@ def empty_context_manager():
total_bumped = 0
for recipe in all_recipes:
try:
bumped_version, old_version, new_version = bump_recipe_version(recipe)
bumped_version, old_version, new_version = bump_recipe_version(recipe, current_branch_name)
if bumped_version:
print(f"Bumped {recipe} from {old_version} to {new_version}")
total_bumped += int(bumped_version)
Expand Down
4 changes: 2 additions & 2 deletions emci/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def automerge_is_enabled(pr):



def make_pr_for_recipe(recipe_dir, pr_title, branch_name, automerge):
def make_pr_for_recipe(recipe_dir, pr_title, target_branch_name, branch_name, automerge):

# git commit
subprocess.check_output(['git', 'add', recipe_dir])
Expand All @@ -111,7 +111,7 @@ def make_pr_for_recipe(recipe_dir, pr_title, branch_name, automerge):
# call gh to create a PR
subprocess.check_call([
'gh', 'pr', 'create',
'-B', 'main',
'-B', target_branch_name,
'--title', pr_title,
'--body', 'Beep-boop-beep! Whistle-whistle-woo!',
'--label', 'Automerge' if automerge else 'Needs Tests'
Expand Down

0 comments on commit 4e7bbee

Please sign in to comment.