diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..f435016 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,76 @@ +name: Deployment + +on: + push: + tags: + - v* + +jobs: + test: + uses: ./.github/workflows/test.yml + + build: + name: Build + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Install libnotify + run: sudo apt-get install libnotify-dev + - name: Build + run: cargo build --release --locked + - name: Upload binary artifact + uses: actions/upload-artifact@v3 + with: + name: bato + path: ./target/release/bato + + gh-release: + name: Publish Github Release + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Download binary artifact + uses: actions/download-artifact@v3 + with: + name: bato + path: ./target/release/ + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: target/release/bato + + aur-packaging: + name: Publish AUR package + needs: gh-release + runs-on: ubuntu-latest + env: + PKG_NAME: bato + PKGBUILD: ./.pkg/aur/PKGBUILD + RELEASE_TAG: ${{ github.ref_name }} + REPOSITORY: ${{ github.repository }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Download sources + run: curl -LfsSo "$PKG_NAME-$RELEASE_TAG".tar.gz "https://github.com/$REPOSITORY/archive/refs/tags/$RELEASE_TAG.tar.gz" + - name: Update PKGBUILD + run: ./.pkg/aur/update.sh + - name: Show PKGBUILD + run: cat "$PKGBUILD" + - name: Publish + uses: KSXGitHub/github-actions-deploy-aur@v2.6.0 + with: + pkgname: ${{ env.PKG_NAME }} + pkgbuild: ${{ env.PKGBUILD }} + commit_username: ${{ secrets.AUR_USERNAME }} + commit_email: ${{ secrets.AUR_EMAIL }} + ssh_private_key: ${{ secrets.AUR_SSH_KEY }} + commit_message: ${{ github.ref_name }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index eaa7b90..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Rust - -on: - push: - tags: - - v* # Push events to v* tags - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install libnotify - run: sudo apt-get install libnotify-dev - - name: Lint - run: cargo clippy - - name: Build - run: cargo build --release --locked - - name: Release - uses: softprops/action-gh-release@v1 - with: - files: target/release/bato - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c7277a2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Test + +on: + workflow_call: + push: + branches: + - master + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy + - name: Install libnotify + run: sudo apt-get install libnotify-dev + - name: Lint + run: cargo clippy + - name: Check + run: cargo check diff --git a/.pkg/aur/PKGBUILD b/.pkg/aur/PKGBUILD new file mode 100644 index 0000000..34dfe33 --- /dev/null +++ b/.pkg/aur/PKGBUILD @@ -0,0 +1,27 @@ +# Maintainer: Pierre Dommerc + +pkgname=bato +pkgver=0.1.0 +pkgrel=1 +pkgdesc='Small program to send battery notifications' +arch=('x86_64') +url='https://github.com/doums/bato' +license=('MPL2') +depends=('libnotify') +makedepends=('rust' 'cargo' 'cmake') +provides=('bato') +conflicts=('bato') +source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz") +sha256sums=('xxx') + +build() { + cd "$pkgname-$pkgver" + cargo build --release --locked +} + +package() { + cd "$pkgname-$pkgver" + install -Dvm 755 "target/release/bato" "$pkgdir/usr/bin/bato" + install -Dvm 644 "bato.yaml" "$pkgdir/usr/share/doc/bato/config/bato.yaml" +} + diff --git a/.pkg/aur/update.sh b/.pkg/aur/update.sh new file mode 100755 index 0000000..471f9bd --- /dev/null +++ b/.pkg/aur/update.sh @@ -0,0 +1,54 @@ +#! /bin/bash + +# script to bump version and update sources hash of a PKGBUILD + +set -e + +red="\e[38;5;1m" +green="\e[38;5;2m" +bold="\e[1m" +reset="\e[0m" + +if [ -z "$PKGBUILD" ]; then + >&2 printf " %b%b✕%b PKGBUILD not set\n" "$red" "$bold" "$reset" + exit 1 +fi + +if [ -z "$PKG_NAME" ]; then + >&2 printf " %b%b✕%b PKG_NAME not set\n" "$red" "$bold" "$reset" + exit 1 +fi + +if [ -z "$RELEASE_TAG" ]; then + >&2 printf " %b%b✕%b RELEASE_TAG not set\n" "$red" "$bold" "$reset" + exit 1 +fi + +if ! [ -a "$PKGBUILD" ]; then + >&2 printf " %b%b✕%b no such file $PKGBUILD\n" "$red" "$bold" "$reset" + exit 1 +fi + +if ! [[ "$RELEASE_TAG" =~ ^v.*? ]]; then + >&2 printf " %b%b✕%b invalid tag $RELEASE_TAG\n" "$red" "$bold" "$reset" + exit 1 +fi + +pkgver="${RELEASE_TAG#v}" +tarball="$PKG_NAME-$RELEASE_TAG".tar.gz + +if ! [ -a "$tarball" ]; then + >&2 printf " %b%b✕%b no such file $tarball\n" "$red" "$bold" "$reset" + exit 1 +fi + +# bump package version +sed -i "s/pkgver=.*/pkgver=$pkgver/" "$PKGBUILD" +printf " %b%b✓%b bump version to $RELEASE_TAG\n" "$green" "$bold" "$reset" + +# generate new checksum +sum=$(set -o pipefail && sha256sum "$tarball" | awk '{print $1}') +sed -i "s/sha256sums=('.*')/sha256sums=('$sum')/" "$PKGBUILD" +printf " %b%b✓%b generated checksum $sum\n" "$green" "$bold" "$reset" + +exit 0 diff --git a/Cargo.lock b/Cargo.lock index 7508960..be03be3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bato" -version = "0.1.6" +version = "0.1.7" dependencies = [ "cmake", "serde", @@ -19,15 +19,15 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.73" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "cmake" -version = "0.1.48" +version = "0.1.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" +checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c" dependencies = [ "cc", ] @@ -40,9 +40,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", @@ -50,48 +50,48 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "serde" -version = "1.0.143" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.143" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", @@ -100,9 +100,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.4" +version = "0.9.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79b7c9017c64a49806c6e8df8ef99b92446d09c92457f85f91835b01a8064ae0" +checksum = "92b5b431e8907b50339b51223b97d102db8d987ced36f6e4d03621db9316c834" dependencies = [ "indexmap", "itoa", @@ -113,9 +113,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.99" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -124,12 +124,12 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unsafe-libyaml" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "931179334a56395bcf64ba5e0ff56781381c1a5832178280c7d7f91d1679aeb0" +checksum = "bc7ed8ba44ca06be78ea1ad2c3682a43349126c8818054231ee6f4748012aed2" diff --git a/Cargo.toml b/Cargo.toml index 8df91a8..e1943f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bato" -version = "0.1.6" +version = "0.1.7" authors = ["pierre "] edition = "2021" links = "notilus" @@ -12,3 +12,8 @@ serde_yaml = "0.9" [build-dependencies] cmake = "0.1" + +[profile.release] +strip = true +opt-level = "s" +lto = true diff --git a/README.md b/README.md index e17d109..d461532 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -[![bato](https://img.shields.io/github/actions/workflow/status/doums/bato/rust.yml?color=0D0D0D&logoColor=BFBFBF&labelColor=404040&logo=github&style=for-the-badge)](https://github.com/doums/bato/actions?query=workflow%3ARust) +[![bato](https://img.shields.io/github/actions/workflow/status/doums/bato/test.yml?color=0D0D0D&logoColor=BFBFBF&labelColor=404040&logo=github&style=for-the-badge)](https://github.com/doums/bato/actions?query=workflow%3Atest) [![bato](https://img.shields.io/aur/version/bato?color=0D0D0D&logoColor=BFBFBF&labelColor=404040&logo=arch-linux&style=for-the-badge)](https://aur.archlinux.org/packages/bato/) ## bato -Small program to send **bat**tery n**o**tifications. Coded in Rust (and C). +Small program to send **bat**tery n**o**tifications. ![bato](https://github.com/doums/bato/blob/master/img/bato.png) @@ -15,38 +15,36 @@ Small program to send **bat**tery n**o**tifications. Coded in Rust (and C). - [usage](#usage) - [license](#license) -### features +### Features Configuration in YAML. Notification events: -* level full -* level low -* level critical -* charging -* discharging -### prerequisite +- level full +- level low +- level critical +- charging +- discharging + +### Prerequisite - a notification server, like [Dunst](https://dunst-project.org/) - libnotify -### install - -Rust is a language that compiles to native code and by default statically links all dependencies.\ -Simply download the latest [release](https://github.com/doums/bato/releases) of the compiled binary and use it! (do not forget to make it executable `chmod 755 bato`) +### Install -### Arch Linux AUR package +- latest [release](https://github.com/doums/bato/releases/latest) +- AUR [package](https://aur.archlinux.org/packages/bato) -bato is present as a [package](https://aur.archlinux.org/packages/bato) in the Arch User Repository. - -### configuration +### Configuration The binary looks for the config file `bato.yaml` located in `$XDG_CONFIG_HOME/bato/` (default to `$HOME/.config/bato/`).\ If the config file is not found, bato prints an error and exits.\ All options are detailed [here](https://github.com/doums/bato/blob/master/bato.yaml). Example: + ```yaml tick_rate: 1 critical_level: 5 @@ -72,9 +70,10 @@ discharging: icon: battery-good ``` -### usage +### Usage Run bato as a _daemon_. For example launch it from a script + ``` #!/usr/bin/bash @@ -88,7 +87,9 @@ if [ "${#pids[@]}" -gt 0 ]; then fi bato & ``` -and call this script from your windows manager, _autostart_ programs. -### license +Call this script from your window manager, _autostart_ programs. + +### License + Mozilla Public License 2.0 diff --git a/src/lib.rs b/src/lib.rs index 197ce40..d0ace9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -255,7 +255,7 @@ impl<'data> Bato<'data> { fn parse_attribute(line: &io::Result, attribute: &str) -> Option { if let Ok(l) = line { - if l.starts_with(&attribute) { + if l.starts_with(attribute) { let s = l.split('=').nth(1); if let Some(v) = s { return v.parse::().ok(); @@ -267,7 +267,7 @@ fn parse_attribute(line: &io::Result, attribute: &str) -> Option { fn parse_status(line: &io::Result) -> Option { if let Ok(l) = line { - if l.starts_with(&STATUS_ATTRIBUTE) { + if l.starts_with(STATUS_ATTRIBUTE) { return l.split('=').nth(1).map(|s| s.to_string()); } }