1
0
Fork 0

chore: extract status-post into own repo
Some checks failed
/ pre-run-notify (push) Failing after 54s
/ sast (push) Successful in 53s
/ post-run-notify (push) Has been cancelled

This commit is contained in:
Marc 2024-07-20 19:41:24 -04:00
parent 35de43427b
commit fabbf51317
Signed by: marc
GPG key ID: 048E042F22B5DC79
4 changed files with 2 additions and 95 deletions

View file

@ -1,48 +0,0 @@
inputs:
webhook-url:
description: "Discord webhook URL events should be sent to."
required: true
project-name:
description: "Project name."
required: true
status:
description: "Status to report."
required: true
message-id:
description: "Message ID to edit."
init:
description: "Marks the first status push, prevents pulling context."
outputs:
message-id:
description: "ID of the message that was posted, for editing purposes in further calls."
value: ${{ steps.post-message.outputs.message-id }}
runs:
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: actions/download-artifact@v3
if: ${{ !inputs.init }}
with:
name: "${{ github.sha }}-${{github.run_number}}-discord-context.zip"
path: /tmp
- id: set-context
run: |
echo "message-id=$(cat /tmp/discord-context)" >> $GITHUB_OUTPUT
- name: Install dependencies
if: ${{ always() }}
run: pip install -r ./.forgejo/actions/push-status-to-discord/requirements.txt
- id: post-message
run: |
echo "$(python ./.forgejo/actions/push-status-to-discord/main.py ${{ inputs.webhook-url }} ${{ inputs.project-name }} ${{ inputs.status }} ${{ steps.set-context.outputs.message-id }})" >> discord-context
- uses: actions/upload-artifact@v3
with:
path: ./discord-context
name: "${{ github.sha }}-${{ github.run_number }}-discord-context.zip"
retention-days: 1
overwrite: true

View file

@ -1,44 +0,0 @@
import sys
import typing
import httpx
COLORS = {
"failure": 0xCB2431,
"success": 0x28A745,
}
class EmbedField(typing.TypedDict):
name: str
value: str
inline: bool
class Embed(typing.TypedDict):
color: str
title: str
fields: list[EmbedField]
if __name__ == "__main__":
webhook_url, project_name, status = sys.argv[1:4]
message_id = None
if len(sys.argv) > 4:
message_id = sys.argv[4]
embed_data = Embed(
color=COLORS["success"],
title=f"{project_name}: build #",
fields=[EmbedField(name="Status", value=status, inline=True)],
)
if message_id:
response = httpx.patch(
f"{webhook_url}/messages/{message_id}?wait=true",
json={"embeds": [embed_data]},
)
else:
response = httpx.post(f"{webhook_url}?wait=true", json={"embeds": [embed_data]})
print(response.json()["id"])

View file

@ -1 +0,0 @@
httpx==0.27

View file

@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: ./.forgejo/actions/push-status-to-discord - uses: https://forge.karnov.club/marc/push-status-to-discord-action@main
id: post-status id: post-status
with: with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }} webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
@ -29,7 +29,7 @@ jobs:
if: always() if: always()
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: ./.forgejo/actions/push-status-to-discord - uses: https://forge.karnov.club/marc/push-status-to-discord-action@main
with: with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }} webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
project-name: ${{ github.repository }} project-name: ${{ github.repository }}