Skip to content

Commit 4cb65dd

Browse files
committed
Get pkgname from pkgbuild
1 parent 50ce1d5 commit 4cb65dd

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GitHub Actions to publish AUR package.
66

77
### `pkgname`
88

9-
**Required** AUR package name.
9+
**Optional** AUR package name. If not specified the name will be extracted from the PKGBUILD file.
1010

1111
### `pkgbuild`
1212

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ branding:
66
icon: package
77
inputs:
88
pkgname:
9-
description: 'AUR package name'
10-
required: true
9+
description: 'AUR package name, extracted from PKGBUILD if not specified'
10+
required: false
1111
pkgbuild:
1212
description: 'Path to PKGBUILD file'
1313
required: true

build.sh

+19-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ assert_non_empty() {
2323
fi
2424
}
2525

26-
assert_non_empty inputs.pkgname "$pkgname"
2726
assert_non_empty inputs.pkgbuild "$pkgbuild"
2827
assert_non_empty inputs.commit_username "$commit_username"
2928
assert_non_empty inputs.commit_email "$commit_email"
@@ -53,6 +52,25 @@ git config --global user.name "$commit_username"
5352
git config --global user.email "$commit_email"
5453
echo '::endgroup::'
5554

55+
echo '::group::Getting pkgname'
56+
if [[ -z "$pkgname" ]]; then
57+
echo 'Extracting pkgname from PKGBUILD'
58+
59+
mkdir -p /tmp/makepkg
60+
cp "$pkgbuild" /tmp/makepkg/PKGBUILD
61+
info=$(cd /tmp/makepkg; makepkg --printsrcinfo)
62+
63+
pattern='pkgname = ([a-z0-9@._+-]*)'
64+
[[ "$info" =~ $pattern ]]
65+
66+
pkgname="${BASH_REMATCH[1]}"
67+
echo "Got pkgname '$pkgname'"
68+
else
69+
echo "Using pkgname '$pkgname' from argument"
70+
assert_non_empty inputs.pkgname "$pkgname"
71+
fi
72+
echo '::endgroup::'
73+
5674
echo '::group::Cloning AUR package into /tmp/local-repo'
5775
git clone -v "https://aur.archlinux.org/${pkgname}.git" /tmp/local-repo
5876
echo '::endgroup::'

0 commit comments

Comments
 (0)