From 73764c23faca66d5e9bcf298675dc26bbd92aa89 Mon Sep 17 00:00:00 2001 From: Evgencheg <73418250+Evgencheg@users.noreply.github.com> Date: Sat, 7 Sep 2024 03:43:37 +0300 Subject: [PATCH] Fix For Discord Changelog (#869) Signed-off-by: Evgencheg <73418250+Evgencheg@users.noreply.github.com> Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> --- .github/workflows/changelog.yml | 80 ++++++++++------------ .github/workflows/discord-changelog.yml | 23 +++++++ Tools/actions_changelogs_since_last_run.py | 36 +++------- 3 files changed, 71 insertions(+), 68 deletions(-) create mode 100644 .github/workflows/discord-changelog.yml diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 83b20ddd6f6..79cfdd83cde 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -8,7 +8,6 @@ env: GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} CHANGELOG_DIR: ${{ vars.CHANGELOG_DIR }} PR_NUMBER: ${{ github.event.number }} - CHANGELOG_WEBHOOK: ${{ secrets.CHANGELOG_WEBHOOK }} jobs: changelog: @@ -17,45 +16,40 @@ jobs: permissions: contents: write steps: - - name: Checkout Master - uses: actions/checkout@v3 - with: - token: ${{ secrets.BOT_TOKEN }} - ref: "${{ vars.CHANGELOG_BRANCH }}" - - - name: Setup Git - run: | - git config --global user.name "${{ vars.CHANGELOG_USER }}" - git config --global user.email "${{ vars.CHANGELOG_EMAIL }}" - shell: bash - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 18.x - - - name: Install Dependencies - run: | - cd "Tools/changelogs" - npm install - shell: bash - continue-on-error: true - - - name: Generate Changelog - run: | - cd "Tools/changelogs" - node changelog.js - shell: bash - continue-on-error: true - - - name: Commit Changelog - run: | - git add *.yml - git commit -m "${{ vars.CHANGELOG_MESSAGE }} (#${{ env.PR_NUMBER }})" - git push - shell: bash - continue-on-error: true - - - name: Publish changelog - run: Tools/actions_changelogs_since_last_run.py - continue-on-error: true + - name: Checkout Master + uses: actions/checkout@v3 + with: + token: ${{ secrets.BOT_TOKEN }} + ref: ${{ vars.CHANGELOG_BRANCH }} + + - name: Setup Git + run: | + git config --global user.name "${{ vars.CHANGELOG_USER }}" + git config --global user.email "${{ vars.CHANGELOG_EMAIL }}" + shell: bash + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Install Dependencies + run: | + cd "Tools/changelogs" + npm install + shell: bash + + - name: Generate Changelog + run: | + cd "Tools/changelogs" + node changelog.js + shell: bash + + - name: Commit Changelog + run: | + git pull origin master + git add *.yml + git commit -m "${{ vars.CHANGELOG_MESSAGE }} (#${{ env.PR_NUMBER }})" + git push + shell: bash + continue-on-error: true diff --git a/.github/workflows/discord-changelog.yml b/.github/workflows/discord-changelog.yml new file mode 100644 index 00000000000..681e4ab0065 --- /dev/null +++ b/.github/workflows/discord-changelog.yml @@ -0,0 +1,23 @@ +name: Discord Changelog + +on: + workflow_dispatch: + schedule: + - cron: '0 6 * * *' + +jobs: + publish_changelog: + runs-on: ubuntu-latest + steps: + + - name: checkout + uses: actions/checkout@v3 + with: + ref: master + + - name: Publish changelog + run: Tools/actions_changelogs_since_last_run.py + env: + CHANGELOG_DIR: ${{ vars.CHANGELOG_DIR }} + CHANGELOG_WEBHOOK: ${{ secrets.CHANGELOG_WEBHOOK }} + continue-on-error: true diff --git a/Tools/actions_changelogs_since_last_run.py b/Tools/actions_changelogs_since_last_run.py index 1c6d27d659d..35020b44aa5 100755 --- a/Tools/actions_changelogs_since_last_run.py +++ b/Tools/actions_changelogs_since_last_run.py @@ -18,14 +18,13 @@ GITHUB_TOKEN = os.environ["GITHUB_TOKEN"] CHANGELOG_DIR = os.environ["CHANGELOG_DIR"] CHANGELOG_WEBHOOK = os.environ["CHANGELOG_WEBHOOK"] -PR_NUMBER = os.environ["PR_NUMBER"] # https://discord.com/developers/docs/resources/webhook DISCORD_SPLIT_LIMIT = 2000 TYPES_TO_EMOJI = { "Fix": "🐛", - "Add": "🆕", + "Add": "✨", "Remove": "❌", "Tweak": "⚒️" } @@ -41,21 +40,8 @@ def main(): session.headers["Accept"] = "Accept: application/vnd.github+json" session.headers["X-GitHub-Api-Version"] = "2022-11-28" - resp = session.get(f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/pulls/{PR_NUMBER}") - resp.raise_for_status() - last_sha = resp.json()["merge_commit_sha"] - - index = int(PR_NUMBER) - while True: - index -= 1 - resp = session.get(f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/pulls/{index}") - resp.raise_for_status() - merge_info = resp.json() - if merge_info["merged_at"]: - last_sha = merge_info["merge_commit_sha"] - break - most_recent = get_most_recent_workflow(session) + last_sha = most_recent['head_commit']['id'] print(f"Last successful publish job was {most_recent['id']}: {last_sha}") last_changelog = yaml.safe_load(get_last_changelog(session, last_sha)) with open(CHANGELOG_DIR, "r") as f: @@ -121,14 +107,14 @@ def diff_changelog(old: dict[str, Any], cur: dict[str, Any]) -> Iterable[Changel def get_discord_body(content: str): return { - "content": content, - # Do not allow any mentions. - "allowed_mentions": { - "parse": [] - }, - # SUPPRESS_EMBEDS - "flags": 1 << 2 - } + "content": content, + # Do not allow any mentions. + "allowed_mentions": { + "parse": [] + }, + # SUPPRESS_EMBEDS + "flags": 1 << 2 + } def send_discord(content: str): @@ -159,7 +145,7 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None: message = change['message'] url = entry.get("url") if url and url.strip(): - group_content.write(f"{emoji} [-]({url}) {message}\n") + group_content.write(f"{emoji} - [{message}]({url})\n") else: group_content.write(f"{emoji} - {message}\n")