Skip to content

Commit

Permalink
Release bot - voting
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
richtja committed Mar 15, 2024
1 parent f2831cf commit 21a7bd7
Showing 1 changed file with 59 additions and 8 deletions.
67 changes: 59 additions & 8 deletions .github/workflows/release-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
workflow_dispatch: null
jobs:
release-vote:
permissions: write-all
name: release vote
runs-on: ubuntu-20.04
steps:
Expand Down Expand Up @@ -50,19 +51,20 @@ jobs:
usr_names=()
for utils_meta in ./metadata/autils/*/; do
for metadata_file in $utils_meta*.yml; do
usr_names+=("@$(sed -n '/github_usr_name:[[:space:]]*\([^[:space:]]\+\)/{s/github_usr_name:[[:space:]]*//;s/[[:space:]]//g;p;q;}' $metadata_file)")
done
done
#for utils_meta in ./metadata/autils/*/; do
# for metadata_file in $utils_meta*.yml; do
# usr_names+=("@$(sed -n '/github_usr_name:[[:space:]]*\([^[:space:]]\+\)/{s/github_usr_name:[[:space:]]*//;s/[[:space:]]//g;p;q;}' $metadata_file)")
# done
#done
usr_names+=" @richtja"
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 }},
Expand All @@ -79,12 +81,55 @@ 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) | tr -d '"' | sort
[[ -z "$thumbs_up_users" ]] && thumbs_up_users_list=() || readarray -t thumbs_up_users_list <<< "$(comm -12 <(echo $usr_names | tr -d '@') <(echo $thumbs_up_users))";
printf '%s\n' "${usr_names[@]}"
printf '%s\n' "${thumbs_up_users[@]}"
printf '%s\n' "${thumbs_up_users_list[@]}"
if [ "${#thumbs_up_users_list[@]}" -ge "${#usr_names[@]}" ]; 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 }},
Expand All @@ -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'

0 comments on commit 21a7bd7

Please sign in to comment.