Skip to content

Commit

Permalink
Add config script to be used with GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tarleb committed Oct 20, 2024
1 parent b2d3823 commit c494fb8
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions scripts/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

usage ()
{
printf 'Generate parameters for GitHub Actions\n\n'
printf 'Usage:\n\t%s <pandoc_version> <build_stack> <image_name>\n' "$0"
}

if [ "$#" -ne 3 ]; then
usage
exit 1
fi

version="${1:-main}"
build_stack="${2:-alpine}"
image_name="${3:-pandoc/minimal}"

versions_file=versions.md
row="$(grep "^| $version " "$versions_file")"

if [ -z "$row" ]; then
printf "Unknown or unsupported version '%s'\n" "$version"
exit 1
fi

field ()
{
col=$(($1 + 1))
printf '%s\n' "$row" | \
awk -F '|' "{ gsub(/^ *| *\$/,\"\",\$$col); print \$${col} }" | \
sed -e 's/ */,/g'
}

case "${build_stack}" in
(alpine|static)
base_image='alpine'
base_image_tag="$(field 3)"
;;
(ubuntu)
base_image='ubuntu'
base_image_tag="$(field 4)"
;;
(*)
printf "Unsupported base image: '%s'\n" "$base_image"
;;
esac

printf '%s\n' "$(field 2)"

tagsbase="$(field 2 | sed -e "s#\([^,]*\)#${image_name}:\1#g")"
tags="$(printf '%s' "$tagsbase" | \
sed -e 's#\([^,]*\)#\1-'${base_image}'#g')"
if ( [ "$image_name" != 'pandoc/minimal' ] && \
[ "$build_stack" = 'alpine' ] ) ||
( [ "$image_name" = 'pandoc/minimal' ] && \
[ "$build_stack" = 'static' ] );
then
tags="${tags},${tagsbase}"
fi

printf 'tags="%s"\n' "$tags"
printf 'base_image="%s"\n' "$base_image"
printf 'base_image_tag="%s"\n' "$base_image_tag"
printf 'texlive_version="%s"\n' "$(field 5)"

0 comments on commit c494fb8

Please sign in to comment.