diff --git a/.gitignore b/.gitignore index b25c15b..733412c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +dist diff --git a/.woodpecker.yml b/.woodpecker.yml index 5e364d5..b69dffc 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,8 +1,70 @@ +clone: + git: + image: woodpeckerci/plugin-git + tags: true + pipeline: - test: - image: debian + test-pylint: + group: test + image: pipelinecomponents/pylint commands: - - apt update - - apt install --no-install-recommends -y pylint3 python3-flake8 python3-git git - - python3 -m flake8 gitdch - - python3 -m pylint gitdch + - pylint gitdch + + test-flake8: + group: test + image: pipelinecomponents/flake8 + commands: + - flake8 gitdch + + build: + image: brenard/debian-python-deb + when: + event: tag + commands: + - echo "$GPG_KEY"|base64 -d|gpg --import + - ./build.sh --quiet + - rm -fr dist/gitdch-* + secrets: [ maintainer_name, maintainer_email, gpg_key, debian_codename ] + + publish-dryrun: + group: publish + image: alpine + when: + event: tag + commands: + - ls dist/* + + publish-gitea: + group: publish + image: plugins/gitea-release + when: + event: tag + settings: + api_key: + from_secret: gitea_token + base_url: https://gitea.zionetrix.net + files: + - gitdch + - dist/*.deb + checksum: + - md5 + - sha512 + + publish-apt: + group: publish + image: brenard/curl + when: + event: tag + commands: + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/gitdch_*_all.deb ) $APT_API_URL/files/gitdch + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/gitdch_*.buildinfo ) $APT_API_URL/files/gitdch + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/gitdch_*.changes ) $APT_API_URL/files/gitdch + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/gitdch_*.dsc ) $APT_API_URL/files/gitdch + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/gitdch_*.tar.gz ) $APT_API_URL/files/gitdch + - curl -u $APT_CREDS -X POST $APT_API_URL/repos/$APT_REPO_NAME/include/gitdch + - APT_SNAP_NAME=$(date +%s)_$APT_REPO_NAME + - > + curl -u $APT_CREDS -X POST -H 'Content-Type: application/json' --data "{\"Name\":\"$APT_SNAP_NAME\"}" $APT_API_URL/repos/$APT_REPO_NAME/snapshots + - > + curl -u $APT_CREDS -X PUT -H 'Content-Type: application/json' --data "{\"Snapshots\": [{\"Component\": \"main\", \"Name\": \"$APT_SNAP_NAME\"}]}" $APT_API_URL/publish/:./$APT_REPO_NAME + secrets: [ apt_api_url, apt_creds, apt_repo_name ] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..f6ed6e0 --- /dev/null +++ b/build.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +QUIET_ARG="" +[ "$1" == "--quiet" ] && QUIET_ARG="--quiet" + +# Enter source directory +cd $( dirname $0 ) + +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/gitdch-$VERSION +mkdir -p $BDIR +[ -z "$QUIET_ARG" ] && RSYNC_ARG="-v" || RSYNC_ARG="" +rsync -a $RSYNC_ARG debian/ $BDIR/debian/ +cp gitdch $BDIR/ + +echo "Set VERSION=$VERSION in gitdch using sed..." +sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" $BDIR/gitdch + +if [ -z "$DEBIAN_CODENAME" ] +then + echo "Retreive 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 gitdch \ + --version "${VERSION}" \ + --code-name $DEBIAN_CODENAME \ + --output $BDIR/debian/changelog \ + "${GITDCH_ARGS[@]}" + +if [ -n "$MAINTAINER_NAME" -a -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 +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..b4c2086 --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: gitdch +Section: admin +Priority: optional +Maintainer: Debian Zionetrix - gitdch +Build-Depends: debhelper (>> 11.0.0), python3, git, python3-git +Standards-Version: 3.9.6 + +Package: gitdch +Architecture: all +Depends: ${misc:Depends}, python3, git, python3-git +Description: Generate debian changelog file from git commit history + Simple python script using GitPython library to generate debian + changelog file from git commit history. Each existing tags is + considered as a release version and current working version is + numbered using ''git describe --always --tags'' command. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..89c8dc5 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,20 @@ +This package was written by Benjamin Renard . + +Copyright (C) 2022 Benjamin Renard + +gitdch is licensed under the GNU general public license, version 3. + +gitdch 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 2, or (at your option) any later version. + +gitdch 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 +gitdch; 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..e772481 --- /dev/null +++ b/debian/dirs @@ -0,0 +1 @@ +usr/bin diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..f87e094 --- /dev/null +++ b/debian/install @@ -0,0 +1 @@ +gitdch usr/bin 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 diff --git a/gitdch b/gitdch index 116bdd9..d946f87 100755 --- a/gitdch +++ b/gitdch @@ -10,11 +10,12 @@ import sys import git +VERSION = '0.0' DEFAULT_GIT_PATCH = './' DEFAULT_CODE_NAME = 'unstable' DEFAULT_URGENCY = 'medium' -parser = argparse.ArgumentParser(description=__doc__) +parser = argparse.ArgumentParser(description=f'{__doc__} (version: {VERSION})') parser.add_argument( '-d', '--debug',