From 53e28dd955a490f7d29ab2aab974f9a20cda983f Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Wed, 4 Dec 2024 11:59:31 +0900 Subject: [PATCH] debug --- .github/actions/backport/action.yml | 87 +++++++++++++++++++++++++++++ .github/workflows/backport-2.0.yml | 34 ++++------- 2 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 .github/actions/backport/action.yml diff --git a/.github/actions/backport/action.yml b/.github/actions/backport/action.yml new file mode 100644 index 00000000..5af76043 --- /dev/null +++ b/.github/actions/backport/action.yml @@ -0,0 +1,87 @@ +name: Backport +description: Backport changes to another release branch. +inputs: + label: + description: The trigger label (i.e., v2.0, v1.18) + required: true + base_branch: + description: The base branch to backport to (i.e., solana-v2.0, solana-v1.18) + required: true + +runs: + using: "composite" + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Fetch pull request data + env: + GH_TOKEN: ${{ github.token }} + shell: bash + run: | + # Get the latest commit. + MERGE_COMMIT=${{ github.sha }} + echo "merge commit: $MERGE_COMMIT" + echo "MERGE_COMMIT=$MERGE_COMMIT" >> $GITHUB_ENV + + # Find the pull request associated with the squashed merge commit. + # DELETE BELOW LINE and use MERGE_COMMIT instead. + MAIN_HEAD="237b5907a1cd840b90969dd0ccf6368852f7ef1a" + echo "Looking for PR associated with commit $MAIN_HEAD..." + + PR=$(gh pr list --state merged --json number,title,headRefName,mergeCommit,labels \ + --jq '.[] | select(.mergeCommit.oid == "$MAIN_HEAD" and (.labels[].name | contains("v2.0")))') + + if [[ -n "$PR" ]]; then + echo "Pull Request found:" + echo "$PR" + echo "BACKPORT=true" >> $GITHUB_ENV + echo "Will backport to solana-v2.0" + else + echo "No associated PR found for this commit." + fi + + # Search for the desired label. + PR_JSON=$(gh pr view $PR_NUMBER --json number,labels) + + # Extract PR number and labels + PR_NUMBER=$(echo "$PR_JSON" | jq -r '.number') + echo "pr number: $PR_NUMBER" + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + + LABELS=$(echo "$PR_JSON" | jq -r '.labels[].name') + echo "labels: $LABELS" + echo "LABELS=$LABELS" >> $GITHUB_ENV + + # - name: Backport changes + # if: ${{ env.BACKPORT == 'true' }} + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # # Set up Git user + # git config user.name "github-actions[bot]" + # git config user.email "github-actions[bot]@users.noreply.github.com" + + # # Fetch all branches + # git fetch --all + + # # Create a new branch off the specified base branch + # BASE_BRANCH="${{ inputs.base_branch }}" + # BACKPORT_BRANCH="backport-${{ env.PR_NUMBER }}-to-${{ inputs.base_branch }}" + # git checkout $BASE_BRANCH + # git checkout -b $BACKPORT_BRANCH + + # # Cherry-pick the merge commit + # git cherry-pick $MERGE_COMMIT || (git cherry-pick --abort && exit 1) + + # # Push the new branch + # git push origin $BACKPORT_BRANCH + + # # Create a pull request + # gh pr create \ + # --base $BASE_BRANCH \ + # --head $BACKPORT_BRANCH \ + # --title "Backport PR #${{ env.PR_NUMBER }} to $BASE_BRANCH" \ + # --body "This is an automated backport of PR #${{ env.PR_NUMBER }} to the $BASE_BRANCH branch." + # outputs: + # result: "Backport successful!" diff --git a/.github/workflows/backport-2.0.yml b/.github/workflows/backport-2.0.yml index 67688d28..ba30ad7b 100644 --- a/.github/workflows/backport-2.0.yml +++ b/.github/workflows/backport-2.0.yml @@ -1,34 +1,22 @@ name: Backport to solana-v2.0-tmp on: + # DELETE ME! push: - branches: - - tmp + branches: [tmp] + pull_request: + branches: [tmp] jobs: backport: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Git Checkout + uses: actions/checkout@v4 - - name: Fetch pull request data - id: pr_data - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # Get the latest commit hash on main - COMMIT_HASH=$(git rev-parse HEAD) - echo $COMMIT_HASH - echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV - - # Find the pull request associated with the commit - PR_NUMBER=$(gh pr list --state merged --base main --json number,mergeCommit --jq ".[] | select(.mergeCommit == \"$COMMIT_HASH\").number") - echo $PR_NUMBER - echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV - - # Fetch the labels for the PR - LABELS=$(gh pr view $PR_NUMBER --json labels --jq '.labels[].name') - echo $LABELS - echo "LABELS=$LABELS" >> $GITHUB_ENV + - name: Backport to v2.0 + uses: ./.github/actions/backport + with: + label: v2.0 + base_branch: solana-v2.0-tmp