From 08b33f5dafe0a64f4f397b2053f4c18b3a9e3d2d Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 15 Jul 2024 15:39:38 +0200 Subject: [PATCH] Configure CI to build & publish new release --- .forgejo/workflows/release.yaml | 85 +++++++++++++++++++++++++++++++++ .gitignore | 1 + .yamllint.yml | 7 +++ build.sh | 59 +++++++++++++++++++++++ debian/compat | 1 + debian/control | 12 +++++ debian/copyright | 20 ++++++++ debian/dirs | 1 + debian/install | 1 + debian/rules | 4 ++ debian/source/format | 1 + 11 files changed, 192 insertions(+) create mode 100644 .forgejo/workflows/release.yaml create mode 100644 .yamllint.yml 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..384fca6 --- /dev/null +++ b/.forgejo/workflows/release.yaml @@ -0,0 +1,85 @@ +--- +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-pg-streaming-replication-*/check_pg_streaming_replication 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 }} + verbose: true + override: true + + 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/.gitignore b/.gitignore index b25c15b..b35e5c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +/.env diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..937d3d5 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,7 @@ +--- +extends: default + +rules: + line-length: + max: 100 + level: warning diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..8a67723 --- /dev/null +++ b/build.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +QUIET_ARG="" +[ "$1" == "--quiet" ] && QUIET_ARG="--quiet" + +# Enter source directory +cd "$( dirname "$0" )" || exit + +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/check-pg-streaming-replication-$VERSION +mkdir -p "$BDIR" +[ -z "$QUIET_ARG" ] && RSYNC_ARG="-v" || RSYNC_ARG="" +rsync -a "$RSYNC_ARG" debian/ "$BDIR"/debian/ +cp check_pg_streaming_replication "$BDIR"/ + +echo "Set VERSION=$VERSION in gitdch using sed..." +sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$BDIR"/check_pg_streaming_replication + +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 check-pg-streaming-replication \ + --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..8ae6deb --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: check-pg-streaming-replication +Section: admin +Priority: optional +Maintainer: Debian Zionetrix - check-pg-streaming-replication +Build-Depends: debhelper (>> 11.0.0) +Standards-Version: 3.9.6 + +Package: check-pg-streaming-replication +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..7e7ff72 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,20 @@ +This package was written by Benjamin Renard . + +Copyright (C) 2024 Benjamin Renard + +check-pg-streaming-replication is licensed under the GNU general public license, version 3. + +check-pg-streaming-replication 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-pg-streaming-replication 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-pg-streaming-replication; 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..7f3af30 --- /dev/null +++ b/debian/install @@ -0,0 +1 @@ +check_pg_streaming_replication 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