From ba0f972b34093b00ce0460515fc0bcaa9f1b5e43 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 15 Jul 2024 19:48:49 +0200 Subject: [PATCH] Configure CI to run tests and build/publish new release --- .forgejo/workflows/release.yaml | 86 +++++++++++++++++++++++++++++++++ .forgejo/workflows/tests.yaml | 14 ++++++ .gitignore | 2 + .pre-commit-config.yaml | 2 +- build.sh | 63 ++++++++++++++++++++++++ debian/compat | 1 + debian/control | 12 +++++ debian/copyright | 20 ++++++++ debian/dirs | 1 + debian/install | 1 + debian/rules | 4 ++ debian/source/format | 1 + 12 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 .forgejo/workflows/release.yaml create mode 100644 .forgejo/workflows/tests.yaml create mode 100644 .gitignore create mode 100755 build.sh create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/dirs create mode 100644 debian/install create mode 100755 debian/rules create mode 100644 debian/source/format diff --git a/.forgejo/workflows/release.yaml b/.forgejo/workflows/release.yaml new file mode 100644 index 0000000..be6dc42 --- /dev/null +++ b/.forgejo/workflows/release.yaml @@ -0,0 +1,86 @@ +--- +name: Build and publish Debian package +on: [create] +jobs: + build: + runs-on: docker + container: + image: docker.io/brenard/debian-python-deb:latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Build Debian package + env: + MAINTAINER_NAME: ${{ vars.MAINTAINER_NAME }} + MAINTAINER_EMAIL: ${{ vars.MAINTAINER_EMAIL }} + DEBIAN_CODENAME: ${{ vars.DEBIAN_CODENAME }} + run: | + echo "${{ secrets.GPG_KEY }}" | base64 -d | gpg --import + ./build.sh + - name: Upload Debian package files + uses: actions/upload-artifact@v3 + with: + name: dist + path: | + dist + + publish-forgejo: + runs-on: docker + container: + image: docker.io/brenard/debian-python-deb:latest + needs: + - build + steps: + - name: Download Debian package files + uses: actions/download-artifact@v3 + with: + name: dist + + - name: Create the release + id: create-release + shell: bash + run: | + mkdir release + mv *.deb release/ + mv check-*/check_* release/ + md5sum release/* > md5sum.txt + sha512sum release/* > sha512sum.txt + mv md5sum.txt sha512sum.txt release/ + { + echo 'release_note<> "$GITHUB_OUTPUT" + + - name: Publish release on Forgejo + uses: actions/forgejo-release@v2 + with: + direction: upload + url: https://gitea.zionetrix.net + token: ${{ secrets.forgejo_token }} + release-dir: release + release-notes: ${{ steps.create-release.outputs.release_note }} + + publish-aptly: + runs-on: docker + container: + image: docker.io/brenard/aptly-publish:latest + needs: + - build + steps: + - name: "Download Debian package files" + uses: actions/download-artifact@v3 + with: + name: dist + + - name: "Publish Debian package on Aptly repository" + uses: https://gitea.zionetrix.net/bn8/aptly-publish@master + with: + api_url: ${{ vars.apt_api_url }} + api_username: ${{ vars.apt_api_username }} + api_password: ${{ secrets.apt_api_password }} + repo_name: ${{ vars.apt_repo_name }} + path: "./" + source_name: ${{ vars.apt_source_name }} diff --git a/.forgejo/workflows/tests.yaml b/.forgejo/workflows/tests.yaml new file mode 100644 index 0000000..e06551d --- /dev/null +++ b/.forgejo/workflows/tests.yaml @@ -0,0 +1,14 @@ +--- +name: Run tests +on: [push] +jobs: + tests: + runs-on: docker + container: + image: docker.io/brenard/python-pre-commit:latest + options: "--workdir /src" + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Run pre-commit + run: pre-commit run --all-files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b35e5c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +/.env diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ee9ee93..b581460 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: - --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf" - --quiet-level=2 - --ignore-regex=.*codespell-ignore$ - #- --write-changes # Uncomment to write changes + # - --write-changes # Uncomment to write changes exclude_types: [csv, json] - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.7.1 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..33b594a --- /dev/null +++ b/build.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +QUIET_ARG="" +[[ "$1" == "--quiet" ]] && QUIET_ARG="--quiet" + +# Enter source directory +cd "$( dirname "$0" )" || exit + +CHECK_FILE="$( find "." -name 'check_*' ! -name '*~' -type f -executable | head -n 1 )" +PACKAGE_NAME="$( basename "$CHECK_FILE" | tr '_' '-' )" + +echo "Clean previous build..." +rm -fr dist + +echo "Detect version using git describe..." +VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )" + +echo "Create building environemt..." +BDIR="dist/$PACKAGE_NAME-$VERSION" +mkdir -p "$BDIR" +RSYNC_ARG="" +[[ -z "$QUIET_ARG" ]] && RSYNC_ARG="-v" +rsync -a "$RSYNC_ARG" debian/ "$BDIR/debian/" +cp "$CHECK_FILE" "$BDIR/" + +echo "Set VERSION=$VERSION in gitdch using sed..." +sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$BDIR/$( basename "$CHECK_FILE" )" + +if [[ -z "$DEBIAN_CODENAME" ]]; then + echo "Retrieve debian codename using lsb_release..." + DEBIAN_CODENAME=$( lsb_release -c -s ) +else + echo "Use debian codename from environment ($DEBIAN_CODENAME)" +fi + +echo "Generate debian changelog using gitdch..." +GITDCH_ARGS=('--verbose') +[[ -n "$QUIET_ARG" ]] && GITDCH_ARGS=('--warning') +if [[ -n "$MAINTAINER_NAME" ]]; then + echo "Use maintainer name from environment ($MAINTAINER_NAME)" + GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}") +fi +if [[ -n "$MAINTAINER_EMAIL" ]]; then + echo "Use maintainer email from environment ($MAINTAINER_EMAIL)" + GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL") +fi +gitdch \ + --package-name "$PACKAGE_NAME" \ + --version "${VERSION}" \ + --code-name "$DEBIAN_CODENAME" \ + --output "$BDIR"/debian/changelog \ + --release-notes dist/release_notes.md \ + "${GITDCH_ARGS[@]}" + +if [[ -n "$MAINTAINER_NAME" ]] && [[ -n "$MAINTAINER_EMAIL" ]]; then + echo "Set Maintainer field in debian control file ($MAINTAINER_NAME <$MAINTAINER_EMAIL>)..." + sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" \ + "$BDIR"/debian/control +fi + +echo "Build debian package..." +cd "$BDIR" || exit +dpkg-buildpackage diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..b4de394 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +11 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..86aaa76 --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: check-container-upgrade +Section: admin +Priority: optional +Maintainer: Debian Zionetrix - check-container-upgrade +Build-Depends: debhelper (>> 11.0.0) +Standards-Version: 3.9.6 + +Package: check-container-upgrade +Architecture: all +Depends: ${misc:Depends}, python3, python3-requests +Description: Monitoring plugin to check Postgres Streaming replication state + This Icinga/Nagios check plugin permit to check Postgres Streaming replication state. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..96b2217 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,20 @@ +This package was written by Benjamin Renard . + +Copyright (C) 2024 Benjamin Renard + +check-container-upgrade is licensed under the GNU general public license, version 3. + +check-container-upgrade is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3, or (at your option) any later version. + +check-container-upgrade 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 +check-container-upgrade; see the file COPYING. If not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +On Debian systems, a copy of the GNU General Public License is available in +/usr/share/common-licenses/GPL-3 as part of the base-files package. diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..b073cdc --- /dev/null +++ b/debian/dirs @@ -0,0 +1 @@ +usr/lib/nagios/plugins diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..88c5032 --- /dev/null +++ b/debian/install @@ -0,0 +1 @@ +check_container_upgrade usr/lib/nagios/plugins diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..7451f59 --- /dev/null +++ b/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f +#export DH_VERBOSE=1 +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..d3827e7 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +1.0