Skip to content

Enable IdentityReflectionTest.java #62

Enable IdentityReflectionTest.java

Enable IdentityReflectionTest.java #62

Workflow file for this run

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Cherry Pick to Release Branch
on:
issue_comment:
types: [created]
permissions:
contents: write
issues: write
pull-requests: write
jobs:
cherry-pick:
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request != null &&
github.event.issue.pull_request.merged_at != null &&
(github.event.comment.body == '/cherry-pick' ||
startsWith(github.event.comment.body, '/cherry-pick '))
steps:
- name: Check permission
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENTER: ${{ github.event.comment.user.login }}
run: |
PR_DATA=$(gh pr view "${{ github.event.issue.number }}" \
--repo "${{ github.repository }}" \
--json author,reviews,mergedBy)
if ! echo "$PR_DATA" | jq -e --arg user "$COMMENTER" '
.author.login == $user or
(.mergedBy.login // "") == $user or
([ .reviews[].author.login ] | index($user)) != null
' > /dev/null; then
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-f body="@${COMMENTER} ⛔ You don't have permission to trigger a cherry-pick. Only the PR author, reviewers, or the person who merged the PR can use this command."
exit 1
fi
- name: Parse command
id: parse
env:
COMMENT_BODY: ${{ github.event.comment.body }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENTER: ${{ github.event.comment.user.login }}
run: |
# Extract required branch argument
TARGET_BRANCH=$(echo "$COMMENT_BODY" | sed 's|^/cherry-pick[[:space:]]*||' | xargs)
if [ -z "$TARGET_BRANCH" ]; then
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-f body="@${COMMENTER} Please specify a target release branch, e.g. \`/cherry-pick v0.9.9-release\`."
exit 1
fi
echo "target_branch=$TARGET_BRANCH" >> "$GITHUB_OUTPUT"
- name: Get PR details
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ github.event.issue.number }}"
REPO="${{ github.repository }}"
PR_DATA=$(gh pr view "$PR_NUMBER" --repo "$REPO" \
--json mergeCommit,title)
MERGE_COMMIT=$(echo "$PR_DATA" | jq -r '.mergeCommit.oid // empty')
PR_TITLE=$(echo "$PR_DATA" | jq -r '.title')
echo "merge_commit=$MERGE_COMMIT" >> "$GITHUB_OUTPUT"
echo "pr_title=$PR_TITLE" >> "$GITHUB_OUTPUT"
- name: Validate target branch
id: branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INPUT_TARGET: ${{ steps.parse.outputs.target_branch }}
COMMENTER: ${{ github.event.comment.user.login }}
run: |
TARGET="$INPUT_TARGET"
# Verify the specified branch exists
if ! gh api "/repos/${{ github.repository }}/branches/$TARGET" > /dev/null 2>&1; then
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-f body="@${COMMENTER} ❌ Cannot cherry-pick: Branch \`$TARGET\` does not exist in this repository."
exit 1
fi
echo "target=$TARGET" >> "$GITHUB_OUTPUT"
- name: Post acknowledgement comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}
COMMENTER: ${{ github.event.comment.user.login }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-f "body=@${COMMENTER} 🍒 Attempting to cherry-pick to \`${TARGET_BRANCH}\`…"
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Cherry-pick commit
id: cherry_pick
env:
MERGE_COMMIT: ${{ steps.pr.outputs.merge_commit }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}
PR_NUMBER: ${{ github.event.issue.number }}
run: |
NEW_BRANCH="cherry-pick-${PR_NUMBER}-to-${TARGET_BRANCH}"
git fetch origin "$TARGET_BRANCH"
git checkout -b "$NEW_BRANCH" "origin/$TARGET_BRANCH"
if git cherry-pick -x "$MERGE_COMMIT"; then
echo "success=true" >> "$GITHUB_OUTPUT"
else
echo "success=false" >> "$GITHUB_OUTPUT"
git cherry-pick --abort || true
fi
echo "new_branch=$NEW_BRANCH" >> "$GITHUB_OUTPUT"
- name: Push branch and create PR
if: steps.cherry_pick.outputs.success == 'true'
id: create_pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_BRANCH: ${{ steps.cherry_pick.outputs.new_branch }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}
PR_NUMBER: ${{ github.event.issue.number }}
PR_TITLE: ${{ steps.pr.outputs.pr_title }}
COMMENTER: ${{ github.event.comment.user.login }}
COMMENT_URL: ${{ github.event.comment.html_url }}
run: |
git push origin "$NEW_BRANCH"
PR_BODY=$(printf 'Cherry-pick of #%s to `%s`.\n\nTriggered by @%s via [comment](%s).' \
"$PR_NUMBER" "$TARGET_BRANCH" "$COMMENTER" "$COMMENT_URL")
PR_URL=$(gh pr create \
--repo "${{ github.repository }}" \
--base "$TARGET_BRANCH" \
--head "$NEW_BRANCH" \
--title "[$TARGET_BRANCH] $PR_TITLE" \
--body "$PR_BODY")
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
- name: Comment success
if: steps.cherry_pick.outputs.success == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}
NEW_PR_URL: ${{ steps.create_pr.outputs.pr_url }}
COMMENTER: ${{ github.event.comment.user.login }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-f "body=@${COMMENTER} ✅ Cherry-pick to \`${TARGET_BRANCH}\` succeeded! New PR created: ${NEW_PR_URL}"
- name: Comment conflict
if: steps.cherry_pick.outputs.success == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERGE_COMMIT: ${{ steps.pr.outputs.merge_commit }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}
PR_NUMBER: ${{ github.event.issue.number }}
COMMENTER: ${{ github.event.comment.user.login }}
run: |
MANUAL_STEPS="git fetch origin"
MANUAL_STEPS+=$'\n'"git checkout -b cherry-pick-${PR_NUMBER}-to-${TARGET_BRANCH} origin/${TARGET_BRANCH}"
MANUAL_STEPS+=$'\n'"git cherry-pick -x ${MERGE_COMMIT}"
MANUAL_STEPS+=$'\n'"# resolve conflicts, then:"
MANUAL_STEPS+=$'\n'"git cherry-pick --continue"
MANUAL_STEPS+=$'\n'"git push origin cherry-pick-${PR_NUMBER}-to-${TARGET_BRANCH}"
CONFLICT_BODY=$(printf '@%s ⚠️ Cherry-pick to `%s` failed due to conflicts. Please resolve them manually:\n\n```bash\n%s\n```\n\nThen open a PR from `cherry-pick-%s-to-%s` to `%s`.' \
"$COMMENTER" "$TARGET_BRANCH" "$MANUAL_STEPS" "$PR_NUMBER" "$TARGET_BRANCH" "$TARGET_BRANCH")
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-f "body=$CONFLICT_BODY"
exit 1