Skip to content

Commit 120e573

Browse files
committed
fix: fix coderabit issues
1 parent 1ebe89c commit 120e573

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

apps/web/scripts/init-submodules.sh

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set +e
2+
set -e
33

44
if [ -n "$GITHUB_TOKEN" ]; then
55
echo "Using HTTPS with GitHub token"
@@ -27,22 +27,51 @@ elif [ -n "$GIT_SSH_KEY" ]; then
2727
exit 1
2828
fi
2929

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+
3045
mkdir -p ~/.ssh
31-
printf '%s' "$GIT_SSH_KEY" > ~/.ssh/id_ed25519
32-
chmod 600 ~/.ssh/id_ed25519
46+
printf '%s' "$GIT_SSH_KEY" > "$SSH_KEY_FILE"
47+
chmod 600 "$SSH_KEY_FILE"
3348
ssh-keyscan github.com >> ~/.ssh/known_hosts
3449

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+
3558
else
36-
echo "No authentication found! Skipping premium submodule initialization."
59+
echo "⚠️ No authentication found! Skipping premium submodule initialization."
3760
echo "Note: Public newsletters will still work. Premium newsletters require authentication."
61+
echo "Status: SKIPPED (exit code 0 - build will continue without premium content)"
3862
exit 0
3963
fi
4064

65+
# Only disable exit-on-error for submodule update to allow graceful failure
66+
set +e
4167
git submodule update --init --recursive --force
42-
if [ $? -eq 0 ]; then
68+
submodule_exit_code=$?
69+
set -e
70+
71+
if [ $submodule_exit_code -eq 0 ]; then
4372
echo "Submodules initialized successfully"
4473
else
45-
echo "Warning: Submodule initialization failed, but continuing build..."
46-
echo "Note: Public newsletters will still work. Premium newsletters require authentication."
47-
exit 0
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
4877
fi

0 commit comments

Comments
 (0)