Skip to content

Commit dab0704

Browse files
committed
Fix portability and add gh CLI check in migration script
- Replace grep -P (GNU-only) with POSIX-compatible pattern for macOS compatibility - Add early check for gh CLI availability with clear warning - Skip GHCR visibility step gracefully when gh is not installed
1 parent 37cc4f3 commit dab0704

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

scripts/devcontainer_use_prebuilt.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ set -euo pipefail
66

77
DEVCONTAINER_JSON=".devcontainer/devcontainer.json"
88

9+
# --- Check prerequisites ---
10+
if ! command -v gh >/dev/null 2>&1; then
11+
echo "WARNING: GitHub CLI (gh) not found. Will skip making the package public." >&2
12+
GH_AVAILABLE=false
13+
else
14+
GH_AVAILABLE=true
15+
fi
16+
917
# --- Resolve GitHub owner/repo from git remote ---
1018
REMOTE_URL=$(git remote get-url origin 2>/dev/null) || {
1119
echo "ERROR: No git remote 'origin' found." >&2
@@ -25,7 +33,7 @@ echo "Repository: $REPO"
2533
echo "Image: $IMAGE"
2634

2735
# --- Check current state: look for an uncommented "image": line ---
28-
if grep -qP '^\s+"image"\s*:' "$DEVCONTAINER_JSON"; then
36+
if grep -q '^[[:space:]]*"image"[[:space:]]*:' "$DEVCONTAINER_JSON"; then
2937
echo "Already using a prebuilt image. Nothing to do."
3038
exit 0
3139
fi
@@ -68,6 +76,15 @@ OWNER=$(echo "$REPO" | cut -d'/' -f1)
6876
PACKAGE_NAME=$(echo "$REPO" | cut -d'/' -f2)
6977
ENCODED_PACKAGE="${PACKAGE_NAME}%2Fdevcontainer"
7078

79+
if ! $GH_AVAILABLE; then
80+
echo "Skipping: gh CLI not available."
81+
echo ""
82+
echo "To make the package public, install gh and run:"
83+
echo " gh auth refresh -s write:packages"
84+
echo " gh api --method PATCH /user/packages/container/${ENCODED_PACKAGE} -f visibility=public"
85+
exit 0
86+
fi
87+
7188
# Determine if owner is an org or a user
7289
IS_ORG=false
7390
if gh api "/orgs/${OWNER}" >/dev/null 2>&1; then

0 commit comments

Comments
 (0)