From 13b1054fa1e1d08c6405eaf593eca9d275b78963 Mon Sep 17 00:00:00 2001 From: "weizhou.lan@daocloud.io" Date: Thu, 3 Aug 2023 11:59:05 +0800 Subject: [PATCH] ci: fix cherry pick Signed-off-by: weizhou.lan@daocloud.io --- .github/workflows/auto-cherrypick.yaml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-cherrypick.yaml b/.github/workflows/auto-cherrypick.yaml index 09e0b98b..00ec3cf2 100644 --- a/.github/workflows/auto-cherrypick.yaml +++ b/.github/workflows/auto-cherrypick.yaml @@ -30,9 +30,20 @@ jobs: run: | set -x echo "============ print var ======== " - grep -Eio "Merge pull request #[0-9]+ " <<< "${JSON}" - PR_NUMBER=` grep -Eio "Merge pull request #[0-9]+ " <<< "${JSON}" | grep -Eo "[0-9]+" | uniq ` - [ -n "${PR_NUMBER}" ] || { echo "no PR number, ignore" ; } + echo "try to get PR from commit" + COMMIT=` echo "${JSON}" | jq '.event.commits[0].id' | tr -d '"' ` || true + if [ -n "${COMMIT}" ]; then + PR_NUMBER=`curl -s -H "Accept: application/vnd.github.groot-preview+json" https://api.github.com/repos/${{ github.repository }}/commits/${COMMIT}/pulls | jq -r '.[].number' ` + else + echo "error, failed to get any commit ID" + fi + if [ -z "${PR_NUMBER}" ] ; then + PR_NUMBER=` grep -Eio "Merge pull request #[0-9]+ " <<< "${JSON}" | grep -Eo "[0-9]+" | uniq ` || true + fi + if [ -z "${PR_NUMBER}" ] ; then + echo "error, failed to get PR NUMBER" + exit 1 + fi PR_URL="https://github.com/${{ github.repository }}/pull/${PR_NUMBER}" ACTION_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" grep '"username":' <<< "${JSON}"