ci: improve status push to discord
This commit is contained in:
parent
626987ba67
commit
6b145d9b91
4 changed files with 79 additions and 10 deletions
|
@ -8,13 +8,15 @@ inputs:
|
||||||
status:
|
status:
|
||||||
description: "Status to report."
|
description: "Status to report."
|
||||||
required: true
|
required: true
|
||||||
|
message-id:
|
||||||
|
description: "Message ID to edit."
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
message-id:
|
message-id:
|
||||||
description: "ID of the message that was posted, for editing purposes in further calls."
|
description: "ID of the message that was posted, for editing purposes in further calls."
|
||||||
value: ""
|
value: ${{ steps.post-message.outputs.message-id }}
|
||||||
|
|
||||||
run:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
|
@ -22,5 +24,7 @@ run:
|
||||||
with:
|
with:
|
||||||
python-version: 3.12
|
python-version: 3.12
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pip install .
|
run: pip install -r ./.forgejo/actions/push-status-to-discord/requirements.txt
|
||||||
- run: python ./main.py ${{ inputs.webhook_url }} ${{ inputs.project_name }} ${{inputs.status }}
|
- id: post-message
|
||||||
|
run: |
|
||||||
|
echo "message-id=$(python ./.forgejo/actions/push-status-to-discord/main.py ${{ inputs.webhook-url }} ${{ inputs.project-name }} ${{ inputs.status }} ${{ inputs.message-id }})" >> $GITHUB_OUTPUT
|
||||||
|
|
|
@ -1,8 +1,44 @@
|
||||||
|
import sys
|
||||||
|
import typing
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
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__":
|
if __name__ == "__main__":
|
||||||
webhook_url, project_name, status = sys.argv[1:]
|
webhook_url, project_name, status = sys.argv[1:4]
|
||||||
response = httpx.post(webhook_url, json={"content": f"{project_name} - {status}"})
|
message_id = None
|
||||||
print(response.json())
|
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"])
|
||||||
|
|
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,12 +5,19 @@ jobs:
|
||||||
pre-run-notify:
|
pre-run-notify:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
- uses: ./.forgejo/actions/push-status-to-discord
|
- uses: ./.forgejo/actions/push-status-to-discord
|
||||||
|
id: post-status
|
||||||
with:
|
with:
|
||||||
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||||
project-name: ${{ github.repository }}
|
project-name: ${{ github.repository }}
|
||||||
status: "Started"
|
status: "Started"
|
||||||
|
- run: echo ${{ steps.post-status.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
|
||||||
sast:
|
sast:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
@ -21,4 +28,25 @@ jobs:
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
run: pipx run black . --check
|
run: pipx run black . --check
|
||||||
- name: Check import ordering
|
- name: Check import ordering
|
||||||
run: pipx run isort **/*.py --check
|
run: pipx run isort . --check
|
||||||
|
post-run-notify:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: always()
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: "${{ github.sha }}-${{github.run_number}}-discord-context.zip"
|
||||||
|
path: /tmp
|
||||||
|
- id: set-context
|
||||||
|
run: |
|
||||||
|
ls -la /tmp
|
||||||
|
ls -la /tmp/discord-context
|
||||||
|
unzip /tmp/discord-context
|
||||||
|
echo "message-id=$(cat discord-context)" >> $GITHUB_OUTPUT
|
||||||
|
- uses: ./.forgejo/actions/push-status-to-discord
|
||||||
|
with:
|
||||||
|
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||||
|
project-name: ${{ github.repository }}
|
||||||
|
status: "Success"
|
||||||
|
message-id: ${{ steps.set-context.outputs.message-id }}
|
||||||
|
|
Loading…
Reference in a new issue