Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.tmp
.env
.env.*
.vscode/
106 changes: 101 additions & 5 deletions scripts/bootstrap-issues.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ APPLICATION_FILE="${ROOT_DIR}/APPLICATION.md"
REGISTRY_FILE="${ROOT_DIR}/.github/issue-registry.json"
DRY_RUN=false
SLUGS_FILE="$(mktemp)"
SLUGS_ORDERED_FILE="$(mktemp)"
REGISTRY_TMP="$(mktemp)"
LABELS_FILE="$(mktemp)"
EXISTING_LABELS_FILE="$(mktemp)"

cleanup() {
rm -f "${SLUGS_FILE}" "${REGISTRY_TMP}" "${APPLICATION_FILE}.tmp"
rm -f "${SLUGS_FILE}" "${SLUGS_ORDERED_FILE}" "${REGISTRY_TMP}" \
"${LABELS_FILE}" "${EXISTING_LABELS_FILE}" "${APPLICATION_FILE}.tmp"
}
trap cleanup EXIT

Expand All @@ -37,8 +41,14 @@ for cmd in gh jq; do
fi
done

if ! gh auth status >/dev/null 2>&1; then
echo "Error: gh is not authenticated. Run: gh auth login" >&2
# gh auth status exits non-zero when any configured host has a stale token
# (e.g. legacy github_com in hosts.yml), even if github.com auth works.
# Verify API access instead — that's what this script actually needs.
if ! gh api user -q .login >/dev/null 2>&1; then
echo "Error: gh is not authenticated or the token is invalid." >&2
echo "Run: gh auth login" >&2
echo >&2
gh auth status 2>&1 || true
exit 1
fi

Expand All @@ -53,10 +63,96 @@ if [[ -z "${REPO}" ]]; then
exit 1
fi

jq -r 'keys[]' "${MAP_FILE}" | sort > "${SLUGS_FILE}"
total="$(wc -l < "${SLUGS_FILE}" | tr -d ' ')"
label_color() {
case "${1}" in
checklist-item) echo "0E8A16" ;;
critical) echo "B60205" ;;
recommended) echo "FBCA04" ;;
phase:*) echo "5319E7" ;;
checklist:*) echo "1D76DB" ;;
*) echo "BFD4F2" ;;
esac
}

label_description() {
case "${1}" in
checklist-item) echo "Part of the CNCF sandbox application preparation checklist" ;;
critical) echo "Required before CNCF submission" ;;
recommended) echo "Improves review experience" ;;
phase:*) echo "Application section: ${1#phase:}" ;;
checklist:*) echo "Checklist item: ${1#checklist:}" ;;
*) echo "" ;;
esac
}

reverse_lines() {
if command -v tac >/dev/null 2>&1; then
tac "$1"
else
tail -r "$1"
fi
}

build_checklist_order() {
grep -oE 'checklist:[a-z0-9-]+' "${APPLICATION_FILE}" \
| sed 's/checklist://' \
| awk '!seen[$0]++' > "${SLUGS_ORDERED_FILE}"
}

validate_checklist_order() {
local map_slugs app_slugs
map_slugs="$(jq -r 'keys[]' "${MAP_FILE}" | sort)"
app_slugs="$(sort "${SLUGS_ORDERED_FILE}")"
if [[ "${map_slugs}" != "${app_slugs}" ]]; then
echo "Error: checklist slugs in APPLICATION.md do not match checklist-map.json" >&2
comm -3 <<< "${map_slugs}" <<< "${app_slugs}" | sed 's/^/ /' >&2
exit 1
fi
}

ensure_labels() {
local label color description

# Use temp files instead of pipes/here-strings so grep never reads the same
# stdin as the while loop (that deadlock shows up as a hang on grep).
echo "Fetching existing repository labels..."
gh label list --limit 500 --json name -q '.[].name' | sort > "${EXISTING_LABELS_FILE}"
jq -r '[.[].labels[]] | unique | sort | .[]' "${MAP_FILE}" > "${LABELS_FILE}"

while IFS= read -r label; do
[[ -z "${label}" ]] && continue
if grep -qxF "${label}" "${EXISTING_LABELS_FILE}"; then
continue
fi

color="$(label_color "${label}")"
description="$(label_description "${label}")"

if [[ "${DRY_RUN}" == true ]]; then
echo "[dry-run] Would create label: ${label}"
continue
fi

echo "Creating label: ${label}"
gh label create "${label}" --color "${color}" --description "${description}"
done < "${LABELS_FILE}"
}

build_checklist_order
validate_checklist_order
# GitHub's default issue list sort is Newest (created descending). Create the
# last checklist item first so the first item appears at the top of the list.
reverse_lines "${SLUGS_ORDERED_FILE}" > "${SLUGS_FILE}"
total="$(wc -l < "${SLUGS_ORDERED_FILE}" | tr -d ' ')"

echo "Bootstrapping ${total} checklist issues for ${REPO}..."
echo "Completion order (top to bottom in the issues list):"
while IFS= read -r slug; do
echo " - $(jq -r --arg s "${slug}" '.[$s].title' "${MAP_FILE}")"
done < "${SLUGS_ORDERED_FILE}"
echo

ensure_labels
echo

echo "{" > "${REGISTRY_TMP}"
Expand Down
Loading