diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..c4476fc --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,12 @@ +name: Build package +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +jobs: + typos: + runs-on: alpine + steps: + - uses: actions/checkout@v4 + - run: deb/build.sh ${{ env.GITHUB_REF_NAME }} ${{ secrets.TOKEN }} diff --git a/deb/app-exporter.service b/deb/app-exporter.service new file mode 100644 index 0000000..58b9f41 --- /dev/null +++ b/deb/app-exporter.service @@ -0,0 +1,11 @@ +[Unit] +Description=Prometheus Application version exporter for the Recycled Cloud +After=network.target + +[Service] +Type=simple +User=root +ExecStart=/usr/local/bin/app-exporter + +[Install] +WantedBy=multi-user.target diff --git a/deb/build.sh b/deb/build.sh new file mode 100755 index 0000000..c57a47b --- /dev/null +++ b/deb/build.sh @@ -0,0 +1,38 @@ +# Variables +package_name=$(head -n1 go.mod | cut -d'/' -f2) +version=$1 + +# deps +apk add dpkg make go curl + +# Structure +deb_folder="${package_name}_${version}-1_amd64" +mkdir -vp \ + "${deb_folder}/usr/local/bin" \ + "${deb_folder}/lib/systemd/system" \ + "${deb_folder}/DEBIAN" + +# Package content +VERSION=$version make build +cp -v "$package_name" "${deb_folder}/usr/local/bin/" +cp -v deb/printer.service "${deb_folder}/lib/systemd/system/" + +# DEBIAN +cat - > "${deb_folder}/DEBIAN/control" < +Description: A Prometheus Application version exporter for the Recycled Cloud +EOF +cp deb/postinst "${deb_folder}/DEBIAN/" +cp deb/prerm "${deb_folder}/DEBIAN/" +cp deb/postrm "${deb_folder}/DEBIAN/" + +# Package +dpkg-deb --build --root-owner-group "$deb_folder" + +curl --fail \ + -H "Authorization: token $2" \ + --upload-file "${deb_folder}.deb" \ + https://code.recycled.cloud/api/packages/RecycledCloud/debian/pool/bookworm/main/upload diff --git a/deb/postinst b/deb/postinst new file mode 100755 index 0000000..c0cca86 --- /dev/null +++ b/deb/postinst @@ -0,0 +1,5 @@ +#!/bin/bash + +systemctl daemon-reload +systemctl enable app-exporter +systemctl start app-exporter diff --git a/deb/postrm b/deb/postrm new file mode 100755 index 0000000..ab20f7b --- /dev/null +++ b/deb/postrm @@ -0,0 +1,3 @@ +#!/bin/bash + +systemctl daemon-reload diff --git a/deb/prerm b/deb/prerm new file mode 100755 index 0000000..098be09 --- /dev/null +++ b/deb/prerm @@ -0,0 +1,4 @@ +#!/bin/bash + +systemctl stop app-exporter +systemctl disable app-exporter