You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

  1. #!/bin/bash
  2. ## List upstream available versions in reverse chronological order
  3. ##
  4. ## These versions information will be the input for the version information
  5. ## usually used by the build process.
  6. ## A external query of upstream sources will be done.
  7. ##
  8. ## This script is launched by ``charm upstream-versions`` and will receive these env variables
  9. ##
  10. ##
  11. ## VERSION_LIMIT ## limit number of version to read
  12. ##
  13. ##
  14. ## The script CWD will be the root of the charm directory
  15. ##
  16. DOCKER_IMAGE_NAME=collabora/code
  17. semver:normalize() {
  18. local upstream_version="$1"
  19. local version="${upstream_version/./}"
  20. read -r year_month major minor patch <<< ${version//./ }
  21. if ! [ "${#patch}" == 1 ]; then
  22. echo "Error: build number is not a single digit: '${patch}' (upstream: '${upstream_version}')" >&2
  23. return 1
  24. fi
  25. if [ "${#major}" -gt 2 ]; then
  26. echo "Error: major number is more than 2 digits: '${major}' (upstream: '${upstream_version}')" >&2
  27. return 1
  28. fi
  29. major=$(printf "%02d" ${major})
  30. echo "${year_month}${major}.${minor}.${patch}"
  31. }
  32. upstream:list() {
  33. local limit=${1:-5}
  34. docker-tags-fetch "$DOCKER_IMAGE_NAME" -l "${limit}" -f "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" |
  35. sort -rV |
  36. cut -f 1 -d "-"
  37. }
  38. while read -r "upstream_version"; do
  39. normalized_version=$(semver:normalize "${upstream_version}") || exit 1
  40. printf "%s %s\n" "$(semver:normalize "${upstream_version}")" "$upstream_version"
  41. done < <(upstream:list "${VERSION_LIMIT}")