From 9b3b56c31bf77d56efa6771b433fe606685f3999 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 14 Oct 2022 13:47:28 -0500 Subject: [PATCH] ci: Allow discord notification to be invoked manually If this workflow fails during normal releases, this provides a way to correct issues and re-run if necessary. --- .github/workflows/notify.yml | 22 ++++++++++++++++++++-- ci/notify/discord_notify.py | 7 +++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/notify.yml b/.github/workflows/notify.yml index 0f914a40..afcf0805 100644 --- a/.github/workflows/notify.yml +++ b/.github/workflows/notify.yml @@ -20,12 +20,30 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + + - uses: octokit/request-action@v2.x + id: release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + route: GET /repos/{org_repo}/releases/tags/{tag} + org_repo: ${{ github.repository }} + tag: ${{ env.TAG }} + - uses: actions/setup-python@v2 with: python-version: '3.x' + - run: pip install discord-webhook + + # Write changelog to a file to avoid certain characters from being processed by the shell + - run: | + cat >changelog.txt <<"EOL" + ${{ fromJSON(steps.release.outputs.data).body }} + EOL + - run: | python ci/notify/discord_notify.py \ - '${{ github.event.release.tag_name }}' \ + '${{ env.TAG }}' \ '${{ secrets.DISCORD_WEBHOOK }}' \ - '${{ github.event.release.body }}' + changelog.txt diff --git a/ci/notify/discord_notify.py b/ci/notify/discord_notify.py index 97b692e0..c24cc0d8 100644 --- a/ci/notify/discord_notify.py +++ b/ci/notify/discord_notify.py @@ -13,13 +13,16 @@ if not webhook_url: changelog = sys.argv[3] if not changelog: - print('Pass changelog as third argument') + print('Pass path to changelog file as third argument') exit(1) +with open(changelog, 'r') as f: + changelog_text = f.read() + mkdown_desc = f''' **Release Notes** ``` -{changelog} +{changelog_text} ``` '''