diff --git a/.gitea/workflows/coder-templates.yml b/.gitea/workflows/coder-templates.yml index c304e78..ea822f4 100644 --- a/.gitea/workflows/coder-templates.yml +++ b/.gitea/workflows/coder-templates.yml @@ -162,31 +162,39 @@ jobs: # templates//VERSION lets a template opt out of being # reprovisioned on every push: bump it and coder templates push - # names the new version "v"; leave it as-is and this looks up - # whether that version name is already pushed and skips if so. - # This is a manual contract, not a content hash - editing a - # template without bumping its VERSION means the change won't - # go out until someone does. paths: on this workflow's trigger - # is templates/** as a whole, so without this every template - # gets a new (identical) version on any push under templates/, - # even ones whose own directory didn't change. + # names the new version "v". This is a manual contract, not a + # content hash - editing a template without bumping its VERSION + # means the change won't go out until someone does. paths: on + # this workflow's trigger is templates/** as a whole, so without + # this every template gets a new (identical) version on any push + # under templates/, even ones whose own directory didn't change. + # + # Rather than pre-checking `coder templates versions list` for + # whether v already exists (fragile - depends on its exact + # JSON shape matching what we expect), just attempt the push and + # treat its specific "version already exists" failure as the + # skip signal instead. version="" if [ -f "$dir/VERSION" ]; then version="$(tr -d '[:space:]' < "$dir/VERSION")" fi - if [ -n "$version" ]; then - existing="$(coder templates versions list "$full" -o json 2>/dev/null || true)" - if [ -n "$existing" ] && echo "$existing" | jq -e --arg v "v$version" 'any(.[]; .name == $v)' >/dev/null 2>&1; then - echo "Skipping $full - version v$version (templates/$name/VERSION) is already pushed. Bump the VERSION file to push a new one." - continue - fi - fi args=(-d "$dir" --yes -m "auto-provisioned from ${GITHUB_SHA:0:12}") [ -n "$version" ] && args+=(--name "v$version") echo "::group::Pushing $full from $dir" - coder templates push "$full" "${args[@]}" + if push_output="$(coder templates push "$full" "${args[@]}" 2>&1)"; then + echo "$push_output" + else + push_status=$? + echo "$push_output" + if [ -n "$version" ] && printf '%s' "$push_output" | grep -qF "A template version with name \"v$version\" already exists"; then + echo "Version v$version (templates/$name/VERSION) is already pushed - nothing to do. Bump the VERSION file to push a new one." + else + echo "::endgroup::" + exit "$push_status" + fi + fi echo "::endgroup::" done