From f2f5d5664575ec3714450af9a50e3f47e7be1a06 Mon Sep 17 00:00:00 2001 From: Aditya Gidh Date: Thu, 23 Jan 2025 14:13:36 -0500 Subject: [PATCH 1/5] Setup Github Action workflow for auto cherry picking commits from main to release Signed-off-by: Aditya Gidh --- .github/workflows/cherry-pick.yml | 79 +++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/.github/workflows/cherry-pick.yml b/.github/workflows/cherry-pick.yml index 126a25d7..1a40b969 100644 --- a/.github/workflows/cherry-pick.yml +++ b/.github/workflows/cherry-pick.yml @@ -1,29 +1,70 @@ -name: Cherry pick PR into release-1.0 branch + +name: Cherry-Pick into release-1.0 branch on: - pull_request_target: + push: branches: - main + workflow_dispatch: jobs: - cherry_pick_release_1_0: + cherry-pick: runs-on: ubuntu-latest - name: Cherry pick into release-1.0 branch - if: ${{ contains(github.event.pull_request.labels.*.name, 'cherry-pick-release-1.0') && github.event.pull_request.merged == true }} + steps: - - name: Checkout - uses: actions/checkout@v4 + # Step 1: Checkout the repository + - name: Checkout Repository + uses: actions/checkout@v3 with: - fetch-depth: 0 - - name: Cherry pick into release-1.0 branch - uses: carloscastrojumo/github-cherry-pick-action@v1.0.10 + fetch-depth: 0 # Ensure we fetch all history for cherry-picking + + # Step 2: Set up Git + - name: Set up Git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Step 3: Check for the specific tag in the commit + - name: Check for Cherry Pick Tag in Commit Message + id: check_tag + run: | + if [[ "$(git log -1 --pretty=%B)" == *"[cherry-pick]"* ]]; then + echo "Found tag [cherry-pick]" + echo "::set-output name=should_cherry_pick::true" + else + echo "No tag found. Skipping cherry-pick." + echo "::set-output name=should_cherry_pick::false" + fi + + # Step 4: Cherry-pick the commit to the release branch + - name: Cherry-pick, commit and push into release-1.0 branch + if: steps.check_tag.outputs.should_cherry_pick == 'true' + run: | + # Get the latest commit hash + COMMIT_HASH=$(git rev-parse HEAD) + + # Create new branch for cherry picking + BRANCH="cherry-pick-$(date +%Y%m%d%H%M%S)" + git checkout -b $BRANCH release-1.0 + + # Cherry-pick the commit + git cherry-pick $COMMIT_HASH || { + echo "Cherry-pick failed. Resolve conflicts manually." + exit 1 } + + # Push the new branch + git push origin $BRANCH_NAME + + + # Step 5: Create a pull request for the release branch + - name: Create Pull Request + if: steps.check_tag.outputs.should_cherry_pick == 'true' + uses: peter-evans/create-pull-request@v5 with: - branch: release-1.0 - labels: | - cherry-pick - reviewers: | - instructlab/ui-maintainers - title: '[cherry-pick] {old_title}' - body: 'Cherry picking #{old_pull_request_id} onto this branch' -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} + base: release-1.0 + head: ${{ steps.cherry-pick.outputs.branch }} + title: "Cherry-pick: Add commit to release-1.0" + body: | + This PR contains a cherry-picked commit from the `main` branch. + - Original commit: $COMMIT_HASH \ No newline at end of file From e2409912460d4224f57aed73e31bdb7b2359d97b Mon Sep 17 00:00:00 2001 From: Aditya Gidh Date: Thu, 23 Jan 2025 14:33:39 -0500 Subject: [PATCH 2/5] potential fixes for workflow errors Signed-off-by: Aditya Gidh --- .github/workflows/cherry-pick.yml | 62 +++++++------------------------ 1 file changed, 14 insertions(+), 48 deletions(-) diff --git a/.github/workflows/cherry-pick.yml b/.github/workflows/cherry-pick.yml index 1a40b969..6f9f3bdb 100644 --- a/.github/workflows/cherry-pick.yml +++ b/.github/workflows/cherry-pick.yml @@ -1,4 +1,3 @@ - name: Cherry-Pick into release-1.0 branch on: @@ -8,63 +7,30 @@ on: workflow_dispatch: jobs: - cherry-pick: + cherry_pick: + if: github.event.pull_request.merged == true runs-on: ubuntu-latest - steps: - # Step 1: Checkout the repository - - name: Checkout Repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v2 with: - fetch-depth: 0 # Ensure we fetch all history for cherry-picking + fetch-depth: 0 - # Step 2: Set up Git - name: Set up Git run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - # Step 3: Check for the specific tag in the commit - - name: Check for Cherry Pick Tag in Commit Message - id: check_tag - run: | - if [[ "$(git log -1 --pretty=%B)" == *"[cherry-pick]"* ]]; then - echo "Found tag [cherry-pick]" - echo "::set-output name=should_cherry_pick::true" - else - echo "No tag found. Skipping cherry-pick." - echo "::set-output name=should_cherry_pick::false" - fi + git config user.name "GitHub Actions Bot" + git config user.email "actions@github.com" - # Step 4: Cherry-pick the commit to the release branch - - name: Cherry-pick, commit and push into release-1.0 branch - if: steps.check_tag.outputs.should_cherry_pick == 'true' + - name: Cherry-pick commit run: | - # Get the latest commit hash - COMMIT_HASH=$(git rev-parse HEAD) - - # Create new branch for cherry picking - BRANCH="cherry-pick-$(date +%Y%m%d%H%M%S)" - git checkout -b $BRANCH release-1.0 - - # Cherry-pick the commit - git cherry-pick $COMMIT_HASH || { - echo "Cherry-pick failed. Resolve conflicts manually." - exit 1 } - - # Push the new branch - git push origin $BRANCH_NAME - + git checkout release-1.0 + git cherry-pick ${{ github.event.pull_request.merge_commit_sha }} - # Step 5: Create a pull request for the release branch - name: Create Pull Request - if: steps.check_tag.outputs.should_cherry_pick == 'true' - uses: peter-evans/create-pull-request@v5 + uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.GITHUB_TOKEN }} + branch: cherry-pick-${{ github.event.pull_request.number }} base: release-1.0 - head: ${{ steps.cherry-pick.outputs.branch }} - title: "Cherry-pick: Add commit to release-1.0" - body: | - This PR contains a cherry-picked commit from the `main` branch. - - Original commit: $COMMIT_HASH \ No newline at end of file + title: 'Cherry-pick: Add commit to release-1.0 ${{ github.event.pull_request.title }}' + body: 'Automatically cherry-picked commit from main branch' From 9a24703692b017251db122f8d0d92bdca25f1489 Mon Sep 17 00:00:00 2001 From: Aditya Gidh Date: Thu, 23 Jan 2025 14:46:30 -0500 Subject: [PATCH 3/5] update versions Signed-off-by: Aditya Gidh --- .github/workflows/cherry-pick.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cherry-pick.yml b/.github/workflows/cherry-pick.yml index 6f9f3bdb..124e3496 100644 --- a/.github/workflows/cherry-pick.yml +++ b/.github/workflows/cherry-pick.yml @@ -1,10 +1,10 @@ name: Cherry-Pick into release-1.0 branch on: - push: + pull_request: + types: [closed] branches: - main - workflow_dispatch: jobs: cherry_pick: @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -27,7 +27,7 @@ jobs: git cherry-pick ${{ github.event.pull_request.merge_commit_sha }} - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 + uses: peter-evans/create-pull-request@v5 with: token: ${{ secrets.GITHUB_TOKEN }} branch: cherry-pick-${{ github.event.pull_request.number }} From 4e6dbb77eb0fa9865cc057194be2d3ff593001ae Mon Sep 17 00:00:00 2001 From: Aditya Gidh Date: Fri, 24 Jan 2025 09:01:53 -0500 Subject: [PATCH 4/5] update for cherry-pick action Signed-off-by: Aditya Gidh --- .github/workflows/cherry-pick.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cherry-pick.yml b/.github/workflows/cherry-pick.yml index 124e3496..aa357c72 100644 --- a/.github/workflows/cherry-pick.yml +++ b/.github/workflows/cherry-pick.yml @@ -8,7 +8,7 @@ on: jobs: cherry_pick: - if: github.event.pull_request.merged == true + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'cherry-pick release-1.0') runs-on: ubuntu-latest steps: - name: Checkout repository From 423112b73dec9f1540df9bd1c545262ab781e928 Mon Sep 17 00:00:00 2001 From: Aditya Gidh Date: Fri, 24 Jan 2025 13:40:15 -0500 Subject: [PATCH 5/5] fix label name per review Signed-off-by: Aditya Gidh --- .github/workflows/cherry-pick.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cherry-pick.yml b/.github/workflows/cherry-pick.yml index aa357c72..06ec8dbe 100644 --- a/.github/workflows/cherry-pick.yml +++ b/.github/workflows/cherry-pick.yml @@ -8,7 +8,7 @@ on: jobs: cherry_pick: - if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'cherry-pick release-1.0') + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'cherry-pick-release-1.0') runs-on: ubuntu-latest steps: - name: Checkout repository