From 3441da9aba7c00e42e2c052d97dbb23c3a4adc4a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Mar 2023 19:17:23 -0500 Subject: [PATCH 01/10] build(deps): bump python-dotenv from 0.21.1 to 1.0.0 (#158) Bumps [python-dotenv](https://github.com/theskumar/python-dotenv) from 0.21.1 to 1.0.0. - [Release notes](https://github.com/theskumar/python-dotenv/releases) - [Changelog](https://github.com/theskumar/python-dotenv/blob/main/CHANGELOG.md) - [Commits](https://github.com/theskumar/python-dotenv/compare/v0.21.1...v1.0.0) --- updated-dependencies: - dependency-name: python-dotenv dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0654cbc..d6842cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,5 @@ Flask==2.2.3 igdb-api-v4==0.1.0 libgravatar==1.0.3 py-cord==2.4.0 -python-dotenv==0.21.1 +python-dotenv==1.0.0 requests==2.28.2 From b1dcc149aa1a0d32c3cb0b399a0705c726492051 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Mar 2023 19:33:21 -0500 Subject: [PATCH 02/10] build(deps): bump libgravatar from 1.0.3 to 1.0.4 (#159) Bumps [libgravatar](https://github.com/pabluk/libgravatar) from 1.0.3 to 1.0.4. - [Release notes](https://github.com/pabluk/libgravatar/releases) - [Commits](https://github.com/pabluk/libgravatar/compare/1.0.3...1.0.4) --- updated-dependencies: - dependency-name: libgravatar dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d6842cd..410d731 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ beautifulsoup4==4.11.2 Flask==2.2.3 igdb-api-v4==0.1.0 -libgravatar==1.0.3 +libgravatar==1.0.4 py-cord==2.4.0 python-dotenv==1.0.0 requests==2.28.2 From ca4ee3fb812cbcf1e35c4629eb14c8b380698b7b Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Wed, 19 Apr 2023 18:18:23 -0400 Subject: [PATCH 03/10] feat(commands): add `channel` command (#167) --- README.md | 13 +++-- discord_bot.py | 146 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 126 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 69ff546..2613703 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,13 @@ Discord bot written in python to help manage the LizardByte discord server. ## Overview This is a custom discord bot with some slash commands to help with support on the LizardByte discord server. -| command | argument 1 | description | -|---------|------------|----------------------------------| -| /help | | Return help message | -| /docs | user | Return the specified docs page | -| /donate | user | Return donation links | -| /random | | Return a random video game quote | +| command | description | argument 1 | +|----------|---------------------------------------------------|---------------------| +| /help | Return help message | | +| /channel | Suggest to move discussion to a different channel | recommended_channel | +| /docs | Return the specified docs page | user | +| /donate | Return donation links | user | +| /random | Return a random video game quote | | ## Instructions diff --git a/discord_bot.py b/discord_bot.py index aa9c16b..99b65cd 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -3,6 +3,7 @@ import json import os import random +from typing import Union # lib imports import discord @@ -29,6 +30,7 @@ bot = discord.Bot(intents=discord.Intents.all(), auto_sync_commands=True) user_mention_desc = 'Select the user to mention' +recommended_channel_desc = 'Select the recommended channel' # context reference # https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context @@ -67,9 +69,10 @@ async def on_ready(): print("'DAILY_TASKS' environment variable is disabled") -@bot.slash_command(name="help", - description=f"Get help with {bot_name}" - ) +@bot.slash_command( + name="help", + description=f"Get help with {bot_name}" +) async def help_command(ctx: discord.ApplicationContext): """ The ``help`` slash command. @@ -84,6 +87,8 @@ async def help_command(ctx: discord.ApplicationContext): description = f"""\ `/help` - Print this message. + `/channel ` - Suggest to move discussion to a different channel. + `/docs ` - Return url to project docs based on follow up questions. `user` - The user to mention in the response. Optional. @@ -100,13 +105,91 @@ async def help_command(ctx: discord.ApplicationContext): await ctx.respond(embed=embed) -@bot.slash_command(name="donate", - description=f"Support the development of {org_name}" - ) +@bot.slash_command( + name="channel", + description="Suggest to move discussion to a different channel" +) +async def channel(ctx: discord.ApplicationContext, + recommended_channel: Option( + input_type=Union[discord.ForumChannel, discord.TextChannel], + description=recommended_channel_desc, + required=True) + ): + """ + The ``channel`` slash command. + + Sends a discord embed, with a suggestion to move discussion to a different channel. Additionally, the command will + let the users know how to gain access to additional channels. + + Parameters + ---------- + ctx : discord.ApplicationContext + Request message context. + recommended_channel : discord.Commands.Option + The recommended channel to move discussion to. + """ + categories_map = { + "dev lounge": "roles", + "insider lounge": "roles", + } + + # test if recommended_channel has an integer value + try: + channel_id = int(recommended_channel.lstrip("<#").rstrip(">")) + except ValueError: + await ctx.respond(f":bangbang: `{recommended_channel}` is not a valid channel.", ephemeral=True) + return + + channel_obj: discord.TextChannel = bot.get_guild(ctx.guild_id).get_channel(channel_id) + + # test if recommended_channel is a valid channel + try: + channel_name = channel_obj.name.lower() + except AttributeError: + await ctx.respond(f":bangbang: `{recommended_channel}` is not a valid channel in this guild.", ephemeral=True) + return + + embed = discord.Embed( + title="Incorrect channel", + description=f"Please move discussion to {recommended_channel}.", + color=0x00ff00, + ) + + permission_ch_id = '' + try: + category_name = channel_obj.category.name.lower() + except AttributeError: + pass + else: + if category_name in categories_map: + for _ in ctx.guild.text_channels: + if _.name == categories_map[category_name]: + permission_ch_id = f'<#{_.id}>\n' + break + + # special channel mentions + # https://github.com/Pycord-Development/pycord/discussions/2020#discussioncomment-5666672 + embed.add_field( + name=f"Need access to `{channel_name}`?", + value=f"You may need to give yourself access in one of these channels:\n {permission_ch_id}" + "\n ." + ) + + embed.set_footer(text=bot_name, icon_url=avatar) + + await ctx.respond(embed=embed) + + +@bot.slash_command( + name="donate", + description=f"Support the development of {org_name}" +) async def donate_command(ctx: discord.ApplicationContext, - user: Option(input_type=discord.Member, - description=user_mention_desc, - required=False)): + user: Option( + input_type=discord.Member, + description=user_mention_desc, + required=False) + ): """ The ``donate`` slash command. @@ -126,13 +209,16 @@ async def donate_command(ctx: discord.ApplicationContext, await ctx.respond('Thank you for your support!', view=DonateCommandView()) -@bot.slash_command(name="random", - description="Random video game quote" - ) +@bot.slash_command( + name="random", + description="Random video game quote" +) async def random_command(ctx: discord.ApplicationContext, - user: Option(discord.Member, - description=user_mention_desc, - required=False)): + user: Option( + input_type=discord.Member, + description=user_mention_desc, + required=False) + ): """ The ``random`` slash command. @@ -171,13 +257,16 @@ async def random_command(ctx: discord.ApplicationContext, await ctx.respond(embed=embed) -@bot.slash_command(name="docs", - description="Return docs for any project." - ) +@bot.slash_command( + name="docs", + description="Return docs for any project." +) async def docs_command(ctx: discord.ApplicationContext, - user: Option(discord.Member, - description=user_mention_desc, - required=False)): + user: Option( + input_type=discord.Member, + description=user_mention_desc, + required=False) + ): """ The ``docs`` slash command. @@ -210,13 +299,16 @@ async def docs_command(ctx: discord.ApplicationContext, ) -@bot.slash_command(name="refund", - description="Refund form for unhappy customers." - ) +@bot.slash_command( + name="refund", + description="Refund form for unhappy customers." +) async def refund_command(ctx: discord.ApplicationContext, - user: Option(discord.Member, - description=user_mention_desc, - required=False)): + user: Option( + input_type=discord.Member, + description=user_mention_desc, + required=False) + ): """ The ``refund`` slash command. From 95bd7bf090465a57550a506aef43f9499ffa77f1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Apr 2023 18:29:32 -0400 Subject: [PATCH 04/10] build(deps): bump py-cord from 2.4.0 to 2.4.1 (#161) Bumps [py-cord](https://github.com/Pycord-Development/pycord) from 2.4.0 to 2.4.1. - [Release notes](https://github.com/Pycord-Development/pycord/releases) - [Changelog](https://github.com/Pycord-Development/pycord/blob/master/CHANGELOG.md) - [Commits](https://github.com/Pycord-Development/pycord/compare/v2.4.0...v2.4.1) --- updated-dependencies: - dependency-name: py-cord dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 410d731..0744fe0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,6 @@ beautifulsoup4==4.11.2 Flask==2.2.3 igdb-api-v4==0.1.0 libgravatar==1.0.4 -py-cord==2.4.0 +py-cord==2.4.1 python-dotenv==1.0.0 requests==2.28.2 From 352fa343a8cb9e24433af0baab4dd3b2a040ccd5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Apr 2023 18:33:35 -0400 Subject: [PATCH 05/10] build(deps): bump beautifulsoup4 from 4.11.2 to 4.12.2 (#166) Bumps [beautifulsoup4](https://www.crummy.com/software/BeautifulSoup/bs4/) from 4.11.2 to 4.12.2. --- updated-dependencies: - dependency-name: beautifulsoup4 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0744fe0..e900aa6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -beautifulsoup4==4.11.2 +beautifulsoup4==4.12.2 Flask==2.2.3 igdb-api-v4==0.1.0 libgravatar==1.0.4 From f37f93d3782ae1e96cbfdff5d0ac64650e1e77ed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Apr 2023 18:37:17 -0400 Subject: [PATCH 06/10] build(deps): bump python (#164) Bumps python from 3.11.2-slim-bullseye to 3.11.3-slim-bullseye. --- updated-dependencies: - dependency-name: python dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a0e6b49..fb1168f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11.2-slim-bullseye +FROM python:3.11.3-slim-bullseye # Basic config ARG DAILY_TASKS=true From 28de001149c5ce1cff3b9ddbdc6c25a9484513f0 Mon Sep 17 00:00:00 2001 From: LizardByte-bot <108553330+LizardByte-bot@users.noreply.github.com> Date: Wed, 19 Apr 2023 18:40:46 -0400 Subject: [PATCH 07/10] ci: update global workflows (#168) --- .github/workflows/automerge.yml | 2 +- .github/workflows/ci-qodana.yml | 292 +++++++++++++++++++++++++++++ .github/workflows/dispatcher.yml | 69 +++++++ .github/workflows/issues-stale.yml | 4 +- 4 files changed, 364 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci-qodana.yml create mode 100644 .github/workflows/dispatcher.yml diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 4774eb2..49ddebf 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -49,7 +49,7 @@ jobs: steps: - name: Automerging - uses: pascalgn/automerge-action@v0.15.5 + uses: pascalgn/automerge-action@v0.15.6 env: BASE_BRANCHES: nightly GITHUB_TOKEN: ${{ secrets.GH_BOT_TOKEN }} diff --git a/.github/workflows/ci-qodana.yml b/.github/workflows/ci-qodana.yml new file mode 100644 index 0000000..91feb59 --- /dev/null +++ b/.github/workflows/ci-qodana.yml @@ -0,0 +1,292 @@ +--- +# This action is centrally managed in https://github.com//.github/ +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in +# the above-mentioned repo. + +name: Qodana + +on: + pull_request: + branches: [master, nightly] + types: [opened, synchronize, reopened] + push: + branches: [master, nightly] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + qodana_initial_check: + name: Qodana Initial Check + permissions: + actions: write # required to use workflow dispatch on fork PRs + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Prepare + id: prepare + run: | + # check the branch variable + if [ "${{ github.event_name }}" == "push" ] + then + echo "This is a PUSH event" + # use the branch name + destination=${{ github.ref_name }} + target=${{ github.ref_name }} + else + echo "This is a PR event" + # use the PR number + destination=${{ github.event.pull_request.number }} + target=${{ github.event.pull_request.base.ref }} + fi + + echo "checkout_repo=$checkout_repo" >> $GITHUB_OUTPUT + echo "checkout_ref=$checkout_ref" >> $GITHUB_OUTPUT + echo "destination=$destination" >> $GITHUB_OUTPUT + echo "target=$target" >> $GITHUB_OUTPUT + + # prepare urls + base=https://${{ github.repository_owner }}.github.io + report_url=${base}/qodana-reports/${{ github.event.repository.name }}/${destination} + echo "report_url=$report_url" >> $GITHUB_OUTPUT + + # build matrix + files=$(find . -type f -iname "qodana*.yaml") + + echo "files: ${files}" + + # do not quote to keep this as a single line + echo files=${files} >> $GITHUB_OUTPUT + + MATRIX_COMBINATIONS="" + REPORTS_MARKDOWN="" + for FILE in ${files}; do + # extract the language from file name after `qodana-` and before `.yaml` + language=$(echo $FILE | sed -r -z -e 's/(\.\/)*.*\/(qodana.yaml)/default/gm') + if [[ $language != "default" ]]; then + language=$(echo $FILE | sed -r -z -e 's/(\.\/)*.*qodana-(.*).yaml/\2/gm') + fi + MATRIX_COMBINATIONS="$MATRIX_COMBINATIONS {\"file\": \"$FILE\", \"language\": \"$language\"}," + REPORTS_MARKDOWN="$REPORTS_MARKDOWN
- [${language}](${report_url}/${language})" + done + + # removes the last character (i.e. comma) + MATRIX_COMBINATIONS=${MATRIX_COMBINATIONS::-1} + + # setup matrix for later jobs + matrix=$(( + echo "{ \"include\": [$MATRIX_COMBINATIONS] }" + ) | jq -c .) + + echo $matrix + echo $matrix | jq . + echo "matrix=$matrix" >> $GITHUB_OUTPUT + + echo "reports_markdown=$REPORTS_MARKDOWN" >> $GITHUB_OUTPUT + + - name: Setup initial notification inputs + id: inputs + if: >- + startsWith(github.event_name, 'pull_request') && + steps.prepare.outputs.files != '' + run: | + # workflow logs + workflow_url_a=https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }} + workflow_url=${workflow_url_a}/actions/runs/${{ github.run_id }} + + # multiline message + message=$(cat <<- EOF + :warning: **Qodana is checking this PR** :warning: + Live results available [here](${workflow_url}) + EOF + ) + + # escape json control characters + message=$(jq -n --arg message "$message" '$message' | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g') + + secondary_inputs=$(echo '{ + "issue_message": "'"${message}"'", + "issue_message_id": "'"qodana"'", + "issue_number": "'"${{ github.event.number }}"'", + "issue_repo_owner": "'"${{ github.repository_owner }}"'", + "issue_repo_name": "'"${{ github.event.repository.name }}"'" + }' | jq -r .) + + #escape json control characters + secondary_inputs=$(jq -n --arg secondary_inputs "$secondary_inputs" '$secondary_inputs' \ + | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g') + + echo $secondary_inputs + + # secondary input as string, not JSON + # todo - change dispatch_ref to master instead of nightly + primary_inputs=$(echo '{ + "dispatch_repository": "'"${{ github.repository_owner }}/.github"'", + "dispatch_workflow": "'"dispatch-issue-comment.yml"'", + "dispatch_ref": "'"nightly"'", + "dispatch_inputs": "'"${secondary_inputs}"'" + }' | jq -c .) + + echo $primary_inputs + echo $primary_inputs | jq . + echo "primary_inputs=$primary_inputs" >> $GITHUB_OUTPUT + + - name: Workflow Dispatch + if: >- + startsWith(github.event_name, 'pull_request') && + steps.prepare.outputs.files != '' + uses: benc-uk/workflow-dispatch@v1.2.2 + continue-on-error: true # this might error if the workflow is not found, but we still want to run the next job + with: + ref: ${{ github.base_ref || github.ref_name }} # base ref for PR and branch name for push + workflow: dispatcher.yml + inputs: ${{ steps.inputs.outputs.primary_inputs }} + token: ${{ github.token }} + + outputs: + destination: ${{ steps.prepare.outputs.destination }} + target: ${{ steps.prepare.outputs.target }} + files: ${{ steps.prepare.outputs.files }} + reports_markdown: ${{ steps.prepare.outputs.reports_markdown }} + matrix: ${{ steps.prepare.outputs.matrix }} + + qodana: + if: ${{ needs.qodana_initial_check.outputs.files != '' }} + needs: [qodana_initial_check] + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.qodana_initial_check.outputs.matrix) }} + name: Qodana-Scan-${{ matrix.language }} + continue-on-error: true + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Get baseline + id: baseline + run: | + # check if destination is not an integer + if ! [[ "${{ needs.qodana_initial_check.outputs.destination }}" =~ ^[0-9]+$ ]] + then + echo "Running for a branch update" + echo "baseline_args=" >> $GITHUB_OUTPUT + else + echo "Running for a PR" + + sarif_file=qodana.sarif.json + repo=${{ github.event.repository.name }} + target=${{ needs.qodana_initial_check.outputs.target }} + language=${{ matrix.language }} + + baseline_file="${repo}/${target}/${language}/results/${sarif_file}" + baseline_file_url="https://lizardbyte.github.io/qodana-reports/${baseline_file}" + + # don't fail if file does not exist + wget ${baseline_file_url} || true + + # check if file exists + if [ -f ${sarif_file} ] + then + echo "baseline exists" + echo "baseline_args=--baseline,${sarif_file}" >> $GITHUB_OUTPUT + else + echo "baseline does not exist" + echo "baseline_args=" >> $GITHUB_OUTPUT + fi + fi + + - name: Rename Qodana config file + id: rename + run: | + # rename the file + if [ "${{ matrix.file }}" != "./qodana.yaml" ] + then + mv -f ${{ matrix.file }} ./qodana.yaml + fi + + - name: Qodana + id: qodana + continue-on-error: true # ensure dispatch-qodana job is run + uses: JetBrains/qodana-action@v2022.3.4 + with: + additional-cache-hash: ${{ github.ref }}-${{ matrix.language }} + artifact-name: qodana-${{ matrix.language }} # yamllint disable-line rule:line-length + args: '--print-problems,${{ steps.baseline.outputs.baseline_args }}' + pr-mode: false + upload-result: true + use-caches: true + + - name: Set output status + id: status + run: | + # check if qodana failed + echo "qodana_status=${{ steps.qodana.outcome }}" >> $GITHUB_OUTPUT + + outputs: + qodana_status: ${{ steps.status.outputs.qodana_status }} + + dispatch-qodana: + # trigger qodana-reports to download artifacts from the matrix runs + needs: [qodana_initial_check, qodana] + runs-on: ubuntu-latest + name: Dispatch Qodana + permissions: + actions: write # required to use workflow dispatch on fork PRs + if: ${{ needs.qodana_initial_check.outputs.files != '' }} + steps: + - name: Setup qodana publish inputs + id: inputs + run: | + # get the artifacts + artifacts=${{ toJson(steps.artifacts.outputs.result) }} + artifacts=$(echo $artifacts | jq -c .) + + # get the target branch + target=${{ needs.qodana_initial_check.outputs.target }} + + # get the destination branch + destination=${{ needs.qodana_initial_check.outputs.destination }} + + # client payload + secondary_inputs=$(echo '{ + "destination": "'"${destination}"'", + "ref": "'"${{ github.ref }}"'", + "repo": "'"${{ github.repository }}"'", + "repo_name": "'"${{ github.event.repository.name }}"'", + "run_id": "'"${{ github.run_id }}"'", + "reports_markdown": "'"${{ needs.qodana_initial_check.outputs.reports_markdown }}"'", + "status": "'"${{ needs.qodana.outputs.qodana_status }}"'" + }' | jq -r .) + + #escape json control characters + secondary_inputs=$(jq -n --arg secondary_inputs "$secondary_inputs" '$secondary_inputs' \ + | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g') + + echo $secondary_inputs + + primary_inputs=$(echo '{ + "dispatch_repository": "'"${{ github.repository_owner }}/qodana-reports"'", + "dispatch_workflow": "'"dispatch-qodana.yml"'", + "dispatch_ref": "'"master"'", + "dispatch_inputs": "'"$secondary_inputs"'" + }' | jq -c .) + + echo $primary_inputs + echo $primary_inputs | jq . + echo "primary_inputs=$primary_inputs" >> $GITHUB_OUTPUT + + - name: Workflow Dispatch + uses: benc-uk/workflow-dispatch@v1.2.2 + continue-on-error: true # this might error if the workflow is not found, but we don't want to fail the workflow + with: + ref: ${{ github.base_ref || github.ref_name }} # base ref for PR and branch name for push + workflow: dispatcher.yml + inputs: ${{ steps.inputs.outputs.primary_inputs }} + token: ${{ github.token }} diff --git a/.github/workflows/dispatcher.yml b/.github/workflows/dispatcher.yml new file mode 100644 index 0000000..c83a233 --- /dev/null +++ b/.github/workflows/dispatcher.yml @@ -0,0 +1,69 @@ +--- +# This action is centrally managed in https://github.com//.github/ +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in +# the above-mentioned repo. + +# This action receives a dispatch event and passes it through to another repo. This is a workaround to avoid issues +# where fork PRs do not have access to secrets. + +name: Dispatcher + +on: + workflow_dispatch: + inputs: + dispatch_repository: + description: 'Repository to dispatch to' + required: true + dispatch_workflow: + description: 'Workflow to dispatch to' + required: true + dispatch_ref: + description: 'Ref/branch to dispatch to' + required: true + dispatch_inputs: + description: 'Inputs to send' + required: true + +jobs: + dispatcher: + name: Repository Dispatch + runs-on: ubuntu-latest + steps: + - name: Unescape JSON control characters + id: inputs + run: | + # get the inputs + dispatch_inputs=${{ github.event.inputs.dispatch_inputs }} + echo "$dispatch_inputs" + + # temporarily replace newlines with a placeholder + dispatch_inputs=$(echo ${dispatch_inputs} | sed 's/\\\\n/_!new_line!_/g') + + # remove newline characters + dispatch_inputs=$(echo ${dispatch_inputs} | sed 's/\\n//g') + + # replace placeholder with newline + dispatch_inputs=$(echo ${dispatch_inputs} | sed 's/_!new_line!_/\\n/g') + + # replace escaped quotes with unescaped quotes + dispatch_inputs=$(echo ${dispatch_inputs} | sed 's/\\"//g') + + # debug echo + echo "$dispatch_inputs" + + # parse as JSON + dispatch_inputs=$(echo "$dispatch_inputs" | jq -c .) + + # debug echo + echo "$dispatch_inputs" + + echo "dispatch_inputs=$dispatch_inputs" >> $GITHUB_OUTPUT + + - name: Workflow Dispatch + uses: benc-uk/workflow-dispatch@v1.2.2 + with: + repo: ${{ github.event.inputs.dispatch_repository }} + ref: ${{ github.event.inputs.dispatch_ref || 'master' }} # default to master if not specified + workflow: ${{ github.event.inputs.dispatch_workflow }} + inputs: ${{ steps.inputs.outputs.dispatch_inputs }} + token: ${{ secrets.GH_BOT_TOKEN || github.token }} # fallback to default token if not specified diff --git a/.github/workflows/issues-stale.yml b/.github/workflows/issues-stale.yml index 5fe1d77..c168034 100644 --- a/.github/workflows/issues-stale.yml +++ b/.github/workflows/issues-stale.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Stale - uses: actions/stale@v7 + uses: actions/stale@v8 with: close-issue-message: > This issue was closed because it has been stalled for 10 days with no activity. @@ -40,7 +40,7 @@ jobs: repo-token: ${{ secrets.GH_BOT_TOKEN }} - name: Invalid Template - uses: actions/stale@v7 + uses: actions/stale@v8 with: close-issue-message: > This issue was closed because the the template was not completed after 5 days. From b20b88141eec2759a8fcfdd38b800ff875263f66 Mon Sep 17 00:00:00 2001 From: LizardByte-bot <108553330+LizardByte-bot@users.noreply.github.com> Date: Wed, 19 Apr 2023 18:42:52 -0400 Subject: [PATCH 08/10] ci: update global docker (#169) --- .github/workflows/ci-docker.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 3858ae1..1082c94 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -205,9 +205,20 @@ jobs: # get branch name BRANCH=${GITHUB_HEAD_REF} + RELEASE=false + if [ -z "$BRANCH" ]; then echo "This is a PUSH event" BRANCH=${{ github.ref_name }} + COMMIT=${{ github.sha }} + CLONE_URL=${{ github.event.repository.clone_url }} + if [[ $BRANCH == "master" ]]; then + RELEASE=true + fi + else + echo "This is a PULL REQUEST event" + COMMIT=${{ github.event.pull_request.head.sha }} + CLONE_URL=${{ github.event.pull_request.head.repo.clone_url }} fi # determine to push image to dockerhub and ghcr or not @@ -220,7 +231,6 @@ jobs: # setup the tags REPOSITORY=${{ github.repository }} BASE_TAG=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]') - COMMIT=${{ github.sha }} TAGS="${BASE_TAG}:${COMMIT:0:7}${{ matrix.tag }},ghcr.io/${BASE_TAG}:${COMMIT:0:7}${{ matrix.tag }}" @@ -259,7 +269,10 @@ jobs: elif [[ $line == "# artifacts: "* && $ARTIFACTS == "" ]]; then # echo the line and use `sed` to remove the custom directive ARTIFACTS=$(echo -e "$line" | sed 's/# artifacts: //') - elif [[ $PLATFORMS != "" && $ARTIFACTS != "" ]]; then + elif [[ $line == "# no-cache-filters: "* && $NO_CACHE_FILTERS == "" ]]; then + # echo the line and use `sed` to remove the custom directive + NO_CACHE_FILTERS=$(echo -e "$line" | sed 's/# no-cache-filters: //') + elif [[ $PLATFORMS != "" && $ARTIFACTS != "" && $NO_CACHE_FILTERS != "" ]]; then # break while loop once all custom directives are found break fi @@ -277,7 +290,10 @@ jobs: echo "branch=${BRANCH}" >> $GITHUB_OUTPUT echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT echo "commit=${COMMIT}" >> $GITHUB_OUTPUT + echo "clone_url=${CLONE_URL}" >> $GITHUB_OUTPUT + echo "release=${RELEASE}" >> $GITHUB_OUTPUT echo "artifacts=${ARTIFACTS}" >> $GITHUB_OUTPUT + echo "no_cache_filters=${NO_CACHE_FILTERS}" >> $GITHUB_OUTPUT echo "platforms=${PLATFORMS}" >> $GITHUB_OUTPUT echo "push=${PUSH}" >> $GITHUB_OUTPUT echo "tags=${TAGS}" >> $GITHUB_OUTPUT @@ -328,9 +344,12 @@ jobs: BUILD_DATE=${{ steps.prepare.outputs.build_date }} BUILD_VERSION=${{ needs.check_changelog.outputs.next_version }} COMMIT=${{ steps.prepare.outputs.commit }} + CLONE_URL=${{ steps.prepare.outputs.clone_url }} + RELEASE=${{ steps.prepare.outputs.release }} tags: ${{ steps.prepare.outputs.tags }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache + no-cache-filters: ${{ steps.prepare.outputs.no_cache_filters }} - name: Build and push id: build @@ -345,9 +364,12 @@ jobs: BUILD_DATE=${{ steps.prepare.outputs.build_date }} BUILD_VERSION=${{ needs.check_changelog.outputs.next_version }} COMMIT=${{ steps.prepare.outputs.commit }} + CLONE_URL=${{ steps.prepare.outputs.clone_url }} + RELEASE=${{ steps.prepare.outputs.release }} tags: ${{ steps.prepare.outputs.tags }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache + no-cache-filters: ${{ steps.prepare.outputs.no_cache_filters }} - name: Arrange Artifacts if: ${{ steps.prepare.outputs.artifacts == 'true' }} @@ -358,6 +380,9 @@ jobs: # https://unix.stackexchange.com/a/52816 find ./ -type f -exec mv -t ./ -n '{}' + + # remove provenance file + rm -f ./provenance.json + - name: Upload Artifacts if: ${{ steps.prepare.outputs.artifacts == 'true' }} uses: actions/upload-artifact@v3 From 1af325c9492429cf4d9a9b0b30748cd12c41a7c8 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Wed, 19 Apr 2023 18:53:37 -0400 Subject: [PATCH 09/10] build(docker): update docker platforms (#170) --- .docker_platforms | 1 - .dockerignore | 12 ++++++++++++ Dockerfile | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) delete mode 100644 .docker_platforms create mode 100644 .dockerignore diff --git a/.docker_platforms b/.docker_platforms deleted file mode 100644 index fa66d0d..0000000 --- a/.docker_platforms +++ /dev/null @@ -1 +0,0 @@ -linux/386,linux/amd64,linux/arm64/v8 \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..20f9026 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +# ignore git files +.git* + +# ignore hidden files +.* + +# ignore directories +docs/ +tests/ + +# ignore venv when building locally +venv/ diff --git a/Dockerfile b/Dockerfile index fb1168f..802381c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,6 @@ +# syntax=docker/dockerfile:1.4 +# artifacts: false +# platforms: linux/amd64 FROM python:3.11.3-slim-bullseye # Basic config @@ -22,7 +25,6 @@ ENV GRAVATAR_EMAIL=$GRAVATAR_EMAIL ENV IGDB_CLIENT_ID=$IGDB_CLIENT_ID ENV IGDB_CLIENT_SECRET=$IGDB_CLIENT_SECRET -RUN mkdir /app WORKDIR /app/ COPY requirements.txt . From 79ec1bf50e25c54a4b3f93b989b8e0c70bf1467a Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Wed, 19 Apr 2023 19:03:59 -0400 Subject: [PATCH 10/10] docs(changelog): bump version to 0.1.3 (#171) --- CHANGELOG.md | 57 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2b2268..0512a81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,23 @@ # Changelog +## [0.1.3] - 2023-04-19 +**Added** +- Add channel command + +**Dependencies** +- Bump python-dotenv from 0.21.1 to 1.0.0 +- Bump libgravatar from 1.0.3 to 1.0.4 +- Bump py-cord from 2.4.0 to 2.4.1 +- Bump beautifulsoup4 from 4.11.2 to 4.12.2 +- Bump python from 3.11.2 to 3.11.3 + +**Misc** +- Update global workflows +- Update global docker +- Update docker platforms + ## [0.1.2] - 2023-02-19 -### Dependencies +**Dependencies** - Bump flask from 2.2.2 to 2.2.3 - Bump igdb-api-v4 from 0.0.5 to 0.1.0 - Bump requests from 2.28.1 to 2.28.2 @@ -12,60 +28,68 @@ - Bump python from 3.9.12 to 3.11.2 ## [0.1.1] - 2022-08-20 -### Changed +**Changed** - Enable timeout callback for `/docs` command after 45s - Incomplete `/docs` commands are deleted 30s after the timeout period - `/docs` command is reset for each call - Fix url returned for `/docs` command when `None` was selected as category - Move constants to `discord_constants.py` - Move avatar related items to `discord_avatar.py` -### Added + +**Added** - Add `discord_modals.py` -### Dependencies + +**Dependencies** - Bump flask from 2.2.1 to 2.2.2 - Bump py-cord from 2.0.0 to 2.0.1 ## [0.1.0] - 2022-08-07 -### Changed +**Changed** - Select Menus added to `docs` slash command to give finer control of returned documentation url - Buttons added to `donate` slash command, removed embeds -### Removed + +**Removed** - Removed guild file -### Dependencies + +**Dependencies** - Bump flask from 2.1.3 to 2.2.1 ## [0.0.5] - 2022-07-31 -### Fixed +**Fixed** - Bot will now self updates username and avatar - Fixed issue with duplicate guild ids - Random quotes are now pulled from `uno` repo -### Added + +**Added** - `docs` slash command -### Removed + +**Removed** - `wiki` slash command -### Dependencies + +**Dependencies** - Bump requests from 2.27.1 to 2.28.1 - Bump py-cord from 2.0.0b3 to 2.0.0 - Bump flask from 2.1.1 to 2.1.3 -### Misc. + +**Misc** - Rebrand to LizardByte - Change License to AGPL v3 ## [0.0.4] - 2022-04-24 -### Fixed +**Fixed** - Corrected environment variable for daily release task ## [0.0.3] - 2022-04-06 -### Fixed +**Fixed** - Environment variable names switched to uppercase ## [0.0.2] - 2022-04-04 -### Added +**Added** - (Misc.) Workflow improvements ## [0.0.1] - 2022-04-03 -### Added +**Added** - (Misc.) Initial release [0.0.1]: https://github.com/lizardbyte/discord-bot/releases/tag/v0.0.1 @@ -76,3 +100,4 @@ [0.1.0]: https://github.com/lizardbyte/discord-bot/releases/tag/v0.1.0 [0.1.1]: https://github.com/lizardbyte/discord-bot/releases/tag/v0.1.1 [0.1.2]: https://github.com/lizardbyte/discord-bot/releases/tag/v0.1.2 +[0.1.3]: https://github.com/lizardbyte/discord-bot/releases/tag/v0.1.3