Configure CI to build & publish new release
All checks were successful
Run tests / tests (push) Successful in 1m17s

This commit is contained in:
Benjamin Renard 2024-07-15 15:39:38 +02:00
parent 97f4875aee
commit 4090417ee3
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
12 changed files with 198 additions and 1 deletions

View file

@ -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<<EOF'
cat release_notes.md | sed 's/"/\\"/g'
echo 'EOF'
} >> "$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 }}

1
.gitignore vendored
View file

@ -1 +1,2 @@
*~ *~
/.env

View file

@ -11,7 +11,7 @@ repos:
- --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf" - --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf"
- --quiet-level=2 - --quiet-level=2
- --ignore-regex=.*codespell-ignore$ - --ignore-regex=.*codespell-ignore$
# - --write-changes # Uncomment to write changes # - --write-changes # Uncomment to write changes
exclude_types: [csv, json] exclude_types: [csv, json]
- repo: https://github.com/pre-commit/mirrors-prettier - repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1 rev: v2.7.1

7
.yamllint.yml Normal file
View file

@ -0,0 +1,7 @@
---
extends: default
rules:
line-length:
max: 100
level: warning

63
build.sh Executable file
View file

@ -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

1
debian/compat vendored Normal file
View file

@ -0,0 +1 @@
11

12
debian/control vendored Normal file
View file

@ -0,0 +1,12 @@
Source: check-pg-streaming-replication
Section: admin
Priority: optional
Maintainer: Debian Zionetrix - check-pg-streaming-replication <debian+check-pg-streaming-replication@zionetrix.net>
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.

20
debian/copyright vendored Normal file
View file

@ -0,0 +1,20 @@
This package was written by Benjamin Renard <brenard@zionetrix.net>.
Copyright (C) 2024 Benjamin Renard <brenard@zionetrix.net>
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.

1
debian/dirs vendored Normal file
View file

@ -0,0 +1 @@
usr/lib/nagios/plugins

1
debian/install vendored Normal file
View file

@ -0,0 +1 @@
check_pg_streaming_replication usr/lib/nagios/plugins

4
debian/rules vendored Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/make -f
#export DH_VERBOSE=1
%:
dh $@

1
debian/source/format vendored Normal file
View file

@ -0,0 +1 @@
1.0