Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 4, 2024
1 parent 5fd85d8 commit abd0fe8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
59 changes: 30 additions & 29 deletions .github/actions/backport/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,61 @@ inputs:
base_branch:
description: The base branch to backport to (i.e., solana-v2.0, solana-v1.18)
required: true
github_token:
description: GitHub token for authentication
required: true

runs:
using: "composite"
steps:
- name: Fetch pull request data
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
MERGE_COMMIT=${{ github.sha }}
echo "MERGE_COMMIT=$MERGE_COMMIT" >> $GITHUB_ENV
# - name: Fetch pull request data
# env:
# GITHUB_TOKEN: ${{ inputs.github_token }}
# shell: bash
# run: |
# MERGE_COMMIT=${{ github.sha }}
# echo "MERGE_COMMIT=$MERGE_COMMIT" >> $GITHUB_ENV

echo "Looking for PR associated with commit $MERGE_COMMIT... with label ${{ inputs.label }}"
PR=$(gh pr list --state merged --json number,title,headRefName,mergeCommit,labels \
--jq ".[] | select(.mergeCommit.oid == \"$MERGE_COMMIT\" and (.labels[].name | contains(\"${{ inputs.label }}\")))")
# echo "Looking for PR associated with commit $MERGE_COMMIT... with label ${{ inputs.label }}"
# PR=$(gh pr list --state merged --json number,title,headRefName,mergeCommit,labels \
# --jq ".[] | select(.mergeCommit.oid == \"$MERGE_COMMIT\" and (.labels[].name | contains(\"${{ inputs.label }}\")))")

if [[ -n "$PR" ]]; then
echo "Pull Request found:"
echo "$PR"
# if [[ -n "$PR" ]]; then
# echo "Pull Request found:"
# echo "$PR"

PR_NUMBER=$(echo $PR | jq -r '.number')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
# PR_NUMBER=$(echo $PR | jq -r '.number')
# echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV

echo "Will backport to ${{ inputs.base_branch }}"
echo "BACKPORT=true" >> $GITHUB_ENV
else
echo "No backport detected."
fi
# echo "Will backport to ${{ inputs.base_branch }}"
# echo "BACKPORT=true" >> $GITHUB_ENV
# else
# echo "No backport detected."
# fi

- name: Backport changes
if: ${{ env.BACKPORT == 'true' }}
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ inputs.github_token }}
shell: bash
run: |
MERGE_COMMIT="461510a10cb3a9f58db6d5d9a4190bbc48051305"
PR_NUMBER="69"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch --all
BASE_BRANCH="${{ inputs.base_branch }}"
BACKPORT_BRANCH="backport-${{ env.PR_NUMBER }}-to-${{ inputs.base_branch }}"
BACKPORT_BRANCH="backport-${{ github.sha }}-to-${{ inputs.base_branch }}"
git checkout $BASE_BRANCH
git pull origin $BASE_BRANCH
git checkout -b $BACKPORT_BRANCH
BACKPORT_BRANCH="backport-${{ env.PR_NUMBER }}-to-${{ inputs.base_branch }}"
git checkout -b $BACKPORT_BRANCH
git cherry-pick $MERGE_COMMIT || (git cherry-pick --abort && exit 1)
git cherry-pick -X theirs --allow-empty $MERGE_COMMIT
git push origin $BACKPORT_BRANCH
gh pr create \
gh pr create -v \
--base $BASE_BRANCH \
--head $BACKPORT_BRANCH \
--title "Backport PR #${{ env.PR_NUMBER }} to $BASE_BRANCH" \
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/backport-2.0.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
name: Backport to solana-v2.0

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
backport:
runs-on: ubuntu-latest

permissions:
pull-requests: write
contents: write

steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Debug Permissions
run: gh auth status
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Backport to v2.0
uses: ./.github/actions/backport
with:
label: v2.0
base_branch: solana-v2.0
github_token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit abd0fe8

Please sign in to comment.