Skip to content

Commit

Permalink
actions: Add Tiobe TICS cron job (#249)
Browse files Browse the repository at this point in the history
This commit adds:

- the necessary tox env targets for generating Cobertura
  coverage report XML format
- a GitHub Workflow which runs the unit tests with coverage enabled,
  and calls the `TICSServer` to upload the analysis results

Signed-off-by: Claudiu Belu <[email protected]>
Co-authored-by: Nashwan Azhari <[email protected]>
  • Loading branch information
claudiubelu and Nashwan Azhari authored Jan 15, 2025
1 parent d795c73 commit 3a8051d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/tiobe-tics-cron.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: TICS nightly quality scan

on:
workflow_dispatch:
schedule:
- cron: '0 10 * * *'

permissions:
contents: read

jobs:
TICS:
permissions:
contents: read
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Latest branches
- { branch: main }

steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit

- name: Checking out repo
uses: actions/checkout@v4
with:
ref: ${{matrix.branch}}

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Go for Cobertura Coverage Converter
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: Run Tests With Coverage
run: |
set -eux -o pipefail
# tox required for running the unit tests with coverage:
pip install tox
tox -e unit,coverage-xml
# TiCS expects the report to be under a "$(pwd)/cover" directory.
mkdir -p "$GITHUB_WORKSPACE/cover"
GENERATED_COVERAGE_XML="$GITHUB_WORKSPACE/charms/worker/k8s/coverage.xml"
mv "$GENERATED_COVERAGE_XML" cover/coverage.xml
- name: Run TICS
run: |
export TICSAUTHTOKEN=${{ secrets.TICSAUTHTOKEN }}
# NOTE(aznashwan): TiCS install script doesn't define defaults; cannot '-u'
set -ex -o pipefail
# Install the TiCS and staticcheck
go install honnef.co/go/tools/cmd/[email protected]
. <(curl --silent --show-error 'https://canonical.tiobe.com/tiobeweb/TICS/api/public/v1/fapi/installtics/Script?cfg=default&platform=linux&url=https://canonical.tiobe.com/tiobeweb/TICS/')
TICSQServer -project k8s-operator -tmpdir /tmp/tics -branchdir "$GITHUB_WORKSPACE"
7 changes: 7 additions & 0 deletions charms/worker/k8s/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ deps =
commands =
coverage report

[testenv:coverage-xml]
description = Create test coverage XML report
deps =
coverage[xml]
commands =
coverage xml

[testenv:update-dashboards]
description = Run the Grafana dashboards update script
deps = pyyaml
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ target-version = ["py38"]
[tool.coverage.report]
show_missing = true

[tool.coverage.xml]
output = "coverage.xml"

# Linting tools configuration
[tool.flake8]
max-line-length = 99
Expand Down
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[tox]
skipsdist=True
skip_missing_interpreters = True
envlist = lint, unit, static, coverage-report
envlist = lint, unit, static, coverage-report, coverage-xml

[vars]
lib_path = {toxinidir}/charms/worker/k8s/lib
Expand Down Expand Up @@ -77,6 +77,11 @@ allowlist_externals = tox
commands =
tox -c {toxinidir}/charms/worker/k8s -e coverage-report

[testenv:coverage-xml]
allowlist_externals = tox
commands =
tox -c {toxinidir}/charms/worker/k8s -e coverage-xml

[testenv:static]
description = Run static analysis tests
deps =
Expand Down

0 comments on commit 3a8051d

Please sign in to comment.