Skip to content

Commit

Permalink
CI: generate PKGBUILD based on the git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
BartSte committed Nov 6, 2024
1 parent 9591257 commit cae5402
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 18 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ jobs:
aur-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2

- name: Generate PKGBUILD
run: |
deploy/make-pgkbuild ${{ github.ref }} > PKGBUILD
- name: Publish AUR package
uses: KSXGitHub/[email protected]
Expand Down
34 changes: 17 additions & 17 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Maintainer: BartSte [email protected]

pkgname=fzf-help
pkgver=2.3.0
pkgrel=1
pkgdesc="Use fzf to select command line options from --help"
arch=('any')
url="https://github.com/BartSte/fzf-help"
license=('MIT')
depends=('fzf' 'bat')
source=("$pkgname::git+https://github.com/BartSte/fzf-help.git")
md5sums=('SKIP')
changelog="CHANGELOG.md"
pkgname=fzf-help
pkgver=0.0.0
pkgrel=1
pkgdesc="Use fzf to select command line options from --help"
arch=('any')
url="https://github.com/BartSte/fzf-help"
license=('MIT')
depends=('fzf' 'bat')
source=("$pkgname::git+https://github.com/BartSte/fzf-help.git")
md5sums=('SKIP')
changelog="CHANGELOG.md"

package() {
cd "$srcdir/$pkgname"
install -Dm644 LICENCE -t "${pkgdir}/usr/share/licenses/${pkgname}"
install -dm755 "${pkgdir}/usr/share/${pkgname}"
cp -dr --no-preserve=ownership {src/*,uninstall} "${pkgdir}/usr/share/${pkgname}"
}
package() {
cd "$srcdir/$pkgname"
install -Dm644 LICENCE -t "${pkgdir}/usr/share/licenses/${pkgname}"
install -dm755 "${pkgdir}/usr/share/${pkgname}"
cp -dr --no-preserve=ownership {src/*,uninstall} "${pkgdir}/usr/share/${pkgname}"
}
82 changes: 82 additions & 0 deletions deploy/make-pkgbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

set -euo pipefail

usage="
Usage: make-pkgbuild <version>
This script emits a PKGBUILD file to stdout.
Options:
-h, --help Show this help message and exit.
"

while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
echo "$usage"
exit 0
;;
*)
break
;;
esac
done

if [[ $# -ne 1 ]]; then
echo "Error: Invalid number of arguments."
echo "$usage"
exit 1
fi

################################################################################
# Ensure the version is in the format of:
# - [0-9]+\.[0-9]+\.[0-9]+
# A leading 'v' is allowed but is removed, otherwise an error is thrown.
################################################################################
assert_version() {
local version="$1"
if [[ ! "$version" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format: $version" >&2
exit 1
else
sed 's/^v//' <<< "$version"
fi
}

################################################################################
# Generate
# The version for the PKGBUILD is read from stdin.
################################################################################
generate() {
local version
version="$(cat -)"

if [[ -z "$version" ]]; then
echo "Error: Version is invalid." >&2
exit 1
fi

echo "# Maintainer: BartSte [email protected]
pkgname=fzf-help
pkgver=$version
pkgrel=1
pkgdesc=\"Use fzf to select command line options from --help\"
arch=('any')
url=\"https://github.com/BartSte/fzf-help\"
license=('MIT')
depends=('fzf' 'bat')
source=(\"\$pkgname::git+https://github.com/BartSte/fzf-help.git\")
md5sums=('SKIP')
changelog=\"CHANGELOG.md\"
package() {
cd \"\$srcdir/\$pkgname\"
install -Dm644 LICENCE -t \"\${pkgdir}/usr/share/licenses/\${pkgname}\"
install -dm755 \"\${pkgdir}/usr/share/\${pkgname}\"
cp -dr --no-preserve=ownership {src/*,uninstall} \"\${pkgdir}/usr/share/\${pkgname}\"
}"
}

assert_version "$1" | generate

0 comments on commit cae5402

Please sign in to comment.