feat: initial commit
This commit is contained in:
commit
a72b3ce334
1 changed files with 56 additions and 0 deletions
56
action.yml
Normal file
56
action.yml
Normal file
|
@ -0,0 +1,56 @@
|
|||
---
|
||||
|
||||
name: Build Python Debian packages
|
||||
description: Build a Debian package from a setuptools-based Python project
|
||||
inputs:
|
||||
python_module:
|
||||
description: Name of the Python root module.
|
||||
required: true
|
||||
package_name:
|
||||
description: Name of the Debian package to build.
|
||||
required: true
|
||||
package_root:
|
||||
description: Root of the directory where to build the package in. Additional files may already be here.
|
||||
required: true
|
||||
package_maintainer:
|
||||
description: Name and email address of the package maintainer, used in the changelog file.
|
||||
required: true
|
||||
architecture:
|
||||
description: Architecture for which this package is built. Only relevant for the resulting filename.
|
||||
default: all
|
||||
runs:
|
||||
using: docker
|
||||
image: docker.io/library/debian:bookworm
|
||||
entrypoint: /bin/bash
|
||||
args:
|
||||
- -c
|
||||
- |
|
||||
apt update; apt install -y python3-pip lintian rsync
|
||||
export VERSION=$(python3 -c 'import ${{ inputs.python_module }}; print(${{ inputs.python_module }}.__version)')
|
||||
mkdir -p \
|
||||
${{ inputs.package_root }}/usr/lib/python3/dist-packages/
|
||||
${{ inputs.package_root }}/usr/share/doc/${{ inputs.package_name }}/
|
||||
echo -n > ${{ inputs.package_root }}/usr/share/doc/${{ inputs.package_name }}/changelog
|
||||
for version in "$(cat CHANGELOG.md | grep '<!-- BEGIN CHANGES' | cut -d ' ' -f 4)"; do
|
||||
echo -e "${{ inputs.package_name }} (${version}-1); urgency=medium\n" >> ${{ inputs.package_root }}/usr/share/doc/${{ inputs.package_name }}/changelog
|
||||
cat CHANGELOG.md | grep -A 1000 "<"'!'"-- BEGIN CHANGES ${version} -->" | grep -B 1000 "<"'!'"-- END CHANGES ${version} -->" | tail -n +2 | head -n -1 | sed -re 's/^-/ */g' >> ${{ inputs.package_root }}/usr/share/doc/${{ inputs.package_name }}/changelog
|
||||
echo -e "\n -- ${{ inputs.package_maintainer }} $(date -R)\n" >> ${{ inputs.package_root }}/usr/share/doc/${{ inputs.package_name }}/changelog
|
||||
done
|
||||
gzip -9n ${{ inputs.package_root }}/usr/share/doc/${{ inputs.package_name }}/changelog
|
||||
# Some versions of setuptools ingore --prefix and always set it to /usr/local.
|
||||
# That's why it's set to /usr/local explicitly here and moved afterwards.
|
||||
python3 setup.py egg_info install --root=${{ inputs.package_root }} --prefix=/usr/local --optimize=1
|
||||
rsync -a ${{ inputs.package_root }}/usr/local/lib/python3.11/dist-packages/ ${{ inputs.package_root }}/usr/lib/python3/dist-packages/
|
||||
[[ -e ${{ inputs.package_root }}/usr/local/bin ]] && rsync -a ${{ inputs.package_root }}/usr/local/bin/ ${{ inputs.package_root }}/usr/bin/
|
||||
rm -rf ${{ inputs.package_root }}/usr/local/lib/ ${{ inputs.package_root }}/usr/local/bin/
|
||||
find ${{ inputs.package_root }}/usr/lib/python3/dist-packages -name __pycache__ -exec rm -r {} \; 2>/dev/null || true
|
||||
find ${{ inputs.package_root }}/usr/lib/python3/dist-packages -name '*.pyc' -exec rm {} \;
|
||||
[[ -f ${{ inputs.package_root }}/DEBIAN/preinst ]] && chmod +x ${{ inputs.package_root }}/DEBIAN/preinst
|
||||
[[ -f ${{ inputs.package_root }}/DEBIAN/postinst ]] && chmod +x ${{ inputs.package_root }}/DEBIAN/postinst
|
||||
[[ -f ${{ inputs.package_root }}/DEBIAN/prerm ]] && chmod +x ${{ inputs.package_root }}/DEBIAN/prerm
|
||||
[[ -f ${{ inputs.package_root }}/DEBIAN/postrm ]] && chmod +x ${{ inputs.package_root }}/DEBIAN/postrm
|
||||
sed -re "s/__VERSION__/${VERSION}-1/g" -i ${{ inputs.package_root }}/DEBIAN/control
|
||||
cd "${{ inputs.package_root }}/.."
|
||||
dpkg-deb --build $(basename ${{ inputs.package_root }})
|
||||
mv "$(basename ${{ inputs.package_root }}).deb" "${{ inputs.package_output_path }}/${{ inputs.package_name }}_${VERSION}-1_${{ inputs.architecture }}.deb"
|
||||
sudo -u nobody lintian "${{ inputs.package_name}}_${VERSION}-1_${{ inputs.architecture }}.deb" || true
|
Loading…
Reference in a new issue