diff --git a/.github/workflows/preview.yml b/.github/workflows/autobranch.yml similarity index 59% rename from .github/workflows/preview.yml rename to .github/workflows/autobranch.yml index adea4524a801dc733d96ed872e2392cf31392155..31fdac67be17a9cd3a32e6ae2893a2348b2413d3 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 @@ -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' ) ) ) || @@ -79,7 +79,7 @@ jobs: git remote -v git branch --list --remotes - - name: Create preview branch + - name: Create autobranch branches run: | set -e @@ -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 for-preview-autobranch preview preview-force