Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 4, 2024
1 parent 0d10237 commit 53e28dd
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 23 deletions.
87 changes: 87 additions & 0 deletions .github/actions/backport/action.yml
Original file line number Diff line number Diff line change
@@ -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!"
34 changes: 11 additions & 23 deletions .github/workflows/backport-2.0.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 53e28dd

Please sign in to comment.