diff --git a/README.md b/README.md index 482efd4..2bcdffe 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ GitHub Actions to publish AUR package. ### `pkgname` -**Required** AUR package name. +**Optional** AUR package name. If not specified the name will be extracted from the PKGBUILD file. ### `pkgbuild` -**Required** Path to PKGBUILD file. This file is often generated by prior steps. +**Optional** Path to PKGBUILD file. This file is often generated by prior steps. The default value is './PKGBUILD' ### `assets` diff --git a/action.yml b/action.yml index 56cfdab..6e5ed84 100644 --- a/action.yml +++ b/action.yml @@ -6,11 +6,12 @@ branding: icon: package inputs: pkgname: - description: 'AUR package name' - required: true + description: 'AUR package name, extracted from PKGBUILD if not specified' + required: false pkgbuild: description: 'Path to PKGBUILD file' - required: true + default: './PKGBUILD' + required: false assets: description: 'Newline-separated glob patterns for additional files to be added to the AUR repository' required: false diff --git a/build.sh b/build.sh index a0a0991..b8adf7c 100755 --- a/build.sh +++ b/build.sh @@ -23,8 +23,6 @@ assert_non_empty() { fi } -assert_non_empty inputs.pkgname "$pkgname" -assert_non_empty inputs.pkgbuild "$pkgbuild" assert_non_empty inputs.commit_username "$commit_username" assert_non_empty inputs.commit_email "$commit_email" assert_non_empty inputs.ssh_private_key "$ssh_private_key" @@ -53,6 +51,25 @@ git config --global user.name "$commit_username" git config --global user.email "$commit_email" echo '::endgroup::' +echo '::group::Getting pkgname' +if [[ -z "$pkgname" ]]; then + echo 'Extracting pkgname from PKGBUILD' + + mkdir -p /tmp/makepkg + cp "$pkgbuild" /tmp/makepkg/PKGBUILD + info=$(cd /tmp/makepkg; makepkg --printsrcinfo) + + pattern='pkgname = ([a-z0-9@._+-]*)' + [[ "$info" =~ $pattern ]] + + pkgname="${BASH_REMATCH[1]}" + echo "Got pkgname '$pkgname'" +else + echo "Using pkgname '$pkgname' from argument" + assert_non_empty inputs.pkgname "$pkgname" +fi +echo '::endgroup::' + echo '::group::Cloning AUR package into /tmp/local-repo' git clone -v "https://aur.archlinux.org/${pkgname}.git" /tmp/local-repo echo '::endgroup::'