Skip to content

Commit

Permalink
ci: add nightly builds for total-project TICS static analysis (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
srunde3 authored Jun 17, 2024
1 parent e3b9adf commit 3a28d4b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 13 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
_trial_temp
.coverage
coverage/
docs/api
build
build-stamp
Expand Down
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion landscape/client/monitor/computertags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions landscape/lib/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# flake8: noqa
# TiCS: disabled

_PY3 = str != bytes

Expand Down
3 changes: 2 additions & 1 deletion landscape/lib/jiffies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 3a28d4b

Please sign in to comment.