From 3a28d4b13cf224c7fdddce36ef4e640c5a9225de Mon Sep 17 00:00:00 2001 From: srunde3 <95937393+srunde3@users.noreply.github.com> Date: Mon, 17 Jun 2024 16:02:01 -0500 Subject: [PATCH] ci: add nightly builds for total-project TICS static analysis (#245) --- .github/workflows/ci.yml | 6 +----- .github/workflows/codecov.yml | 6 +----- .github/workflows/static-analysis.yml | 24 ++++++++++++++++++++++++ .gitignore | 1 + Makefile | 21 ++++++++++++++++++++- landscape/client/monitor/computertags.py | 4 +++- landscape/lib/compat.py | 1 + landscape/lib/jiffies.py | 3 ++- 8 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38efb55b2..d2d296e67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,11 +10,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - run: | - make depends - # -common seems a catch-22, but this is just a shortcut to - # initialize user and dirs, some used through tests. - sudo apt-get -y install landscape-common + - run: make depends-ci - run: make check TRIAL=/usr/bin/trial3 lint: runs-on: ubuntu-latest diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 74ec22834..69e5543c4 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -9,11 +9,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - run: | - make depends - # -common seems a catch-22, but this is just a shortcut to - # initialize user and dirs, some used through tests. - sudo apt-get -y install landscape-common + - run: make depends-ci - run: make coverage TRIAL=/usr/bin/trial3 - name: upload uses: codecov/codecov-action@v3 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 000000000..3d2c70391 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,24 @@ +name: TiCS static analysis + +on: + workflow_dispatch: + schedule: + - cron: '0 6 * * *' # Run at 6:00a (arbitrary) to avoid peak activity on runners +jobs: + TICS: + runs-on: ubuntu-latest + steps: + - name: Checkout master branch + uses: actions/checkout@v4 + with: + submodules: true + - name: Make coverage report for TiCS + run: make prepare-tics-analysis + - name: TICS GitHub Action + uses: tiobe/tics-github-action@v3 + with: + project: landscape-client + viewerUrl: https://canonical.tiobe.com/tiobeweb/TICS/api/cfg?name=default + ticsAuthToken: ${{ secrets.TICSAUTHTOKEN }} + installTics: true + filelist: . # whole project for nightly/on-demand runs diff --git a/.gitignore b/.gitignore index 43ba519be..21fb9f713 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ _trial_temp .coverage +coverage/ docs/api build build-stamp diff --git a/Makefile b/Makefile index 1378f9b23..842f946a8 100644 --- a/Makefile +++ b/Makefile @@ -17,12 +17,21 @@ help: ## Print help about available targets .PHONY: depends depends: - sudo apt-get -y install python3-configobj python3-coverage python3-distutils-extra\ + sudo apt update && sudo apt-get -y install python3-configobj python3-coverage python3-distutils-extra\ python3-flake8 python3-mock python3-netifaces python3-pip python3-pycurl python3-twisted\ net-tools + +.PHONY: depends-dev +depends-dev: depends pip install pre-commit $(PRE_COMMIT) install +# -common seems a catch-22, but this is just a shortcut to +# initialize user and dirs, some used through tests. +.PHONY: depends-ci +depends-ci: depends + sudo apt-get -y install landscape-common + all: build .PHONY: build @@ -53,10 +62,12 @@ pyflakes: pre-commit: -pre-commit run -a +.PHONY: clean clean: -find landscape -name __pycache__ -exec rm -rf {} \; -find landscape -name \*.pyc -exec rm -f {} \; -rm -rf .coverage + -rm -rf coverage -rm -rf tags -rm -rf _trial_temp -rm -rf docs/api @@ -136,6 +147,14 @@ snap: $(SNAPCRAFT) .PHONY: snap +# TICS expects coverage info to be in ./coverage/.coverage +.PHONY: prepare-tics-analysis +prepare-tics-analysis: depends-ci coverage + sudo apt install pylint + mkdir -p coverage + cp .coverage ./coverage/.coverage + cp coverage.xml ./coverage/coverage.xml + include Makefile.packaging .DEFAULT_GOAL := help diff --git a/landscape/client/monitor/computertags.py b/landscape/client/monitor/computertags.py index 5f60070e6..6a6bd8f6b 100644 --- a/landscape/client/monitor/computertags.py +++ b/landscape/client/monitor/computertags.py @@ -15,8 +15,10 @@ class ComputerTags(DataWatcher): run_interval = 3600 # Every hour only when data changed run_immediately = True - def __init__(self, args=sys.argv): + def __init__(self, args=None): super().__init__() + if args is None: + args = sys.argv self.args = args # Defined to specify args in unit tests def get_data(self): diff --git a/landscape/lib/compat.py b/landscape/lib/compat.py index 8b5522481..0bdcf0a50 100644 --- a/landscape/lib/compat.py +++ b/landscape/lib/compat.py @@ -1,4 +1,5 @@ # flake8: noqa +# TiCS: disabled _PY3 = str != bytes diff --git a/landscape/lib/jiffies.py b/landscape/lib/jiffies.py index 6403bde8c..4350bf5ba 100644 --- a/landscape/lib/jiffies.py +++ b/landscape/lib/jiffies.py @@ -25,7 +25,8 @@ def detect_jiffies(): # is called. pid = os.fork() if pid == 0: - os._exit(0) + # os._exit is standard practice to end a child process + os._exit(0) # //TICS !W0212: private access is OK uptime2_data = read_uptime2()