Skip to content

Commit

Permalink
Build dpkg (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
boonya authored Oct 14, 2020
1 parent 331fc30 commit 86519bf
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
79 changes: 79 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build

on: push

env:
PACKAGE_ROOT: pkg-src
PACKAGE: raspi-fan-control
DESC: "RaspberryPI Cooling Fan Control Service."
MAINTAINER: "Serhii [boonya] Buinytskyi <me@boonya.info>"
ARCH: arm64

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Retrieve latest package version
run: |
TYPE=$(echo ${{github.ref}} | cut -d'/' -f 2)
LABEL=$(echo ${{github.ref}} | cut -d'/' -f 3)
if [[ "$TYPE" == "tags" ]]; then
echo "LATEST_PKG_VERSION=$LABEL" >> $GITHUB_ENV
# echo "::set-output name=latest_pkg_version::$LABEL"
else
git fetch --tags
LATEST_PKG_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))-$LABEL
echo "LATEST_PKG_VERSION=$LATEST_PKG_VERSION" >> $GITHUB_ENV
# echo "::set-output name=latest_pkg_version::$LATEST_PKG_VERSION"
fi;
- name: Create package source
run: |
mkdir -p ${{env.PACKAGE_ROOT}}/usr/bin
cp main.py ${{env.PACKAGE_ROOT}}/usr/bin/raspi-fan-control
mkdir -p ${{env.PACKAGE_ROOT}}/etc/systemd/system/
cp raspi-fan-control.service ${{env.PACKAGE_ROOT}}/etc/systemd/system/raspi-fan-control.service
PYTHON_PACKAGES=$(cat requirements.txt | xargs)
sed -i "s/{{python-packages}}/$PYTHON_PACKAGES/" ${{env.PACKAGE_ROOT}}/DEBIAN/postinst
sed -i "s/{{python-packages}}/$PYTHON_PACKAGES/" ${{env.PACKAGE_ROOT}}/DEBIAN/postrm
- name: Build package
id: build
uses: jiro4989/build-deb-action@v2
with:
package: ${{env.PACKAGE}}
desc: ${{env.DESC}}
maintainer: ${{env.MAINTAINER}}
package_root: ${{env.PACKAGE_ROOT}}
arch: 'arm64'
# version: ${{steps.vars.outputs.latest_pkg_version}}
version: ${{env.LATEST_PKG_VERSION}}
- name: Upload package artifact
uses: actions/upload-artifact@v2
with:
path: "*.deb"
- name: Retrieve package name
run: |
PKG=$(ls *.deb)
echo "PKG=$PKG" >> $GITHUB_ENV
- name: Create Draft Release
uses: actions/create-release@v1
if: startsWith(github.ref, 'refs/tags/')
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{steps.create_release.outputs.upload_url}}
asset_path: ${{env.PKG}}
asset_name: ${{env.PKG}}
asset_content_type: application/vnd.debian.binary-package
8 changes: 8 additions & 0 deletions pkg-src/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

set -e

pip3 install {{python-packages}}
sudo systemctl daemon-reload
systemctl start raspi-fan-control || echo "Can't start service"
systemctl enable raspi-fan-control || echo "Can't enable service"
5 changes: 5 additions & 0 deletions pkg-src/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -e

pip3 uninstall {{python-packages}}
6 changes: 6 additions & 0 deletions pkg-src/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -e

systemctl disable raspi-fan-control || echo "Can't disable service"
systemctl stop raspi-fan-control || echo "Can't stop service"
1 change: 0 additions & 1 deletion raspi-fan-control.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Description=RaspberryPI Cooling Fan Control Service
Documentation=https://github.com/boonya/raspi-fan-control

[Service]
WorkingDirectory=/usr/local/raspi-fan-control
ExecStart=/usr/bin/raspi-fan-control
TimeoutStartSec=30
Restart=always
Expand Down

0 comments on commit 86519bf

Please sign in to comment.