From 1f49b6acd2e8a012272338bd9b95558264610368 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 2 Jun 2023 13:02:58 +0100 Subject: [PATCH 1/4] .github/workflows/preview.yml: Use autobranch label Only trigger the workflow for branches with the "autobranch" label. --- .github/workflows/preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index adea4524a..368aec975 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -40,14 +40,14 @@ jobs: ( ( github.event.action == 'synchronize' && - contains(github.event.pull_request.labels.*.name, 'preview') + contains(github.event.pull_request.labels.*.name, 'autobranch') ) || ( ( github.event.action == 'labeled' || github.event.action == 'unlabeled' ) && - github.event.label.name == 'preview' + github.event.label.name == 'autobranch' ) ) ) || -- GitLab From fbcfc90ff6d595512da645a2d8f02b68a11299f6 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 2 Jun 2023 13:04:28 +0100 Subject: [PATCH 2/4] .github/workflows/preview.yml: Rename workflow to "autobranch" --- .github/workflows/{preview.yml => autobranch.yml} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename .github/workflows/{preview.yml => autobranch.yml} (96%) diff --git a/.github/workflows/preview.yml b/.github/workflows/autobranch.yml similarity index 96% rename from .github/workflows/preview.yml rename to .github/workflows/autobranch.yml index 368aec975..1e2a0c827 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/autobranch.yml @@ -1,4 +1,4 @@ -name: preview +name: autobranch on: # Whenever a pull request is labeled or unlabeled. @@ -23,12 +23,12 @@ permissions: contents: write jobs: - preview: - name: preview + autobranch: + name: autobranch # Ensure jobs queue in order, so that we don't get race conditions while # pushing the branch - concurrency: preview + concurrency: autobranch # Set the type of machine to run on # https://github.com/actions/virtual-environments @@ -79,7 +79,7 @@ jobs: git remote -v git branch --list --remotes - - name: Create preview branch + - name: Create autobranch branches run: | set -e -- GitLab From 5017163c7dcef05c3920d020ec237fa0fc96c628 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 2 Jun 2023 13:09:49 +0100 Subject: [PATCH 3/4] .github/workflows/autobranch.yml: Allow making more autobranches --- .github/workflows/autobranch.yml | 43 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/.github/workflows/autobranch.yml b/.github/workflows/autobranch.yml index 1e2a0c827..3315bbeb7 100644 --- a/.github/workflows/autobranch.yml +++ b/.github/workflows/autobranch.yml @@ -88,24 +88,35 @@ jobs: source init_env && - lisa-combine-pr --repo 'ARM-Software/lisa' --pr-label preview --branch preview-force && + function update_branch() { + local label=$1 + local branch=$2 + local force_branch=$3 - git fetch origin preview && + local worktree=../${branch}-repo + local patch=${branch}-update.patch - # Work in a separate worktree so that there is no risk of folders - # added to PATH by init_env being manipulated - git worktree add ../preview-repo --checkout preview && + lisa-combine-pr --repo 'ARM-Software/lisa' --pr-label "$label" --branch "$force_branch" && - git -C ../preview-repo diff --binary HEAD..preview-force > update.patch && + git fetch origin "$branch" && - 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 -C ../preview-repo apply --index ../origin-repo/update.patch && - git -C ../preview-repo commit --all -m "Autocommit to preview branch on $(date) tracking preview-force" + # Work in a separate worktree so that there is no risk of folders + # added to PATH by init_env being manipulated + git worktree add "$worktree" --checkout "$branch" && - git push --force origin preview-force - git push origin preview - else - echo "Empty patch, preview and preview-force branches are up to date." - fi + git -C "$worktree" diff --binary "HEAD..$force_branch" > "$patch" && + + if [[ -s "$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 -C "$worktree" apply --index "../origin-repo/$patch" && + git -C "$worktree" commit --all -m "Autocommit to $branch branch on $(date) tracking $force_branch" + + git push --force origin "$force_branch" + git push origin "$branch" + else + echo "Empty patch, $branch and $force_branch branches are up to date." + fi + } + + update_branch preview preview preview-force -- GitLab From e872985088a450c9f2de6ecf1581751fb68ecb80 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 2 Jun 2023 13:11:38 +0100 Subject: [PATCH 4/4] .github/workflows/autobranch.yml: Change preview PR label to for-preview-autobranch --- .github/workflows/autobranch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/autobranch.yml b/.github/workflows/autobranch.yml index 3315bbeb7..31fdac67b 100644 --- a/.github/workflows/autobranch.yml +++ b/.github/workflows/autobranch.yml @@ -119,4 +119,4 @@ jobs: fi } - update_branch preview preview preview-force + update_branch for-preview-autobranch preview preview-force -- GitLab