commit 8f123c941fe7d24a62dc646d30903078ed795a1b Author: Altareos Date: Sat Jun 21 12:49:49 2025 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c48bc7d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +PKGBUILD +*PKGBUILD +.SRCINFO \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1d29896 --- /dev/null +++ b/action.yml @@ -0,0 +1,25 @@ +name: "Make SRCINFO" +description: "Generate .SRCINFO file from PKGBUILD" +inputs: + pkgbuild-file: + description: "Path to PKGBUILD file" + srcinfo-file: + description: "Path to .SRCINFO file to be created" + default: ".SRCINFO" +outputs: + version: + description: "Version of the package" +runs: + using: "composite" + steps: + - name: "Make SRCINFO" + shell: bash + run: "./mksrcinfo.sh $PKGBUILD_PATH > $SRCINFO_PATH" + env: + PKGBUILD_PATH: ${{ inputs.pkgbuild-file }} + SRCINFO_PATH: ${{ inputs.srcinfo-file }} + - name: "Get version" + shell: bash + run: "grep 'pkgver = ' $SRCINFO_PATH | sed 's/ = /=/' >> $GITHUB_OUTPUT" + env: + SRCINFO_PATH: ${{ inputs.srcinfo-file }} diff --git a/mksrcinfo.sh b/mksrcinfo.sh new file mode 100755 index 0000000..a54a0f1 --- /dev/null +++ b/mksrcinfo.sh @@ -0,0 +1,103 @@ +#!/usr/bin/bash + +# declare known fields +base_fields=(pkgver pkgrel epoch) +section_scalar_fields=(pkgdesc url install changelog) +section_arch_fields=(source depends checkdepends makedepends optdepends provides conflicts replaces md5sums sha1sums sha224sums sha256sums sha384sums sha512sums) +section_array_fields=(arch groups license noextract options backup validpgpkeys "${section_arch_fields[@]}") +section_fields=("${section_scalar_fields[@]}" "${section_array_fields[@]}") + +# load PKGBUILD +source "${1:-./PKGBUILD}" + +# check if a variable is an array +is_array() { + [[ "$(declare -p $1)" =~ "declare -a" ]] +} + +# unset all field variables +clear_fields() { + for field in "${section_fields[@]}"; do + eval "unset $field" + done +} + +# print a field with indentation +print_field() { + printf "\t$1 = %s\n" "$2" +} + +# print a scalar field +print_scalar_field() { + eval "[[ -v "$1" ]] && print_field '$1' \"\${$1}\"" +} + +# print all values of an array field +print_array_field() { + if ! [[ -v "$1" ]]; then return; fi + if ! is_array "$1"; then + print_scalar_field "$1" + fi + local f + eval "for f in \"\${$1[@]}\"; do print_field "$1" \"\$f\"; done" +} + +# load section content from its package function +load_section_content() { + if [[ -n $1 ]]; then + suffix="_$1" + else + suffix="" + fi + if [[ ! "$(type -t "package$suffix")" = function ]]; then return; fi + # eval only variable assignments in package function + while read -r line; do + eval "$line" + done < <(declare -f "package$suffix" | grep -E '^[[:space:]]*(declare +)?[[:alnum:]_]*=') +} + +# print fields for a section +print_section_content() { + for field in "${section_scalar_fields[@]}"; do + print_scalar_field "$field" + done + + for field in "${section_array_fields[@]}"; do + print_array_field "$field" + done + + for a in "${arch[@]}"; do + for field in "${section_arch_fields[@]}"; do + print_array_field "${field}_$a" + done + done +} + +# main + +# determine pkgbase +if ! is_array pkgname; then + pkgname=($pkgname) +fi +printf "pkgbase = %s\n" "${pkgbase:-${pkgname[0]}}" + +# run pkgver function if needed +if [[ ! -v pkgver ]] && [[ "$(type -t pkgver)" = function ]]; then + pkgver="$(pkgver)" +fi + +# load base section content and print it +load_section_content +for field in "${base_fields[@]}"; do + print_scalar_field "$field" +done +print_section_content + +# load section content for each split package and print it +for splitname in "${pkgname[@]}"; do + printf "\npkgname = %s\n" "$splitname" + clear_fields + load_section_content "$splitname" + print_section_content +done +