Skip to content

Commit db38a5f

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

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ assert_non_empty() {
2323
fi
2424
}
2525

26-
assert_non_empty inputs.pkgname "$pkgname"
27-
assert_non_empty inputs.pkgbuild "$pkgbuild"
2826
assert_non_empty inputs.commit_username "$commit_username"
2927
assert_non_empty inputs.commit_email "$commit_email"
3028
assert_non_empty inputs.ssh_private_key "$ssh_private_key"
@@ -53,6 +51,27 @@ git config --global user.name "$commit_username"
5351
git config --global user.email "$commit_email"
5452
echo '::endgroup::'
5553

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

0 commit comments

Comments
 (0)