diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index da29422..c8270fb 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -83,6 +83,41 @@ jobs: curl -fsS -o /dev/null -X POST -H "Authorization: token $TOKEN" \ -F "attachment=@$f" "$api/releases/$id/assets?name=$(basename "$f")" done + # The ci workflow builds the images of this tag after lint and tests, + # which takes longer than this job. A chart published before them makes + # clusters that follow the chart repository roll out a release whose + # images do not exist yet (ImagePullBackOff in the migrate hook). + - name: Wait for the images + env: + PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }} + run: | + set -eu + if [ -z "$PACKAGE_TOKEN" ]; then + echo "::warning::PACKAGE_TOKEN is not set; not waiting for the images." + exit 0 + fi + host="${GITHUB_SERVER_URL#*://}" + owner="$(printf '%s' "${GITHUB_REPOSITORY%/*}" | tr 'A-Z' 'a-z')" + tag="${GITHUB_REF_NAME#v}" + accept="application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json,application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.docker.distribution.manifest.v2+json" + deadline=$(( $(date +%s) + 90 * 60 )) + for repo in uptimesebi uptimesebi-checker uptimesebi-statuspage; do + until + token="$(curl -fsS --user "$GITHUB_ACTOR:$PACKAGE_TOKEN" \ + "$GITHUB_SERVER_URL/v2/token?service=container_registry&scope=repository:$owner/$repo:pull" \ + | sed -n 's/.*"token":"\([^"]*\)".*/\1/p')" + curl -fsS -o /dev/null -I -H "Authorization: Bearer $token" -H "Accept: $accept" \ + "$GITHUB_SERVER_URL/v2/$owner/$repo/manifests/$tag" + do + if [ "$(date +%s)" -ge "$deadline" ]; then + echo "::error::$host/$owner/$repo:$tag did not appear within 90 minutes; the chart is not published." + exit 1 + fi + echo "waiting for $host/$owner/$repo:$tag" + sleep 30 + done + echo "$host/$owner/$repo:$tag is there" + done # helm repo add uptimesebi /api/packages//helm - name: Publish Helm chart env: