Skip to content

Commit 2b8529f

Browse files
committed
build: optimize release build
1 parent da0d049 commit 2b8529f

File tree

9 files changed

+243
-77
lines changed

9 files changed

+243
-77
lines changed

.github/workflows/deploy.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Deployment
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
test:
10+
uses: ./.github/workflows/test.yml
11+
12+
build:
13+
name: Build
14+
runs-on: ubuntu-latest
15+
needs: test
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
- name: Install Rust toolchain
20+
uses: dtolnay/rust-toolchain@master
21+
with:
22+
toolchain: stable
23+
- name: Install libnotify
24+
run: sudo apt-get install libnotify-dev
25+
- name: Build
26+
run: cargo build --release --locked
27+
- name: Upload binary artifact
28+
uses: actions/upload-artifact@v3
29+
with:
30+
name: bato
31+
path: ./target/release/bato
32+
33+
gh-release:
34+
name: Publish Github Release
35+
needs: build
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v3
40+
- name: Download binary artifact
41+
uses: actions/download-artifact@v3
42+
with:
43+
name: bato
44+
path: ./target/release/
45+
- name: Release
46+
uses: softprops/action-gh-release@v1
47+
with:
48+
files: target/release/bato
49+
50+
aur-packaging:
51+
name: Publish AUR package
52+
needs: gh-release
53+
runs-on: ubuntu-latest
54+
env:
55+
PKG_NAME: bato
56+
PKGBUILD: ./.pkg/aur/PKGBUILD
57+
RELEASE_TAG: ${{ github.ref_name }}
58+
REPOSITORY: ${{ github.repository }}
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v3
62+
- name: Download sources
63+
run: curl -LfsSo "$PKG_NAME-$RELEASE_TAG".tar.gz "https://github.com/$REPOSITORY/archive/refs/tags/$RELEASE_TAG.tar.gz"
64+
- name: Update PKGBUILD
65+
run: ./.pkg/aur/update.sh
66+
- name: Show PKGBUILD
67+
run: cat "$PKGBUILD"
68+
- name: Publish
69+
uses: KSXGitHub/[email protected]
70+
with:
71+
pkgname: ${{ env.PKG_NAME }}
72+
pkgbuild: ${{ env.PKGBUILD }}
73+
commit_username: ${{ secrets.AUR_USERNAME }}
74+
commit_email: ${{ secrets.AUR_EMAIL }}
75+
ssh_private_key: ${{ secrets.AUR_SSH_KEY }}
76+
commit_message: ${{ github.ref_name }}

.github/workflows/rust.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test
2+
3+
on:
4+
workflow_call:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
test:
15+
name: Test
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
- name: Install Rust toolchain
21+
uses: dtolnay/rust-toolchain@master
22+
with:
23+
toolchain: stable
24+
components: clippy
25+
- name: Install libnotify
26+
run: sudo apt-get install libnotify-dev
27+
- name: Lint
28+
run: cargo clippy
29+
- name: Check
30+
run: cargo check

.pkg/aur/PKGBUILD

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Maintainer: Pierre Dommerc <[email protected]>
2+
3+
pkgname=bato
4+
pkgver=0.1.0
5+
pkgrel=1
6+
pkgdesc='Small program to send battery notifications'
7+
arch=('x86_64')
8+
url='https://github.com/doums/bato'
9+
license=('MPL2')
10+
depends=('libnotify')
11+
makedepends=('rust' 'cargo' 'cmake')
12+
provides=('bato')
13+
conflicts=('bato')
14+
source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz")
15+
sha256sums=('xxx')
16+
17+
build() {
18+
cd "$pkgname-$pkgver"
19+
cargo build --release --locked
20+
}
21+
22+
package() {
23+
cd "$pkgname-$pkgver"
24+
install -Dvm 755 "target/release/bato" "$pkgdir/usr/bin/bato"
25+
install -Dvm 644 "bato.yaml" "$pkgdir/usr/share/doc/bato/config/bato.yaml"
26+
}
27+

.pkg/aur/update.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#! /bin/bash
2+
3+
# script to bump version and update sources hash of a PKGBUILD
4+
5+
set -e
6+
7+
red="\e[38;5;1m"
8+
green="\e[38;5;2m"
9+
bold="\e[1m"
10+
reset="\e[0m"
11+
12+
if [ -z "$PKGBUILD" ]; then
13+
>&2 printf " %b%b✕%b PKGBUILD not set\n" "$red" "$bold" "$reset"
14+
exit 1
15+
fi
16+
17+
if [ -z "$PKG_NAME" ]; then
18+
>&2 printf " %b%b✕%b PKG_NAME not set\n" "$red" "$bold" "$reset"
19+
exit 1
20+
fi
21+
22+
if [ -z "$RELEASE_TAG" ]; then
23+
>&2 printf " %b%b✕%b RELEASE_TAG not set\n" "$red" "$bold" "$reset"
24+
exit 1
25+
fi
26+
27+
if ! [ -a "$PKGBUILD" ]; then
28+
>&2 printf " %b%b✕%b no such file $PKGBUILD\n" "$red" "$bold" "$reset"
29+
exit 1
30+
fi
31+
32+
if ! [[ "$RELEASE_TAG" =~ ^v.*? ]]; then
33+
>&2 printf " %b%b✕%b invalid tag $RELEASE_TAG\n" "$red" "$bold" "$reset"
34+
exit 1
35+
fi
36+
37+
pkgver="${RELEASE_TAG#v}"
38+
tarball="$PKG_NAME-$RELEASE_TAG".tar.gz
39+
40+
if ! [ -a "$tarball" ]; then
41+
>&2 printf " %b%b✕%b no such file $tarball\n" "$red" "$bold" "$reset"
42+
exit 1
43+
fi
44+
45+
# bump package version
46+
sed -i "s/pkgver=.*/pkgver=$pkgver/" "$PKGBUILD"
47+
printf " %b%b✓%b bump version to $RELEASE_TAG\n" "$green" "$bold" "$reset"
48+
49+
# generate new checksum
50+
sum=$(set -o pipefail && sha256sum "$tarball" | awk '{print $1}')
51+
sed -i "s/sha256sums=('.*')/sha256sums=('$sum')/" "$PKGBUILD"
52+
printf " %b%b✓%b generated checksum $sum\n" "$green" "$bold" "$reset"
53+
54+
exit 0

Cargo.lock

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bato"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors = ["pierre <[email protected]>"]
55
edition = "2021"
66
links = "notilus"
@@ -12,3 +12,8 @@ serde_yaml = "0.9"
1212

1313
[build-dependencies]
1414
cmake = "0.1"
15+
16+
[profile.release]
17+
strip = true
18+
opt-level = "s"
19+
lto = true

0 commit comments

Comments
 (0)