ci: improve status push to discord
This commit is contained in:
parent
626987ba67
commit
df24efc8a6
4 changed files with 35 additions and 5 deletions
|
@ -14,7 +14,7 @@ outputs:
|
|||
description: "ID of the message that was posted, for editing purposes in further calls."
|
||||
value: ""
|
||||
|
||||
run:
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Setup Python
|
||||
|
@ -22,5 +22,6 @@ run:
|
|||
with:
|
||||
python-version: 3.12
|
||||
- name: Install dependencies
|
||||
run: pip install .
|
||||
- run: python ./main.py ${{ inputs.webhook_url }} ${{ inputs.project_name }} ${{inputs.status }}
|
||||
run: pip install -r ./.forgejo/actions/push-status-to-discord/requirements.txt
|
||||
- run: |
|
||||
echo "test=$(python ./.forgejo/actions/push-status-to-discord/main.py ${{ inputs.webhook-url }} ${{ inputs.project-name }} ${{ inputs.status }})" >> $GITHUB_OUTPUT
|
||||
|
|
|
@ -1,8 +1,35 @@
|
|||
import httpx
|
||||
|
||||
import typing
|
||||
import sys
|
||||
|
||||
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:]
|
||||
response = httpx.post(webhook_url, json={"content": f"{project_name} - {status}"})
|
||||
print(response.json())
|
||||
embed_data = Embed(
|
||||
color=COLORS["success"],
|
||||
title=f"{project_name}: build #",
|
||||
fields=[
|
||||
EmbedField(
|
||||
name="Status",
|
||||
value=status,
|
||||
inline=True
|
||||
)
|
||||
]
|
||||
)
|
||||
response = httpx.post(f"{webhook_url}?wait=true", json={"embeds": [embed_data]})
|
||||
print(response.text)
|
||||
|
|
1
.forgejo/actions/push-status-to-discord/requirements.txt
Normal file
1
.forgejo/actions/push-status-to-discord/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
httpx==0.27
|
|
@ -5,6 +5,7 @@ jobs:
|
|||
pre-run-notify:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./.forgejo/actions/push-status-to-discord
|
||||
with:
|
||||
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
|
|
Loading…
Reference in a new issue