From 672c08a037bf78f3e29015f3a706c03b85d7c8f5 Mon Sep 17 00:00:00 2001 From: Hiroto Funakoshi Date: Mon, 1 Apr 2024 14:33:38 +0900 Subject: [PATCH 1/3] fix: use push event for backport-pr workflow Signed-off-by: Hiroto Funakoshi --- .github/workflows/backport.yml | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 5d041ce025..eb3cd2097b 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -15,16 +15,21 @@ # name: "Run backport PR" on: - pull_request: - types: - - "closed" + push: + branches: + - main + - "release/v*.*" + - "!release/v*.*.*" env: + BASE_BRANCH: "main" TARGET_LABEL_NAME_PREFIX: "actions/backport/" BACKPORT_BRANCH_NAME_PREFIX: "backport" + FETCHED_GITHUB_INFO_PATH: github_info.json + GITHUB_USER: ${{ secrets.DISPATCH_USER }} + GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }} jobs: dump-contexts-to-log: runs-on: ubuntu-latest - if: ${{ github.event.pull_request.merged == true }} steps: - uses: actions/checkout@v4 - uses: ./.github/actions/dump-context @@ -44,28 +49,34 @@ jobs: gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} git_user_signingkey: true git_commit_gpgsign: true + - name: Fetch PR info + run: | + # gh pr list --limit 10 --json number,title,body,labels,headRefName,headRefOid,mergeCommit --state merged --base ${BASE_BRANCH} | \ + gh pr list --limit 10 --json number,title,body,labels,headRefName,headRefOid,mergeCommit --state merged | \ + jq --arg oid "${GITHUB_SHA}" '.[] | select(.mergeCommit.oid == $oid)' > ${FETCHED_GITHUB_INFO_PATH} + cat ${FETCHED_GITHUB_INFO_PATH} + echo ${GITHUB_SHA} - name: Set context id: set_context run: | - LABEL_NAMES=`cat ${GITHUB_EVENT_PATH} | jq -r --arg PREFIX $TARGET_LABEL_NAME_PREFIX '[.pull_request.labels[]? | select(.name | startswith($PREFIX)) | .name] | join(" ")'` + LABEL_NAMES=`cat ${FETCHED_GITHUB_INFO_PATH} | jq -r --arg PREFIX $TARGET_LABEL_NAME_PREFIX '[.labels[]? | select(.name | startswith($PREFIX)) | .name] | join(" ")'` echo "LABEL_NAMES=${LABEL_NAMES}" >> $GITHUB_OUTPUT # e.g.) actions/backport/v1.7 actions/backport/v1.8 echo "${LABEL_NAMES}" - name: Create PR if: ${{ steps.set_context.outputs.LABEL_NAMES != '' }} env: LABEL_NAMES: ${{ steps.set_context.outputs.LABEL_NAMES }} - GITHUB_USER: ${{ secrets.DISPATCH_USER }} - GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }} run: | - PR_TITLE=`cat $GITHUB_EVENT_PATH | jq -r ".pull_request.title"` - PR_BODY=`cat $GITHUB_EVENT_PATH | jq -r ".pull_request.body"` - PR_NUM=`cat $GITHUB_EVENT_PATH | jq -r ".pull_request.number"` + PR_TITLE=`cat $FETCHED_GITHUB_INFO_PATH | jq -r ".title"` + PR_BODY=`cat $FETCHED_GITHUB_INFO_PATH | jq -r ".body"` + PR_NUM=`cat $FETCHED_GITHUB_INFO_PATH | jq -r ".number"` + PR_BRANCH_NAME=`cat $FETCHED_GITHUB_INFO_PATH | jq -r ".headRefName"` echo "${PR_NUM} ${PR_TITLE}: ${PR_BODY}" for LABEL_NAME in ${LABEL_NAMES}; do BRANCH_NAME=`echo "${LABEL_NAME}" | sed -e "s:^${TARGET_LABEL_NAME_PREFIX}::"` # e.g) release/vx.x, main - BACKPORT_BRANCH_NAME="${BACKPORT_BRANCH_NAME_PREFIX}/${BRANCH_NAME}/${GITHUB_HEAD_REF}" # e.g) backport/release/vx.x/{current branch name} + BACKPORT_BRANCH_NAME="${BACKPORT_BRANCH_NAME_PREFIX}/${BRANCH_NAME}/${PR_BRANCH_NAME}" # e.g) backport/release/vx.x/{current branch name} echo "BRANCH_NAME=${BRANCH_NAME}" echo "BACKPORT_BRANCH_NAME=${BACKPORT_BRANCH_NAME}" @@ -75,7 +86,7 @@ jobs: git checkout -b ${BACKPORT_BRANCH_NAME} # Force cherry-pick. The conflicts will be modified within the backport PR. - git cherry-pick $GITHUB_SHA || (git add -A && git cherry-pick --continue --no-edit) + git cherry-pick ${GITHUB_SHA} || (git add -A && git cherry-pick --continue --no-edit) git push origin ${BACKPORT_BRANCH_NAME} gh pr create --base ${BRANCH_NAME} \ From 685b576f588ba85e49c71b93b1cb9f79025c2d0e Mon Sep 17 00:00:00 2001 From: Hiroto Funakoshi Date: Mon, 1 Apr 2024 14:34:30 +0900 Subject: [PATCH 2/3] fix: deleted unnecessary comment Signed-off-by: Hiroto Funakoshi --- .github/workflows/backport.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index eb3cd2097b..05f888ade9 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -51,7 +51,6 @@ jobs: git_commit_gpgsign: true - name: Fetch PR info run: | - # gh pr list --limit 10 --json number,title,body,labels,headRefName,headRefOid,mergeCommit --state merged --base ${BASE_BRANCH} | \ gh pr list --limit 10 --json number,title,body,labels,headRefName,headRefOid,mergeCommit --state merged | \ jq --arg oid "${GITHUB_SHA}" '.[] | select(.mergeCommit.oid == $oid)' > ${FETCHED_GITHUB_INFO_PATH} cat ${FETCHED_GITHUB_INFO_PATH} From c0389c0ebd807ad4959fb2caac7e24df511b0109 Mon Sep 17 00:00:00 2001 From: Hiroto Funakoshi Date: Mon, 1 Apr 2024 14:40:49 +0900 Subject: [PATCH 3/3] fix: deleted unnecessary environment variable Signed-off-by: Hiroto Funakoshi --- .github/workflows/backport.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 05f888ade9..2af5ac45f2 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -21,7 +21,6 @@ on: - "release/v*.*" - "!release/v*.*.*" env: - BASE_BRANCH: "main" TARGET_LABEL_NAME_PREFIX: "actions/backport/" BACKPORT_BRANCH_NAME_PREFIX: "backport" FETCHED_GITHUB_INFO_PATH: github_info.json