|
1 | 1 | #!/bin/bash |
2 | | -set +e |
| 2 | +set -e |
3 | 3 |
|
4 | 4 | if [ -n "$GITHUB_TOKEN" ]; then |
5 | 5 | echo "Using HTTPS with GitHub token" |
@@ -27,22 +27,51 @@ elif [ -n "$GIT_SSH_KEY" ]; then |
27 | 27 | exit 1 |
28 | 28 | fi |
29 | 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 | + |
30 | 45 | 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" |
33 | 48 | ssh-keyscan github.com >> ~/.ssh/known_hosts |
34 | 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 | + |
35 | 58 | else |
36 | | - echo "No authentication found! Skipping premium submodule initialization." |
| 59 | + echo "⚠️ No authentication found! Skipping premium submodule initialization." |
37 | 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)" |
38 | 62 | exit 0 |
39 | 63 | fi |
40 | 64 |
|
| 65 | +# Only disable exit-on-error for submodule update to allow graceful failure |
| 66 | +set +e |
41 | 67 | 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 |
43 | 72 | echo "Submodules initialized successfully" |
44 | 73 | 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 |
48 | 77 | fi |
0 commit comments