@@ -16,6 +16,15 @@ help() {
1616 echo " * f - Force build and push even if the tag already exists in the registry"
1717}
1818
19+ # Authenticate when GITHUB_TOKEN is set to avoid the low anonymous API rate limit
20+ github_api () {
21+ local auth=()
22+ if [[ -n " $GITHUB_TOKEN " ]]; then
23+ auth=(-H " Authorization: Bearer $GITHUB_TOKEN " )
24+ fi
25+ curl --silent --show-error --fail -L -H " Accept: application/vnd.github+json" " ${auth[@]} " " https://api.github.com/$1 "
26+ }
27+
1928# 'latest' always rebuilds; other tags skip if already pushed, unless forced.
2029tagAlreadyExists () {
2130 if [[ " $OPTION_VERSION " == " latest" ]] || [[ -n " $FORCE " ]] || [[ -z " $PUSH " ]]; then
@@ -27,7 +36,7 @@ tagAlreadyExists() {
2736
2837loadVersionAndTags () {
2938 # @todo: Currently limited to 99 releases, may use pagination
30- ddev_releases=($( curl --silent -L -H " Accept: application/vnd.github+json " https://api.github.com/ repos/${GITHUB_OWNER} /ddev/releases? per_page=99 | jq -r ' .[].tag_name' ) )
39+ ddev_releases=($( github_api " repos/${GITHUB_OWNER} /ddev/releases?per_page=99" | jq -r ' .[].tag_name' ) )
3140
3241 IFS=' .' read -r -a version <<< " $OPTION_VERSION"
3342 bugfix_release=" ${version[2]} "
@@ -91,7 +100,7 @@ if [ "$OPTION_VERSION" = "latest" ]; then
91100 DDEV_VERSION=" latest"
92101 DOCKER_TAGS=(" -t $IMAGE_NAME :latest" )
93102elif [ " $OPTION_VERSION " = " stable" ]; then
94- DDEV_VERSION=" $( curl --silent -L -H " Accept: application/vnd.github+json " https://api.github.com/ repos/ddev /ddev/releases/latest | jq -r ' .tag_name' ) "
103+ DDEV_VERSION=" $( github_api " repos/${GITHUB_OWNER} /ddev/releases/latest" | jq -r ' .tag_name' ) "
95104
96105 if [[ ! " $DDEV_VERSION " =~ ^v[0-9]+\. [0-9]+\. [0-9]+$ ]]; then
97106 echo " Error: Latest DDEV release '$DDEV_VERSION ' is not a valid semver version."
0 commit comments