From 5433b3253466d6556b544fb3b7b52b01591c7b91 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 2 Jun 2023 11:25:31 +0100 Subject: [PATCH 1/2] tools/lisa-make-preview: Rename to lisa-combine-pr and add CLI args FEATURE Generalize lisa-make-preview to combine pull requests with arbitrary tags and create a branch with any name required. --- tools/{lisa-make-preview => lisa-combine-pr} | 23 ++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) rename tools/{lisa-make-preview => lisa-combine-pr} (77%) diff --git a/tools/lisa-make-preview b/tools/lisa-combine-pr similarity index 77% rename from tools/lisa-make-preview rename to tools/lisa-combine-pr index a21e0afba..764e00de4 100755 --- a/tools/lisa-make-preview +++ b/tools/lisa-combine-pr @@ -23,19 +23,34 @@ from tempfile import NamedTemporaryFile import json from collections import ChainMap from operator import itemgetter +import argparse from github3 import GitHub def main(): - owner = 'ARM-Software' - repo = 'lisa' + parser = argparse.ArgumentParser( + description=""" + Combine github pull requests with the given tag into a branch, rebasing all + PRs on top of each other. + """, + ) + + parser.add_argument('--repo', required=True, help='Github repository as owner/name') + parser.add_argument('--pr-label', action='append', required=True, help='Pull request labels to look for') + parser.add_argument('--branch', required=True, help='Name of the branch to be created. If the branch exists, it will be forcefully updated') + + args = parser.parse_args() + owner, repo = args.repo.split('/', 1) + labels = args.pr_label + branch = args.branch + gh = GitHub() issues = gh.issues_on( username=owner, repository=repo, state='open', - labels=['preview'], + labels=labels, ) prs = [ @@ -98,7 +113,7 @@ def main(): manifest = f.name - cmd = ['batch-rebase', 'create', '.', '--manifest', manifest, '--create-branch', 'preview'] + cmd = ['batch-rebase', 'create', '.', '--manifest', manifest, '--create-branch', branch] print(cmd) subprocess.check_call(cmd) -- GitLab From e0334a8b625a3c24f742f399734051ef341fed70 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 2 Jun 2023 11:41:14 +0100 Subject: [PATCH 2/2] .github/workflows/preview.yml: Update creation of preview branch Update lisa-make-preview to lisa-combine-pr and create 2 branches: * preview-force: Formerly "preview", this branch is rebased and forced pushed to. This makes it convenient to inspect the extra commits, but inconvenient to pull from. * preview: this can be pulled from, and will be updated to track preview-force. The commits will be meaingless autocommits but this allows a linear history without any force push, making pulling easy on user side. --- .github/workflows/preview.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 73e51dfe1..904889947 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -78,6 +78,23 @@ jobs: - name: Create preview branch run: | set -e - source init_env - lisa-make-preview - git push origin preview --force + export LC_ALL=C + + source init_env && + + lisa-combine-pr --repo 'ARM-Software/lisa' --pr-label preview --branch preview-force && + + git checkout preview && + git diff --binary preview..preview-force > update.patch + + if [[ -s update.patch ]]; then + # Apply the patch to the index as well, so that any file created + # is automatically added to the commit we are about to create. + git apply --index update.patch && + git commit --all -m "Autocommit to preview branch on $(date) tracking preview-force" + + git push --force origin preview-force + git push origin preview + else + echo "Empty patch, preview and preview-force branches are up to date." + fi -- GitLab