Configure CI to build & publish Debian package on release

This commit is contained in:
Benjamin Renard 2025-02-23 10:46:28 +01:00
parent 449f5f51c7
commit f36d7ed93f
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
6 changed files with 132 additions and 5 deletions

7
.chglog.yml Normal file
View file

@ -0,0 +1,7 @@
conventional-commits: false
deb:
distribution: stable
urgency: stable
debug: false
owner: Benjamin Renard <brenard@zionetrix.net>
package-name: aptly-publish

View file

@ -0,0 +1,91 @@
---
name: Build and publish Debian package
on: [create]
jobs:
build:
runs-on: docker
container:
image: docker.io/brenard/nfpm:latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Debian package
run: |
echo "${{ secrets.GPG_KEY }}" | base64 -d > key.gpg
VERSION="$( git describe --tags | sed 's/^[^0-9]*//' )" yq eval '.version = strenv(VERSION)' nfpm.yaml -i
yq eval '.deb.signature.key_file = "key.gpg"' nfpm.yaml -i
yq eval '.maintainer = "${{ vars.MAINTAINER_NAME }} <${{ vars.MAINTAINER_EMAIL }}>"' nfpm.yaml -i
yq eval '.deb.distribution = "${{ vars.DEBIAN_CODENAME }}"' .chglog.yml -i
cat nfpm.yaml
chglog init
mkdir dist
chglog format --template release -o dist/release_notes.md
nfpm -f nfpm.yaml package --packager deb --target dist
cp aptly-publish dist
- 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 aptly-publish 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 }}

View file

@ -5,13 +5,17 @@ jobs:
test-precommit: test-precommit:
runs-on: docker runs-on: docker
container: container:
image: docker.io/brenard/python-pre-commit:latest image: docker.io/library/node:16-alpine
steps: steps:
- name: Install tests dependencies
run: apk -Uuv add python3 py3-requests py3-urllib3 py3-pip py3-debian py3-chardet py3-pylint git bash
- name: Install pre-commit
run: pip install pre-commit
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Install python dependencies
run: python3 -m pip install --break-system-packages debian-parser requests urllib3
- name: Run pre-commit - name: Run pre-commit
run: pre-commit run --all-files run: |
git config --global --add safe.directory "$(pwd)"
pre-commit run --all-files || { cat /root/.cache/pre-commit/pre-commit.log; exit 1; }

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
*~ *~
/venv /venv
/dist /dist
/changelog.yml
*.gpg

View file

@ -50,7 +50,7 @@ repos:
hooks: hooks:
- id: pylint - id: pylint
name: pylint name: pylint
entry: pylint entry: python3 -m pylint
language: system language: system
types: [python] types: [python]
require_serial: true require_serial: true

23
nfpm.yaml Normal file
View file

@ -0,0 +1,23 @@
# yaml-language-server: $schema=https://nfpm.goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
name: aptly-publish
arch: all
platform: linux
version: 2025.2.1
section: devel
priority: optional
depends:
- python3
- python3-requests
- python3-urllib3
- python3-debian
maintainer: Benjamin Renard <brenard@zionetrix.net>
description: Tool to publish one (or more) Debian package on a Aptly repository using its API
homepage: https://gitea.zionetrix.net/bn8/aptly-publish
license: GPL-3
# Changelog YAML file, see: https://github.com/goreleaser/chglog
changelog: changelog.yml
contents:
- src: ./aptly-publish
dst: /usr/bin