Fix provision job crashing on templates already at their current VERSION
Run 109 failed: profiles-3d-printing (and the same would've hit every other already-versioned template) already had a "v1" version from the previous run, and the pre-check meant to detect that and skip (coder templates versions list -o json piped through jq) apparently doesn't match the CLI's actual JSON shape - it never found the existing version, so the push was attempted anyway and coder rejected the duplicate name, failing the whole job. Simpler and more robust: just attempt the push and treat its specific "A template version with name ... already exists" failure as the skip signal, instead of trying to predict it from a separate list call.
This commit is contained in:
@@ -162,31 +162,39 @@ jobs:
|
||||
|
||||
# templates/<name>/VERSION lets a template opt out of being
|
||||
# reprovisioned on every push: bump it and coder templates push
|
||||
# names the new version "v<N>"; 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<N>". 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<N> 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user