Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
ci: split actions depending on kind
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Urbanek <[email protected]>
  • Loading branch information
shanduur committed May 14, 2024
1 parent 45dec2d commit 88d0fd7
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 49 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: go

on:
pull_request:
branches: [ '*' ]
paths:
- 'api/**'
- 'cmd/**'
- 'hack/templates/**'
- 'hack/*.go'
- 'internal/**'
- 'go.mod'
- 'go.sum'
push:
branches:
- "main"

jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: false
- uses: golangci/golangci-lint-action@v6
with:
version: latest
skip-cache: true

tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: false
- run: |
make test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: linters-tests
name: linters

on:
pull_request:
Expand All @@ -19,19 +19,6 @@ jobs:
configFile: .commitlintrc.mjs
token: ${{ secrets.GITHUB_TOKEN }}

golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: false
- uses: golangci/golangci-lint-action@v6
with:
version: latest
skip-cache: true

shell-linters:
runs-on: ubuntu-latest
steps:
Expand All @@ -46,14 +33,3 @@ jobs:
with:
dockerfile: Dockerfile
recursive: true

tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: false
- run: |
make test
34 changes: 34 additions & 0 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: python

on:
pull_request:
branches: [ '*' ]
paths:
- 'hack/**'
- 'docs/**'
- 'poetry.lock'
- 'pyproject.toml'
push:
branches:
- "main"

jobs:
linters:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: fregante/setup-git-user@v2
- uses: actions/setup-python@v5
with:
python-version: '3.x'
check-latest: true
- run: |
pip install poetry
- run: |
poetry install
- run: |
poetry run black --check .
poetry run isort --check .
poetry run mypy .
56 changes: 32 additions & 24 deletions hack/report.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import sys
import argparse
import xml.dom.minidom as minidom
import sys
import traceback
import xml.dom.minidom as minidom

FAILED = ":x: Failed"
PASSED = ":white_check_mark: Passed"


class Table:
def __init__(self, headers: list[str]) -> None:
self.headers = headers
self.separator = ["---"] * len(headers)
self.cols = len(headers)
self.rows = []
self.rows: list[list[str]] = []

def add(self, row: list[str]) -> None:
assert self.cols == len(row)
self.rows.append(row)


class Report:
def __init__(self,
time: str, timestamp: str,
table: Table,
) -> None:
def __init__(
self,
time: str,
timestamp: str,
table: Table,
) -> None:
self.time = time
self.timestamp = timestamp
self.table = table
Expand All @@ -32,32 +35,37 @@ def __init__(self,

def print(self) -> None:
print(f'## E2E report {":white_check_mark:" if self.ok else ":x:"}')
print(f'Started at `{self.timestamp}` took `{self.time}`')
print('')
print(f'![](https://img.shields.io/badge/tests-{self.passes}_passed%2C_{self.failures}_failed-{"green" if self.ok else "red"})')
print('')
print('|'.join(self.table.headers))
print('|'.join(self.table.separator))
for row in sorted(self.table.rows, key=lambda x: x[self.table.cols-1], reverse=True):
print('|'.join(row))
print(f"Started at `{self.timestamp}` took `{self.time}`")
print("")
print(
f'![](https://img.shields.io/badge/tests-{self.passes}_passed%2C_{self.failures}_failed-{"green" if self.ok else "red"})'
)
print("")
print("|".join(self.table.headers))
print("|".join(self.table.separator))
for row in sorted(
self.table.rows, key=lambda x: x[self.table.cols - 1], reverse=True
):
print("|".join(row))


def generate_markdown(report: str) -> None:
dom = minidom.parse(report)

table = Table(["Test Suite", "Test Case", "Time (s)", "Status"])

testsuiteList = dom.getElementsByTagName('testsuite')
testsuiteList = dom.getElementsByTagName("testsuite")
for testsuite in testsuiteList:
testsuite_name = testsuite.getAttribute("name")
testcases = testsuite.getElementsByTagName('testcase')
testcases = testsuite.getElementsByTagName("testcase")

for testcase in testcases:
testcase_name = testcase.getAttribute("name")
time = testcase.getAttribute("time")
status = FAILED if testcase.getElementsByTagName("failure") else PASSED
table.add(row=[testsuite_name, testcase_name, f'`{time}`', status])
table.add(row=[testsuite_name, testcase_name, f"`{time}`", status])

testsuites = dom.getElementsByTagName('testsuites')
testsuites = dom.getElementsByTagName("testsuites")

Report(
time=testsuites[0].getAttribute("time"),
Expand Down Expand Up @@ -89,8 +97,8 @@ def run(args=sys.argv):
try:
generate_markdown(args.file)
except Exception as exc:
print('## Report generation failed :skull:')
print('')
print('```log')
print(f'{traceback.print_exception(exc)}')
print('```')
print("## Report generation failed :skull:")
print("")
print("```log")
print(f"{traceback.print_exception(exc)}")
print("```")

0 comments on commit 88d0fd7

Please sign in to comment.