Compare commits

...

5 Commits

Author SHA1 Message Date
Benjamin Renard 7f53b8aa56 CI: upgrade syntax
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2024-01-22 01:52:20 +01:00
Benjamin Renard 1c12d4fce5 Improve pre-commit hooks & code cleaning 2024-01-22 01:50:13 +01:00
Benjamin Renard 742e00f24d
debian package: add missing dependency on python3-xmltodict
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-12-19 14:13:58 +01:00
Benjamin Renard 487d38eafe
Upgrade pre-commit hooks and introduce bandit hook
ci/woodpecker/manual/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2023-11-29 18:47:47 +01:00
Benjamin Renard dba77147a5
Consider version with the higther number as the latest release 2023-11-29 18:42:48 +01:00
6 changed files with 88 additions and 39 deletions

View File

@ -1,31 +1,67 @@
# Pre-commit hooks to run tests and ensure code is cleaned.
# See https://pre-commit.com for more information
---
repos:
- repo: local
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: pylint
- id: ruff
args:
- --fix
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--keep-percent-format", "--py37-plus"]
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
args: ["--target-version", "py37", "--line-length", "100"]
- repo: https://github.com/PyCQA/isort
rev: 5.11.5
hooks:
- id: isort
args: ["--profile", "black", "--line-length", "100"]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
args: ["--max-line-length=100"]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args:
- --ignore-words-list=fro,hass
- --skip="./.*,*.csv,*.json,*.ambr"
- --quiet-level=2
exclude_types: [csv, json]
- repo: https://github.com/adrienverge/yamllint
rev: v1.32.0
hooks:
- id: yamllint
args: ["-d {extends: relaxed, rules: {line-length: disable}}", "-s"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
require_serial: true
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
rev: v1.0.5
hooks:
- id: flake8
args: ['--max-line-length=100']
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
- id: python-bandit-vulnerability-check
name: bandit
args: [--skip, "B101", --recursive, mylib]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: pyupgrade
args: ['--keep-percent-format', '--py37-plus']
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
args: ['--target-version', 'py37', '--line-length', '100']
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ['--profile', 'black', '--line-length', '100']
- id: check-executables-have-shebangs
stages: [manual]

View File

@ -3,7 +3,7 @@ clone:
image: woodpeckerci/plugin-git
tags: true
pipeline:
steps:
tests:
image: brenard/python-pre-commit:latest
commands:
@ -15,24 +15,25 @@ pipeline:
image: brenard/debian-python-deb
when:
event: tag
depends_on: [tests]
commands:
- echo "$GPG_KEY"|base64 -d|gpg --import
- ./build.sh --quiet
secrets: [ maintainer_name, maintainer_email, gpg_key, debian_codename ]
secrets: [maintainer_name, maintainer_email, gpg_key, debian_codename]
publish-dryrun:
group: publish
image: alpine
when:
event: tag
depends_on: [build]
commands:
- ls dist/* dist/check-forgejo-upgrade-*/check_forgejo_upgrade
publish-gitea:
group: publish
image: plugins/gitea-release
when:
event: tag
depends_on: [build]
settings:
api_key:
from_secret: gitea_token
@ -46,10 +47,10 @@ pipeline:
- sha512
publish-apt:
group: publish
image: brenard/aptly-publish
when:
event: tag
depends_on: [build]
settings:
api_url:
from_secret: apt_api_url

View File

@ -37,7 +37,6 @@ Copyright (c) 2023 Benjamin Renard <brenard@zionetrix.net>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

View File

@ -24,7 +24,7 @@ sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" $BDIR/check_forgejo_upgrade
if [ -z "$DEBIAN_CODENAME" ]
then
echo "Retreive debian codename using lsb_release..."
echo "Retrieve debian codename using lsb_release..."
DEBIAN_CODENAME=$( lsb_release -c -s )
else
echo "Use debian codename from environment ($DEBIAN_CODENAME)"

View File

@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import argparse
import logging
import re
import subprocess
import subprocess # nosec
import sys
import requests
@ -55,11 +55,11 @@ logging.basicConfig(level=logging.DEBUG if options.debug else logging.WARNING)
CURRENT = None
cmd = [options.path, "--version"]
logging.debug("Command use to retreive current version of Forgejo: %s", " ".join(cmd))
logging.debug("Command use to retrieve current version of Forgejo: %s", " ".join(cmd))
OUTPUT = None
EXCEPTION = None
try:
OUTPUT = subprocess.check_output(cmd)
OUTPUT = subprocess.check_output(cmd) # nosec
logging.debug("Output:\n%s", OUTPUT)
m = re.search("version ([^ ]+) built", OUTPUT.decode("utf8", errors="ignore"))
if m:
@ -69,7 +69,7 @@ except Exception as err: # pylint: disable=broad-except
logging.debug("Current version: %s", CURRENT)
if not CURRENT:
print("UNKNOWN - Fail to retreive current Forgejo")
print("UNKNOWN - Fail to retrieve current Forgejo")
print(f'Command: {" ".join(cmd)}')
print("Output:")
print(OUTPUT if OUTPUT else "")
@ -81,24 +81,37 @@ CURRENT = CURRENT.replace("+", "-")
logging.debug("Cleaned current version: %s", CURRENT)
LATEST = None
LATEST_INT = None
try:
logging.debug("Get releases RSS feed from %s...", options.url)
r = requests.get(options.url, timeout=options.timeout)
logging.debug("Data retreive:\n%s", r.text)
logging.debug("Data retrieve:\n%s", r.text)
data = xmltodict.parse(r.text)
versions = {}
for item in data["rss"]["channel"]["item"]:
version = re.sub("^v", "", item["title"])
if not options.include_rc and "-rc" in version:
logging.debug("Ignore release candidate %s", version)
continue
LATEST = version
break
except Exception: # pylint: disable=broad-except
version_int = int(re.sub(r"[\.-]", "000", version))
logging.debug("Found version %s (%s)", version, version_int)
if not LATEST_INT or LATEST_INT < version_int:
if LATEST:
logging.debug(
"Version %s considered as newer than %s, override latest version",
version,
LATEST,
)
LATEST = version
LATEST_INT = version_int
else:
logging.debug("Version %s considered as oldest than %s", version, LATEST)
except Exception: # pylint: disable=broad-except # nosec
pass
logging.debug("Latest version: %s", LATEST)
if not LATEST:
print("UNKNOWN - Fail to retreive latest Forgejo release from the project RSS feed")
print("UNKNOWN - Fail to retrieve latest Forgejo release from the project RSS feed")
print(f"Current version: {CURRENT}")
sys.exit(3)

2
debian/control vendored
View File

@ -7,7 +7,7 @@ Standards-Version: 3.9.6
Package: check-forgejo-upgrade
Architecture: all
Depends: ${misc:Depends}, python3, python3-requests
Depends: ${misc:Depends}, python3, python3-requests, python3-xmltodict
Description: Monitoring plugin to check Forgejo instance upgrade status
This Icinga/Nagios check plugin permit to check Forgejo instance upgrade
status by comparing the local forgejo binary version against the latest