Skip to content

Commit bbc41dc

Browse files
authored
Merge pull request #212 from apsinghdev/fix/submodule-scr
[fix] submodule scr
2 parents ba63be5 + 120e573 commit bbc41dc

1 file changed

Lines changed: 59 additions & 4 deletions

File tree

apps/web/scripts/init-submodules.sh

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,75 @@ set -e
33

44
if [ -n "$GITHUB_TOKEN" ]; then
55
echo "Using HTTPS with GitHub token"
6+
7+
# Verify token is not empty after trimming
8+
if [ -z "${GITHUB_TOKEN// }" ]; then
9+
echo "Error: GITHUB_TOKEN is set but empty"
10+
exit 1
11+
fi
612

713
# Overwrite the submodule URL with token-authenticated URL
814
git submodule set-url apps/web/src/content/newsletters-premium \
915
https://$GITHUB_TOKEN:@github.com/apsinghdev/opensox-newsletters-premium.git
1016

1117
elif [ -n "$GIT_SSH_KEY" ]; then
1218
echo "Using SSH key authentication"
19+
20+
if [ -z "${GIT_SSH_KEY// }" ]; then
21+
echo "Error: GIT_SSH_KEY is set but empty"
22+
exit 1
23+
fi
24+
25+
if ! echo "$GIT_SSH_KEY" | grep -qE "^(ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521|-----BEGIN)"; then
26+
echo "Error: GIT_SSH_KEY does not appear to be a valid SSH key"
27+
exit 1
28+
fi
29+
30+
# Determine key type from the key header and use appropriate filename
31+
if echo "$GIT_SSH_KEY" | grep -q "^ssh-ed25519"; then
32+
SSH_KEY_FILE="$HOME/.ssh/id_ed25519"
33+
elif echo "$GIT_SSH_KEY" | grep -q "^ssh-rsa"; then
34+
SSH_KEY_FILE="$HOME/.ssh/id_rsa"
35+
elif echo "$GIT_SSH_KEY" | grep -q "^ecdsa-sha2"; then
36+
SSH_KEY_FILE="$HOME/.ssh/id_ecdsa"
37+
elif echo "$GIT_SSH_KEY" | grep -q "^-----BEGIN"; then
38+
# PEM format - could be RSA, ECDSA, or Ed25519, default to RSA
39+
SSH_KEY_FILE="$HOME/.ssh/id_rsa"
40+
else
41+
# Fallback to ed25519 if type cannot be determined
42+
SSH_KEY_FILE="$HOME/.ssh/id_ed25519"
43+
fi
44+
1345
mkdir -p ~/.ssh
14-
printf '%s' "$GIT_SSH_KEY" > ~/.ssh/id_ed25519
15-
chmod 600 ~/.ssh/id_ed25519
46+
printf '%s' "$GIT_SSH_KEY" > "$SSH_KEY_FILE"
47+
chmod 600 "$SSH_KEY_FILE"
1648
ssh-keyscan github.com >> ~/.ssh/known_hosts
49+
50+
# Configure SSH to use the specific key file for GitHub
51+
cat >> ~/.ssh/config <<EOF
52+
Host github.com
53+
IdentityFile $SSH_KEY_FILE
54+
IdentitiesOnly yes
55+
EOF
56+
chmod 600 ~/.ssh/config
57+
1758
else
18-
echo "No authentication found!"
59+
echo "⚠️ No authentication found! Skipping premium submodule initialization."
60+
echo "Note: Public newsletters will still work. Premium newsletters require authentication."
61+
echo "Status: SKIPPED (exit code 0 - build will continue without premium content)"
62+
exit 0
1963
fi
2064

65+
# Only disable exit-on-error for submodule update to allow graceful failure
66+
set +e
2167
git submodule update --init --recursive --force
22-
echo "Submodules initialized successfully"
68+
submodule_exit_code=$?
69+
set -e
70+
71+
if [ $submodule_exit_code -eq 0 ]; then
72+
echo "Submodules initialized successfully"
73+
else
74+
echo "Error: Submodule initialization failed after authentication was provided."
75+
echo "This may indicate network issues, invalid credentials, or repository problems."
76+
exit $submodule_exit_code
77+
fi

0 commit comments

Comments
 (0)