Skip to content

Commit

Permalink
build: optimize release build
Browse files Browse the repository at this point in the history
  • Loading branch information
doums committed Jan 12, 2023
1 parent da0d049 commit 2b8529f
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 77 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}
27 changes: 0 additions & 27 deletions .github/workflows/rust.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .pkg/aur/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Maintainer: Pierre Dommerc <[email protected]>

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"
}

54 changes: 54 additions & 0 deletions .pkg/aur/update.sh
Original file line number Diff line number Diff line change
@@ -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
54 changes: 27 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bato"
version = "0.1.6"
version = "0.1.7"
authors = ["pierre <[email protected]>"]
edition = "2021"
links = "notilus"
Expand All @@ -12,3 +12,8 @@ serde_yaml = "0.9"

[build-dependencies]
cmake = "0.1"

[profile.release]
strip = true
opt-level = "s"
lto = true
Loading

0 comments on commit 2b8529f

Please sign in to comment.