Skip to content

Commit 8bff2d8

Browse files
authored
Bot updates (emscripten-forge#1547)
* version bot for emscripten-3.1.73
1 parent 348bfbd commit 8bff2d8

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

.github/workflows/new_versions.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919
with:
20-
ref: ${{ matrix.branch }}
20+
ref: main
2121

2222
- name: Install micromamba
2323
uses: mamba-org/setup-micromamba@v1
@@ -26,6 +26,6 @@ jobs:
2626

2727
- name: Determine new package version and open/merge PRs
2828
shell: bash -l -eo pipefail {0}
29-
run: python -m emci bot bump-recipes-versions
29+
run: python -m emci bot bump-recipes-versions ${{ matrix.branch }}
3030
env:
3131
GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }}

emci/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ def changed(
6868

6969

7070
@bot_app.command()
71-
def bump_recipes_versions():
71+
def bump_recipes_versions(target_branch_name: str):
7272
from .bot.bump_recipes_versions import bump_recipe_versions
7373

74-
bump_recipe_versions(RECIPES_EMSCRIPTEN_DIR)
74+
bump_recipe_versions(RECIPES_EMSCRIPTEN_DIR, target_branch_name)
7575

7676
if __name__ == "__main__":
7777
app()

emci/bot/bump_recipes_versions.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .next_version import next_version
1010
from .url_exists import url_exists
1111
from .hash_url import hash_url
12-
from ..git_utils import bot_github_user_ctx, git_branch_ctx, make_pr_for_recipe, automerge_is_enabled,set_bot_user
12+
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
1313
import sys
1414
import json
1515

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

228228

229-
def bump_recipe_versions(recipe_dir, use_bot=True, pr_limit=10):
229+
def bump_recipe_versions(recipe_dir, pr_target_branch, use_bot=True, pr_limit=1):
230230

231231
# empty context manager
232232
@contextlib.contextmanager
@@ -249,11 +249,17 @@ def empty_context_manager():
249249

250250
# get all opened PRs
251251
with user_ctx():
252+
253+
current_branch_name = get_current_branch_name()
254+
if current_branch_name == pr_target_branch:
255+
print(f"Already on target branch {pr_target_branch}")
256+
else:
257+
print(f"swichting from {current_branch_name} to {pr_target_branch}")
258+
# switch to the target branch
259+
subprocess.run(['git', 'stash'], check=False)
260+
subprocess.check_output(['git', 'checkout', pr_target_branch])
252261

253-
# get current branch name
254-
current_branch_name = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8').strip()
255-
256-
print(f"Current branch name: {current_branch_name}")
262+
assert get_current_branch_name() == pr_target_branch
257263

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

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

0 commit comments

Comments
 (0)