From 06391877d78e8c2522bcb843e05ca0c78d2a5836 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sat, 27 Jul 2024 15:03:58 -0400 Subject: [PATCH] ci: add static+dynamic analysis steps on push fix: yaml linting fix: python linting fix: python formatting --- .forgejo/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ .yamllint.yaml | 6 ++++++ action.yml | 1 + main.py | 21 +++++++++++++++++---- 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 .forgejo/workflows/ci.yml create mode 100644 .yamllint.yaml diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..5462c4e --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,39 @@ +--- +on: [push] # yamllint disable-line rule:truthy + +jobs: + static-analysis: + name: Static analysis + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Yaml formatting + id: yaml-format + run: pipx run yamllint . + continue-on-error: true + - name: Python formatting + id: python-format + run: pipx run black . --check + continue-on-error: true + - name: Job status + if: | + ${{ steps.yaml-format.outcome != 'success' }} || + ${{ steps.python-format.outcome != 'success' }} + run: exit 1 + dynamic-analysis: + name: Dynamic analysis + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: | + pip install -r ./requirements.txt + pipx install pylint + pipx ensurepath + - name: Python linting + id: python-linting + run: pylint **/*.py + continue-on-error: true + - name: Job status + if: ${{ steps.python-linting.outcome != 'success' }} + run: exit 1 diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..f764383 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,6 @@ +--- +extends: default + +rules: + line-length: + max: 120 diff --git a/action.yml b/action.yml index de000d9..15191da 100644 --- a/action.yml +++ b/action.yml @@ -1,3 +1,4 @@ +--- name: Post build status to Discord inputs: diff --git a/main.py b/main.py index a664bec..ceb6bc1 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,10 @@ +""" +Push status to Discord action + +Pushes provided build status data to Discord as a new message or as +an edit to an existing message. +""" + import sys import typing import datetime @@ -13,12 +20,22 @@ COLORS = { class EmbedField(typing.TypedDict): + """ + Single embedded field + See: https://discord.com/developers/docs/resources/message#embed-object-embed-field-structure + """ + name: str value: str inline: bool class Embed(typing.TypedDict): + """ + Single message embed + See: https://discord.com/developers/docs/resources/message#embed-object-embed-field-structure + """ + color: str title: str fields: list[EmbedField] @@ -37,10 +54,6 @@ class MessageState(typing.TypedDict): embeds: list[Embed] -class Context(typing.TypedDict): - message: MessageState - - if __name__ == "__main__": ( webhook_url,