From c2ca471c5119adbb6361bfb514be70f59f62d874 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 22 Dec 2023 15:56:06 +0800 Subject: [PATCH] [Tool] Add version label in merge pipeline (backport #37640) (#37641) Co-authored-by: andyziye <108652123+andyziye@users.noreply.github.com> --- .github/workflows/ci-merged.yml | 44 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-merged.yml b/.github/workflows/ci-merged.yml index fb7918ed3ad44..5eb7ab8ac235f 100644 --- a/.github/workflows/ci-merged.yml +++ b/.github/workflows/ci-merged.yml @@ -4,7 +4,7 @@ on: pull_request_target: branches: - main - - 'branch*' + - 'branch-[0-9].[0-9]' types: - closed permissions: @@ -168,25 +168,49 @@ jobs: gh run list --workflow ${yaml} -R ${REPO} -b ${GITHUB_HEAD_REF} --json databaseId -q '.[].databaseId' | xargs gh run cancel -R ${REPO} || true update_backport_merged_msg: - runs-on: ubuntu-latest + runs-on: [ self-hosted, quick ] if: > - github.base_ref != 'main' && github.event.pull_request.merged == true && - contains(github.event.pull_request.title, '(backport #') && - !contains(github.event.pull_request.labels.*.name, 'sync') + github.base_ref != 'main' && github.event.pull_request.merged == true env: LABEL: ${{ github.base_ref }}-merged + PR_NUMBER: ${{ github.event.number }} steps: - - name: prepare label + - name: prepare merge label + if: > + !contains(github.event.pull_request.labels.*.name, 'sync') && + contains(github.event.pull_request.title, '(backport #') env: GH_TOKEN: ${{ secrets.PAT }} run: | - gh label create ${LABEL} -R ${GITHUB_REPOSITORY} -c 98C1D7 -f + gh label create "${LABEL}" -R ${GITHUB_REPOSITORY} -c 98C1D7 -f - - name: commit_sha - if: always() + - name: add merge label + if: > + always() && !contains(github.event.pull_request.labels.*.name, 'sync') && + contains(github.event.pull_request.title, '(backport #') env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | ORI_PR=$(echo "${{ github.event.pull_request.title }}" | grep -oP '\(backport #\K\d+' | tail -n 1) - gh pr edit ${ORI_PR} -R ${GITHUB_REPOSITORY} --add-label "${BRANCH}-merged" + gh pr edit ${ORI_PR} -R ${GITHUB_REPOSITORY} --add-label "${LABEL}" + + - name: prepare version label + id: prepare_version_label + if: always() + env: + GH_TOKEN: ${{ secrets.PAT }} + run: | + rm -rf ./ci-tool && cp -rf /var/lib/ci-tool ./ci-tool && cd ci-tool && git pull >/dev/null + version=$(./scripts/get_next_release_tag.sh) + version_label="version:${version}" + echo "LABEL=${version_label}" >> $GITHUB_OUTPUT + gh label create "${version_label}" -R ${GITHUB_REPOSITORY} -c 1d76db -f + + - name: add version label + if: always() + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION_LABEL: ${{ steps.prepare_version_label.outputs.LABEL }} + run: | + gh pr edit ${PR_NUMBER} -R ${GITHUB_REPOSITORY} --add-label "${VERSION_LABEL}"