From 9ad0b9ad78722f306d5b1fc9f0ed99a2fa07d171 Mon Sep 17 00:00:00 2001 From: Jan Richter Date: Thu, 15 Feb 2024 13:28:07 +0100 Subject: [PATCH] Release bot - voting This adds votes counting into release bot, based on BP005. It will count thumbs up or thumbs down in release discussion and if every maintainer will add thumbs up, the bot will start the release. If the release is not ready yet, it will notify maintainers to do their votes. Reference: #7 Signed-off-by: Jan Richter --- .github/workflows/release-bot.yml | 61 ++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-bot.yml b/.github/workflows/release-bot.yml index 11417f8..5f57fb1 100644 --- a/.github/workflows/release-bot.yml +++ b/.github/workflows/release-bot.yml @@ -5,6 +5,7 @@ on: workflow_dispatch: null jobs: release-vote: + permissions: write-all name: release vote runs-on: ubuntu-20.04 steps: @@ -55,21 +56,21 @@ jobs: usr_names+=("@$(sed -n '/github_usr_name:[[:space:]]*\([^[:space:]]\+\)/{s/github_usr_name:[[:space:]]*//;s/[[:space:]]//g;p;q;}' $metadata_file)") done done - echo 'USR_NAMES='$(echo "${usr_names[@]}" | tr ' ' '\n' | sort -u) >> $GITHUB_ENV + echo 'TIME_FOR_RELEASE=0' >> $GITHUB_ENV - name: Create release discussion if: ${{ env.TIME_FOR_VOTE == 1 }} env: GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} run: | - if [[ "${{ env.DISCUSSION_ID }}" = "null" ]]; then + if [[ ${{ env.DISCUSSION_ID }} = "null" ]]; then gh api graphql -f query='mutation { createDiscussion(input: { repositoryId: ${{ vars.REPOSITORY_ID }}, categoryId: ${{ vars.CATEGORY_ID }}, body: "Hello all, Autils reached threshold of ${{ vars.RELEASE_THRESHOLD }} commits from the latest release and now we have ${{ env.COMMITS_NUMBER }} commits from the latest release. Therefore, it is time to vote if new release is needed. Please use :+1: or :-1: for this discussion to vote. - Thank you.\n\nThis vote is meat only for maintainers: ${{ env.USR_NAMES }}", + Thank you.\n\nThis vote is meat only for maintainers: ", title: "Release decision"}) { discussion { @@ -79,17 +80,61 @@ jobs: } ' fi + - name: Count votes + if: ${{ env.TIME_FOR_VOTE == 1 }} + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + run: | + if [[ ${{ env.DISCUSSION_ID }} != "null" ]]; then + readarray -t usr_names <<< "${{ env.USR_NAMES }}" + thumbs_up_users=$(gh api graphql -f query='{ + node(id: ${{ env.DISCUSSION_ID }}) { + ... on Discussion { + reactions(content:THUMBS_UP, first:50) { + nodes{ + createdAt + user { + login + } + } + } + } + } + }' | jq .data.node.reactions.nodes[].user.login | sort | tr -d '"') + thumbs_up_users_list=($(comm -23 <(echo "${usr_names[@]}" | tr -d '@') <(echo "${thumbs_up_users[@]}"))) + echo "${usr_names[@]}" + echo "${thumbs_up_users[@]}" + echo "${thumbs_up_users_list[@]}" + echo "${#thumbs_up_users_list[@]}" + if [ "${#thumbs_up_users_list[@]}" -eq 0 ]; then + gh api graphql -f query='mutation { + closeDiscussion(input: { + discussionId: ${{ env.DISCUSSION_ID }}}) { + + discussion { + id + } + } + }' + echo "It is time for release." + echo 'TIME_FOR_RELEASE=1' >> $GITHUB_ENV + else + echo "We don't have enought votes." + fi + + echo 'TH_UP_NAMES='$(echo "${thumbs_up_users_list[@]}" | tr ' ' '\n' | sort -u) >> $GITHUB_ENV + fi - name: Add comment to discussion if: ${{ env.TIME_FOR_VOTE == 1 }} env: GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} run: | - if [[ "${{ env.DISCUSSION_ID }}" != "null" ]]; then + if [[ ${{ env.DISCUSSION_ID }} != "null" && ${{ env.TIME_FOR_RELEASE }} == 0 ]]; then gh api graphql -f query='mutation { addDiscussionComment(input: { discussionId: ${{ env.DISCUSSION_ID }}, body: "This is a kindly reminder of ongoing release voting. Please use :+1: or :-1: for this discussion to vote. - Thank you.\n\nNew commits from the beginning of the voting: ${{ env.NEW_COMMITS }}\nThis vote is meat only for maintainers: ${{ env.USR_NAMES }}"}) { + Thank you.\n\nNew commits from the beginning of the voting: ${{ env.NEW_COMMITS }}\nThis vote is meat only for maintainers: "}) { comment { id @@ -98,3 +143,9 @@ jobs: } ' fi + - name: Release + if: ${{ env.TIME_FOR_RELEASE == 1 }} + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + run: | + echo 'RELEASE'