commit 9b3366bb9d729f9b930acde911065ee1b2961898 Author: Benjamin Renard Date: Sun Mar 10 12:06:16 2024 +0100 Initial release diff --git a/.forgejo/workflows/release.yaml b/.forgejo/workflows/release.yaml new file mode 100644 index 0000000..ff2fcf4 --- /dev/null +++ b/.forgejo/workflows/release.yaml @@ -0,0 +1,54 @@ +--- +name: Build and publish forgejo-runner 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 + - name: Build Debian package + run: | + echo "${{ secrets.GPG_KEY }}"|base64 -d|gpg --import + export MAINTAINER_NAME="${{ secrets.MAINTAINER_NAME }}" + export MAINTAINER_EMAIL="${{ secrets.MAINTAINER_EMAIL }}" + export DEBIAN_CODENAME="${{ secrets.DEBIAN_CODENAME }}" + ./build.sh --install-deps --debug + - name: Upload Debian package files + uses: actions/upload-artifact@v4 + with: + name: dist + path: | + dist/*.buildinfo + dist/*.changes + dist/*.deb + dist/*.dsc + dist/*.tar.gz + dist/release_notes.md + + publish-forgejo: + runs-on: docker + container: + image: docker.io/brenard/debian-python-deb:latest + steps: + - name: Download Debian package files + uses: actions/download-artifact@v4 + with: + name: dist + + - name: Create the release + id: publish-release-notes + run: | + mkdir dist/release + mv dist/*.deb dist/release/ + value< /dev/stderr + echo "Usage: $0 [-x] [-I]" + echo " -I/--install-deps Install build dependencies" + echo " -q/--quiet Enable quiet mode" + echo " -x/--debug Enable debug mode" + [ -n "$@" ] && exit 1 +} + +idx=1 +while [ $idx -le $# ] +do + OPT=${!idx} + case $OPT in + -I|--install-deps) + INSTALL_DEPS=1 + ;; + -q|--quiet) + QUIET_ARG="--quiet" + ;; + -x|--debug) + set -x + DEBUG=1 + ;; + *) + usage "Unkown parameter '$OPT'" + esac + let idx=idx+1 +done + +# Enter source directory +cd $( dirname $0 ) + +# Install build dependencies +if [ $INSTALL_DEPS -eq 1 ] +then + echo "Install build dependencies..." + apt-get update + apt-get install --no-install-recommends --yes \ + $(grep Build-Depends debian/control|sed 's/Build-Depends: //'|sed 's/([^)]\+)//'|tr -d ',') +fi + +echo "Clean previous build..." +rm -fr dist + +echo "Detect version using git describe..." +[ $DEBUG -eq 1 ] && git show +VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )-0" + +echo "Create building environment..." +BDIR=dist/forgejo-runner-$VERSION +mkdir -p $BDIR +[ -z "$QUIET_ARG" ] && RSYNC_ARG="-v" || RSYNC_ARG="" +rsync -a $RSYNC_ARG debian/ $BDIR/debian/ + +echo "Download forgejo-runner binary..." +[ -n "$QUIET_ARG" ] && CURL_ARG="--silent" || CURL_ARG="" +curl $CURL_ARG --location -o $BDIR/forgejo-runner \ + https://code.forgejo.org/forgejo/runner/releases/download/v$VERSION/forgejo-runner-$VERSION-linux-amd64 + +echo "Generate forgejo-runner configuration example file..." +chmod 755 $BDIR/forgejo-runner +$BDIR/forgejo-runner generate-config > $BDIR/config.yml + +echo "Adjust forgejo configuration file..." +sed -i 's#^\( *file:\).*#\1 /etc/forgejo-runner/.runner#' $BDIR/config.yml +sed -i 's#^\( *dir:\).*#\1 /var/cache/forgejo-runner#' $BDIR/config.yml +sed -i 's|^\( *\)envs:.*|\1# envs:|' $BDIR/config.yml +sed -i 's|^\( *\)\( A_TEST_ENV.*\)|\1# \2|' $BDIR/config.yml + +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 forgejo-runner \ + --version "${VERSION}" \ + --code-name $DEBIAN_CODENAME \ + --output $BDIR/debian/changelog \ + --release-notes dist/release_notes.md \ + "${GITDCH_ARGS[@]}" + +BUILD_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 +else + echo "Maintainer email not found in environment, disable signing." + BUILD_ARGS="--no-sign" +fi + +echo "Build debian package..." +cd $BDIR +dpkg-buildpackage $BUILD_ARGS + 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..bd6ce94 --- /dev/null +++ b/debian/control @@ -0,0 +1,14 @@ +Source: forgejo-runner +Section: admin +Priority: optional +Maintainer: Debian Zionetrix - forgejo-runner +Build-Depends: debhelper (>> 11.0.0), curl, lsb-release, git, rsync, gitdch, sed +Standards-Version: 3.9.6 + +Package: forgejo-runner +Architecture: amd64 +Depends: ${misc:Depends} +Description: Forgejo runner daemon + Forgejo is a self-hosted lightweight software forge. + This package contain a daemon that connects to a Forgejo instance and runs jobs for + continous integration. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..cb6460c --- /dev/null +++ b/debian/copyright @@ -0,0 +1,30 @@ +This package was debianized by Benjamin Renard +on Sun, 10 Mar 2024 11:48:52 +0100. + +Copyright: + + Copyright (c) 2023 The Forgejo Authors + Copyright (c) 2022 The Gitea Authors + +License: + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +The Debian packaging is (C) 2024, Benjamin Renard and +is licensed under the GPL version 3, see '/usr/share/common-licenses/GPL-3'. diff --git a/debian/forgejo-runner.install b/debian/forgejo-runner.install new file mode 100644 index 0000000..f46cd17 --- /dev/null +++ b/debian/forgejo-runner.install @@ -0,0 +1,2 @@ +forgejo-runner usr/bin/ +config.yml etc/forgejo-runner/ diff --git a/debian/forgejo-runner.preinst b/debian/forgejo-runner.preinst new file mode 100644 index 0000000..e3aca57 --- /dev/null +++ b/debian/forgejo-runner.preinst @@ -0,0 +1,50 @@ +#!/bin/bash + +SERVER_HOME=/var/cache/forgejo-runner +SERVER_USER=forgejo-runner +SERVER_NAME="Forgejo runner" +SERVER_GROUP=forgejo-runner + +case "$1" in + install|upgrade) + + # Create group if not existing + if ! getent group | grep -q "^$SERVER_GROUP:" ; then + echo -n "Adding group $SERVER_GROUP..." + addgroup --quiet --system $SERVER_GROUP 2>/dev/null ||true + echo " done." + fi + + # Create homedir if not existing + test -d $SERVER_HOME || mkdir $SERVER_HOME + + # Create user if not existing + if ! getent passwd | grep -q "^$SERVER_USER:"; then + echo -n "Adding system user $SERVER_USER..." + adduser --quiet \ + --system \ + --ingroup $SERVER_GROUP \ + --home $SERVER_HOME \ + --no-create-home \ + --disabled-password \ + $SERVER_USER 2>/dev/null || true + echo " done." + fi + + # Adjust file and directory permissions + if ! dpkg-statoverride --list $SERVER_HOME >/dev/null + then + chown -R $SERVER_USER:adm $SERVER_HOME + chmod u=rwx,g=rxs,o= $SERVER_HOME + fi + + # Add user to docker group (if exists) + if getent group docker >/dev/null + then + adduser $SERVER_USER docker + fi + + ;; +esac + +#DEBHELPER# diff --git a/debian/forgejo-runner.service b/debian/forgejo-runner.service new file mode 100644 index 0000000..8886be3 --- /dev/null +++ b/debian/forgejo-runner.service @@ -0,0 +1,16 @@ +[Unit] +Description=Forgejo Runner +After=syslog.target +After=network.target + +[Service] +RestartSec=2s +Type=simple +User=forejo-runner +Group=forgejo-runner +WorkingDirectory=/var/cache/forgejo-runner/ +ExecStart=/usr/bin/forgejo-runner daemon --config /etc/forgejo-runner/config.yml +Restart=on-failure + +[Install] +WantedBy=multi-user.targe diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..e793b4a --- /dev/null +++ b/debian/rules @@ -0,0 +1,5 @@ +#!/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/last_release.txt b/last_release.txt new file mode 100644 index 0000000..15a2799 --- /dev/null +++ b/last_release.txt @@ -0,0 +1 @@ +3.3.0 diff --git a/publish_new_release.sh b/publish_new_release.sh new file mode 100755 index 0000000..5e4537a --- /dev/null +++ b/publish_new_release.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +ROOT_DIR=$( dirname $( realpath $0 ) ) + +set -e + +LATEST="$1" + +if [ -z "$LATEST" ] +then + echo -n "Getting latest release..." + LATEST=$( curl --silent https://code.forgejo.org/forgejo/runner/tags.rss|xq -x '/rss/channel/item[1]/title'|sed 's/^v//' ) + echo done. +fi + +echo "Latest release: $LATEST" +[ -n "$( git tag -l "$LATEST" )" ] && echo "Release $LATEST already exists" && exit 1 + +echo "Press [enter] to create and publish this new release" +read + +echo "Create new release..." +cd $ROOT_DIR +echo -n "$LATEST" > last_release.txt +git add last_release.txt +git commit -m "Release $LATEST" +git tag "$LATEST" +echo done. + +echo "Publish new release..." +git push +git push --tags +echo done.