From bc489fdb40c64f899957a139fbe3e4049a9f80d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Tue, 16 May 2023 12:57:56 +0200 Subject: [PATCH] ci: add basic config checking with ruff MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr Å tetiar --- .github/workflows/build-push.yml | 29 +++++++++++++++++++++++++++++ .gitignore | 2 ++ .ruff.toml | 1 + phase1/master.cfg | 14 +++++++------- phase2/master.cfg | 9 ++++----- requirements-dev.txt | 2 ++ 6 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 .ruff.toml create mode 100644 requirements-dev.txt diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 666c9e3..b6f1c3c 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -15,9 +15,38 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + test-lint: + name: Test with Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: + - "3.9" + - "3.10" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: pip install -r requirements-dev.txt + + - name: Lint with ruff + run: ruff phase*/master.cfg + +# FIXME +# - name: Stylecheck with black +# run: black phase*/master.cfg + build-test-push: name: Build, test and push containers runs-on: ubuntu-latest + needs: test-lint permissions: packages: write diff --git a/.gitignore b/.gitignore index 3a2e179..a94d1d2 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ phase[12]/twistd.* !.gitlab/**/* !.github !.github/**/* +!requirements-dev.txt +!.ruff.toml diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..f419fc5 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1 @@ +ignore = ["E501"] diff --git a/phase1/master.cfg b/phase1/master.cfg index 00d744c..c392c5f 100644 --- a/phase1/master.cfg +++ b/phase1/master.cfg @@ -608,7 +608,7 @@ def UsignSec2Pub(props): comment = branches[branch].get("usign_comment") or "untrusted comment: secret key" seckey = branches[branch].get("usign_key") seckey = base64.b64decode(seckey) - except: + except Exception: return None return "{}\n{}".format(re.sub(r"\bsecret key$", "public key", comment), @@ -710,12 +710,12 @@ for target in targets: # check out the source # Git() runs: - # if repo doesn't exist: 'git clone repourl' - # method 'clean' runs 'git clean -d -f', method fresh runs 'git clean -f -f -d -x'. Only works with mode='full' - # git cat-file -e - # git checkout -f - # git checkout -B - # git rev-parse HEAD + # if repo doesn't exist: 'git clone repourl' + # method 'clean' runs 'git clean -d -f', method fresh runs 'git clean -f -f -d -x'. Only works with mode='full' + # git cat-file -e + # git checkout -f + # git checkout -B + # git rev-parse HEAD factory.addStep(Git( name = "git", repourl = repo_url, diff --git a/phase2/master.cfg b/phase2/master.cfg index 8b7df6a..e19a731 100644 --- a/phase2/master.cfg +++ b/phase2/master.cfg @@ -5,7 +5,6 @@ import os import re import sys import base64 -import random import subprocess import configparser @@ -93,7 +92,7 @@ max_builds = dict() for section in ini.sections(): if section.startswith("worker "): if ini.has_option(section, "name") and ini.has_option(section, "password") and \ - ini.has_option(section, "phase") and ini.getint(section, "phase") == 2: + ini.has_option(section, "phase") and ini.getint(section, "phase") == 2: name = ini.get(section, "name") password = ini.get(section, "password") sl_props = { 'shared_wd': False } @@ -324,7 +323,7 @@ def IsArchitectureSelected(target): def UsignSec2Pub(seckey, comment="untrusted comment: secret key"): try: seckey = base64.b64decode(seckey) - except: + except Exception: return None return "{}\n{}".format(re.sub(r"\bsecret key$", "public key", comment), @@ -367,7 +366,7 @@ def getNewestCompleteTime(bldr): if last_build and last_build[0]: last_complete_at = last_build[0]['complete_at'] if last_complete_at and (last_complete_at > complete_at): - return last_complete_at + return last_complete_at return complete_at @@ -762,7 +761,7 @@ for arch in arches: description = "Uploading source archives", workdir = "build/sdk", command = ["rsync", "--files-from=sourcelist", "-4", "--progress", "--checksum", "--delay-updates", - WithProperties("--partial-dir=.~tmp~%s~%%(workername)s" %(arch[0])), "-avz", "dl/", "%s/" %(rsync_src_url)], + WithProperties("--partial-dir=.~tmp~%s~%%(workername)s" %(arch[0])), "-avz", "dl/", "%s/" %(rsync_src_url)], env={'RSYNC_PASSWORD': rsync_src_key}, haltOnFailure = False, flunkOnFailure = False, diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..a14cc03 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +black==23.3.0 +ruff==0.0.267 -- 2.30.2