| @@ -34,10 +34,32 @@ jobs: |
| 34 | - name: Push to GitHub | 34 | - name: Push to GitHub |
| 35 | env: | 35 | env: |
| 36 | SSH_KEY: ${{ secrets.GH_MIRROR_SSH_KEY }} | 36 | SSH_KEY: ${{ secrets.GH_MIRROR_SSH_KEY }} |
| | 37 | + shell: bash |
| 37 | run: | | 38 | run: | |
| 38 | mkdir -p ~/.ssh | 39 | mkdir -p ~/.ssh |
| 39 | - printf '%s\n' "$SSH_KEY" > ~/.ssh/mirror_key | 40 | + |
| | 41 | + # A key pasted from Windows carries CRLF line endings, and some secret stores flatten newlines |
| | 42 | + # into spaces or literal \n: OpenSSH then fails with "error in libcrypto". Rebuild the PEM layout |
| | 43 | + key=$(printf '%s' "$SSH_KEY" | tr -d '\r') |
| | 44 | + key=${key//\\n/$'\n'} |
| | 45 | + header=$(grep -oE -- '-----BEGIN [A-Z ]+-----' <<< "$key" || true) |
| | 46 | + if [[ -n $header && $key != *$'\n'* ]]; then |
| | 47 | + footer=$(grep -oE -- '-----END [A-Z ]+-----' <<< "$key") |
| | 48 | + body=${key#"$header"} |
| | 49 | + body=${body%"$footer"} |
| | 50 | + key=$(printf '%s\n' "$header"; tr ' ' '\n' <<< "$body" | sed '/^$/d'; printf '%s\n' "$footer") |
| | 51 | + fi |
| | 52 | + printf '%s\n' "$key" > ~/.ssh/mirror_key |
| 40 | chmod 600 ~/.ssh/mirror_key | 53 | chmod 600 ~/.ssh/mirror_key |
| | 54 | + |
| | 55 | + # Fail early with a readable diagnosis (header and line count only, never the key itself) |
| | 56 | + if ! ssh-keygen -y -f ~/.ssh/mirror_key > /dev/null; then |
| | 57 | + first=$(head -n 1 ~/.ssh/mirror_key) |
| | 58 | + [[ $first == -----* || $first == ssh-* ]] || first="(neither a PEM header nor a public key)" |
| | 59 | + echo "GH_MIRROR_SSH_KEY is not a usable private key: $(wc -l < ~/.ssh/mirror_key) lines, first line: ${first:0:40}" |
| | 60 | + echo "Expected the private key, without passphrase, from -----BEGIN OPENSSH PRIVATE KEY----- to -----END OPENSSH PRIVATE KEY-----" |
| | 61 | + exit 1 |
| | 62 | + fi |
| 41 | echo "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl" > ~/.ssh/known_hosts | 63 | echo "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl" > ~/.ssh/known_hosts |
| 42 | export GIT_SSH_COMMAND="ssh -i ~/.ssh/mirror_key -o IdentitiesOnly=yes" | 64 | export GIT_SSH_COMMAND="ssh -i ~/.ssh/mirror_key -o IdentitiesOnly=yes" |
| 43 | | 65 | |