ci: add basic config checking with ruff v3
authorPetr Štetiar <ynezz@true.cz>
Tue, 16 May 2023 10:57:56 +0000 (12:57 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 16 May 2023 14:52:33 +0000 (16:52 +0200)
Signed-off-by: Petr Štetiar <ynezz@true.cz>
.github/workflows/build-push.yml
.gitignore
.ruff.toml [new file with mode: 0644]
phase1/master.cfg
phase2/master.cfg
requirements-dev.txt [new file with mode: 0644]

index 666c9e39d6fab4dcafe6d4d11f3928485c210299..b6f1c3c938c51b4bbb0b96b88f80834d354ca5ab 100644 (file)
@@ -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
index 3a2e17936ce51de8de12b7a6c23a367cce29ff92..a94d1d22ede7e410bcb0e5c14b3bb8012fb5142b 100644 (file)
@@ -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 (file)
index 0000000..f419fc5
--- /dev/null
@@ -0,0 +1 @@
+ignore = ["E501"]
index 00d744c09b8a4a51b9ba884d1eef3880a33b0cdd..c392c5f2185de2521b97c887db36222b997f7396 100644 (file)
@@ -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 <commit>
-         # git checkout -f <commit>
-         # git checkout -B <branch>
-         # 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 <commit>
+       # git checkout -f <commit>
+       # git checkout -B <branch>
+       # git rev-parse HEAD
        factory.addStep(Git(
                name = "git",
                repourl = repo_url,
index 8b7df6a8697344966ec8f0e5aeb25f1b1bea8165..e19a7314cc67267d922c81040e09aa146f47f754 100644 (file)
@@ -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 (file)
index 0000000..a14cc03
--- /dev/null
@@ -0,0 +1,2 @@
+black==23.3.0
+ruff==0.0.267