diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 73e51dfe16a42c56cfd694f66841e151efe9fbed..9048899471abe6764ac49cae462590719b016bc3 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 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 a21e0afba56af3567b4e641acb79df707f85ef39..764e00de4288597aaf7d61cdc92232caf7a9747c 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)