Skip to content

Commit

Permalink
Bot updates (#1547)
Browse files Browse the repository at this point in the history
* version bot for emscripten-3.1.73
  • Loading branch information
DerThorsten authored Jan 14, 2025
1 parent 348bfbd commit 8bff2d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/new_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
ref: main

- name: Install micromamba
uses: mamba-org/setup-micromamba@v1
Expand All @@ -26,6 +26,6 @@ jobs:

- name: Determine new package version and open/merge PRs
shell: bash -l -eo pipefail {0}
run: python -m emci bot bump-recipes-versions
run: python -m emci bot bump-recipes-versions ${{ matrix.branch }}
env:
GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }}
4 changes: 2 additions & 2 deletions emci/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def changed(


@bot_app.command()
def bump_recipes_versions():
def bump_recipes_versions(target_branch_name: str):
from .bot.bump_recipes_versions import bump_recipe_versions

bump_recipe_versions(RECIPES_EMSCRIPTEN_DIR)
bump_recipe_versions(RECIPES_EMSCRIPTEN_DIR, target_branch_name)

if __name__ == "__main__":
app()
24 changes: 15 additions & 9 deletions emci/bot/bump_recipes_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .next_version import next_version
from .url_exists import url_exists
from .hash_url import hash_url
from ..git_utils import bot_github_user_ctx, git_branch_ctx, make_pr_for_recipe, automerge_is_enabled,set_bot_user
from ..git_utils import bot_github_user_ctx, git_branch_ctx, make_pr_for_recipe, automerge_is_enabled,set_bot_user,get_current_branch_name
import sys
import json

Expand Down Expand Up @@ -226,7 +226,7 @@ def user_ctx(user, email, bypass=False):
subprocess.check_output(['git', 'config', '--unset', 'user.email'])


def bump_recipe_versions(recipe_dir, use_bot=True, pr_limit=10):
def bump_recipe_versions(recipe_dir, pr_target_branch, use_bot=True, pr_limit=1):

# empty context manager
@contextlib.contextmanager
Expand All @@ -249,11 +249,17 @@ def empty_context_manager():

# get all opened PRs
with user_ctx():

current_branch_name = get_current_branch_name()
if current_branch_name == pr_target_branch:
print(f"Already on target branch {pr_target_branch}")
else:
print(f"swichting from {current_branch_name} to {pr_target_branch}")
# switch to the target branch
subprocess.run(['git', 'stash'], check=False)
subprocess.check_output(['git', 'checkout', pr_target_branch])

# 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}")
assert get_current_branch_name() == pr_target_branch

# Check for opened PRs and merge them if the CI passed
print("Checking opened PRs and merge them if green!")
Expand All @@ -265,13 +271,13 @@ def empty_context_manager():
if not pr_line:
continue
pr_id = pr_line.split()[0]
target_branch_name = subprocess.check_output(
that_pr_target_branch = subprocess.check_output(
['gh', 'pr', 'view', pr_id, '--json', 'baseRefName', '-q', '.baseRefName']
).decode('utf-8').strip()
if target_branch_name == current_branch_name:
if that_pr_target_branch == pr_target_branch:
prs.append(pr_line)
else:
print(f"skip PR {pr_id} [ current branch {current_branch_name} but PR is for {target_branch_name}]")
print(f"PR {pr_id} is not targeting {pr_target_branch} [but {that_pr_target_branch}], skipping it")

all_recipes = [recipe for recipe in Path(recipe_dir).iterdir() if recipe.is_dir()]
# map from folder names to recipe-dir
Expand Down

0 comments on commit 8bff2d8

Please sign in to comment.