|
1 | 1 | #!/bin/bash |
2 | | -# initialize git submodules during vercel build |
| 2 | +set -e |
3 | 3 |
|
4 | | -set -e # Exit immediately on any error |
5 | | - |
6 | | -# Use HTTPS with token if available, otherwise try SSH |
7 | 4 | if [ -n "$GITHUB_TOKEN" ]; then |
8 | | - git config --global credential.helper store |
9 | | - echo "https://${GITHUB_TOKEN}@github.com" > ~/.git-credentials |
10 | | - chmod 600 ~/.git-credentials |
11 | | - echo "Configured git credential helper for GitHub token" |
| 5 | + echo "Using HTTPS with GitHub token" |
| 6 | + |
| 7 | + # Overwrite the submodule URL with token-authenticated URL |
| 8 | + git submodule set-url apps/web/src/content/newsletters-premium \ |
| 9 | + https://$GITHUB_TOKEN:@github.com/apsinghdev/opensox-newsletters-premium.git |
| 10 | + |
12 | 11 | elif [ -n "$GIT_SSH_KEY" ]; then |
13 | | - # Fallback to SSH if token is not available |
14 | | - mkdir -p ~/.ssh || { echo "Failed to create ~/.ssh directory" >&2; exit 1; } |
15 | | - printf '%s' "$GIT_SSH_KEY" > ~/.ssh/id_ed25519 || { echo "Failed to write SSH key" >&2; exit 1; } |
16 | | - chmod 600 ~/.ssh/id_ed25519 || { echo "Failed to set SSH key permissions" >&2; exit 1; } |
17 | | - ssh-keyscan -t ed25519 github.com >> ~/.ssh/known_hosts 2>/dev/null || true |
18 | | - echo "Configured SSH for private repository access" |
| 12 | + echo "Using SSH key authentication" |
| 13 | + mkdir -p ~/.ssh |
| 14 | + printf '%s' "$GIT_SSH_KEY" > ~/.ssh/id_ed25519 |
| 15 | + chmod 600 ~/.ssh/id_ed25519 |
| 16 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
19 | 17 | else |
20 | | - echo "Warning: No GITHUB_TOKEN or GIT_SSH_KEY found. Private submodule may fail to clone." >&2 |
| 18 | + echo "No authentication found!" |
21 | 19 | fi |
22 | 20 |
|
23 | | -# initialize and update submodules |
24 | | -git submodule update --init --recursive --remote |
25 | | - |
26 | | -echo "submodules initialized successfully" |
27 | | - |
| 21 | +git submodule update --init --recursive --force |
| 22 | +echo "Submodules initialized successfully" |
0 commit comments