Skip to content

Commit

Permalink
Pull versions from release channels
Browse files Browse the repository at this point in the history
Refactors the newly introduced version reporting to use versions
parsed from each shell release channel.
  • Loading branch information
alganet committed Dec 9, 2023
1 parent 5bc66c0 commit 7312567
Show file tree
Hide file tree
Showing 17 changed files with 724 additions and 833 deletions.
537 changes: 208 additions & 329 deletions .github/workflows/docker-build.yml

Large diffs are not rendered by default.

577 changes: 222 additions & 355 deletions .github/workflows/docker-push.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cache/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
FROM debian:buster-slim AS builder

# Update distro
RUN apt-get -y update
RUN apt -y update && apt -y upgrade

# Copy contents
COPY "shvr.sh" "/shvr/shvr.sh"
Expand Down
64 changes: 44 additions & 20 deletions shvr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -euf
SHVR_DIR_SELF="$(cd "$(dirname "$0")"; pwd)"
SHVR_DIR_SRC="${SHVR_DIR_SRC:-"/usr/src/shvr"}"
SHVR_DIR_OUT="${SHVR_DIR_OUT:-"/opt"}"
SHVR_DIR_CACHE="${SHVR_DIR_CACHE:-"${SHVR_DIR_SELF}/.cache"}"

shvr ()
{
Expand All @@ -31,7 +32,7 @@ shvr_targets ()
then set -- $(printf '%s ' $(shvr_interpreters))
fi

shvr_each targets "${@:-}" | sort -V
shvr_each targets "${@:-}"
}

shvr_semver_majors ()
Expand All @@ -41,15 +42,15 @@ shvr_semver_majors ()

shvr_semver_minors ()
{
"shvr_targets_$1" | sed -n 's/^\('"$2"'\)\([.]*[^.]*\)\([.]*.*\)$/\1\2/p' | uniq
"shvr_targets_$1" | sed -n 's/^\('"$2"'\)\([.][0-9]*\)\([.]*.*\)/\1\2/p' | uniq
}

shvr_semver_patches ()
{
shvr_semver_minors "$@"
"shvr_targets_$1" | sed -n 's/^\('"$2"'\)\([.][0-9]*\)\([.]*[0-9]*\)/\1\2/p' | uniq
}

shvr_latest ()
shvr_versions ()
{
if test $# = 0
then set -- $(shvr_interpreters | tr '\n' ' ')
Expand All @@ -58,20 +59,27 @@ shvr_latest ()
while test $# -gt 0
do
. "${SHVR_DIR_SELF}/variants/${1}.sh"
majors="$(shvr_majors_$1 | tr '\n' ' ')"
majors="$(shvr_majors_$1 | head -n ${SHVR_MAJORS:-16} | tr '\n' ' ')"
if test -n "$majors"
then printf '%s ' "$1-latest"
fi
for major in $majors
do
minors="$(shvr_minors_$1 $major | tr '\n' ' ')"
minors="$(shvr_minors_$1 $major | head -n ${SHVR_MINORS:-16} | tr '\n' ' ')"
printf '%s ' "$major-latest"
if test -z "$minors"
then echo "$major"
fi
for minor in $minors
do
patches="$(shvr_patches_$1 $minor | sort -V -r | tr '\n' ' ')"
if test "$patches" != "$minor "
patches="$(shvr_patches_$1 $minor | sort -V -r | head -n ${SHVR_PATCHES:-1} | tr '\n' ' ')"
if test "$major " != "$minors" && test "$minor " != "$patches"
then printf '%s ' "$minor-latest"
fi
if test -z "$patches"
then
echo "$minor"
fi
for patch in $patches
do
echo "$patch"
Expand Down Expand Up @@ -113,7 +121,7 @@ shvr_yml_tags ()
{
interpreter="${1%%_*}"
version="${1#"$interpreter"_}"
shvr_latest "$interpreter" |
shvr_versions "$interpreter" |
sed -n '/'"$(echo "$version" |
sed 's/\./\\./g')"'$/p' |
tr ' ' '\n' |
Expand All @@ -135,6 +143,8 @@ shvr_yml_header ()
# Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
# SPDX-License-Identifier: ISC
# THIS FILE IS AUTO-GENERATED, DO NOT EDIT
name: $2
on:
Expand Down Expand Up @@ -174,6 +184,11 @@ shvr_yml_header ()
@
}

shvr_latest ()
{
shvr_versions "$1" | grep latest | sed '/beta\|alpha\|rc/ d'
}

shvr_yml_items ()
{
if test "$1" = "multi"
Expand All @@ -184,17 +199,11 @@ shvr_yml_items ()
##########################################
#multi-latest
- name: multi-latest
targets: "$(shvr_latest | sed 's/ $//' | rev | cut -d' ' -f1 | rev | sort -V | tr '\n' ' ' )"
targets: "$(SHVR_MAJORS=2 SHVR_MINORS=2 SHVR_PATCHES=1 shvr_versions | sed 's/ $//' | rev | cut -d' ' -f1 | rev | sort -V -r | tr '\n' ' ' )"
can_fail_build: false
tags: |
latest
multi-latest
#multi-all
- name: multi-all
targets: "$(shvr_targets | sort -V | tr '\n' ' ' | sed 's/ $//')"
can_fail_build: false
tags: |
multi-all
@
echo
fi
Expand All @@ -207,21 +216,23 @@ shvr_yml_items ()
@
if test "$1" = "multi"
then
targets="$(shvr_targets "$interpreter" | tr '\n' ' ' | sed 's/ $//')"
targets="$(shvr_versions "$interpreter" | sed 's/ $//' | rev | cut -d' ' -f1 | rev | sort -V -r | tr '\n' ' ' )"
if test -n "$targets"
then
cat <<-@
# $interpreter-all
- name: $interpreter-all
targets: ""
targets: "$targets"
can_fail_build: false
tags: |
$interpreter-all
@
fi
echo
fi
targets="$(shvr_latest "$interpreter")"

targets="$(shvr_versions "$interpreter")"

echo "$targets" | while read -r target
do
if test -z "$target"
Expand All @@ -247,5 +258,18 @@ shvr_yml_items ()
done
}

shvr_cache ()
{
cache_key="${SHVR_DIR_CACHE}/$1"
shift

if ! test -f "$cache_key"
then
mkdir -p "${SHVR_DIR_CACHE}"
"$@" > "$cache_key"
fi

cat "$cache_key"
}

shvr "${@:-}"
52 changes: 39 additions & 13 deletions variants/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,45 @@

shvr_targets_bash ()
{
cat <<-@
bash_5.2.15
bash_5.1.16
bash_5.0.18
bash_4.4.23
bash_4.3.48
bash_4.2.53
bash_4.1.17
bash_4.0.44
bash_3.2.57
bash_3.1.23
bash_3.0.22
@
shvr_cache targets_bash \
curl --no-progress-meter "https://ftp.gnu.org/gnu/bash/" |
grep -Eo 'href="[^"]*"' |
sed -n '
s/^href="bash-/bash_/
s/"$//
/^bash_[0-9][0-9]*.*\.tar\.gz$/ {
s/\.tar\.gz$//
p
}
/^bash_[0-9][0-9]*.*-patches\/$/ {
s/^bash_/bash-/
p
}
' |
while read -r possible_version
do
if test "${possible_version%"patches/"}" != "$possible_version"
then
shvr_cache "targets_bash${possible_version%'/'}" \
curl --no-progress-meter "https://ftp.gnu.org/gnu/bash/$possible_version" |
grep -Eo 'href="[^"]*"' |
sed -n '
s/^href="//
s/"$//
/^bash.*[0-9][0-9][0-9]$/ {
p
}
' |
sort -V |
cut -d'-' -f2 |
sed "s/^/${possible_version%'/'}/" |
sed 's/^bash-/bash_/; s/-patches[0]*/./'
else echo "$possible_version"
fi
done |
grep -v "^bash_[0-2]\." |
sort -u |
sort -V -r
}

shvr_majors_bash () { shvr_semver_majors bash; }
Expand Down
35 changes: 16 additions & 19 deletions variants/busybox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@

shvr_targets_busybox ()
{
cat <<-@
busybox_1.36.0
busybox_1.35.0
busybox_1.34.1
busybox_1.33.2
busybox_1.33.1
busybox_1.32.1
busybox_1.31.1
busybox_1.30.1
busybox_1.29.3
busybox_1.28.4
busybox_1.27.2
busybox_1.26.2
busybox_1.25.1
busybox_1.24.2
busybox_1.23.2
busybox_1.22.1
busybox_1.21.1
@
shvr_cache targets_busybox \
curl --no-progress-meter "https://busybox.net/downloads/" |
grep -Eoi 'href="[^"]*"' |
sed -n '
s/^href="busybox-/busybox_/
s/"$//
/^busybox_[0-9][0-9]*.*\.tar\.bz2$/ {
s/\.tar\.bz2$//
p
}
' |
grep "^busybox_1\.[0-9][0-9]" |
grep -v "^busybox_1\.[0-1][0-9]" |
grep -v "^busybox_1\.20\." |
sort -u |
sort -V -r
}

shvr_majors_busybox () { shvr_semver_majors busybox; }
Expand Down
22 changes: 21 additions & 1 deletion variants/dash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@

shvr_targets_dash ()
{
shvr_cache targets_dash \
curl --no-progress-meter "https://git.kernel.org/pub/scm/utils/dash/dash.git/refs/" |
grep -Eoi "href='[^']*'" |
sed -n "
s/^href='\/pub\/scm\/utils\/dash\/dash.git\/snapshot\/dash-/dash_/
s/'$//
/^dash_[0-9][0-9]*.*\.tar\.gz$/ {
s/\.tar\.gz$//
p
}
" |
grep -v "^dash_0\.5\.[0-6]$" |
sort -u |
sort -V -r

return
cat <<-@
dash_0.5.11
dash_0.5.11.5
Expand All @@ -17,7 +33,11 @@ shvr_targets_dash ()
@
}

shvr_majors_dash () { shvr_semver_majors dash; }
shvr_majors_dash ()
{
shvr_targets_dash | sed -n 's/^dash_0\.\([0-9]*\).*$/dash_0\.\1/p' | sort -u | sort -r
}

shvr_minors_dash () { shvr_semver_minors dash "$@"; }
shvr_patches_dash () { shvr_semver_patches dash "$@"; }

Expand Down
Loading

0 comments on commit 7312567

Please sign in to comment.