Fix SSH key load failure: add trailing newline to key.pem - #2
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix failing GitHub Actions job build
Fix SSH key load failure: add trailing newline to key.pem
Jul 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a deployment failure where OpenSSH/libcrypto rejects PEM private keys that don’t end with a trailing newline, by ensuring the generated key.pem is newline-terminated in the deploy script. It also adjusts the GitHub Actions workflow to avoid running the deploy step on non-push events.
Changes:
- Write
$SSH_KEYtokey.pemwith a guaranteed trailing newline to satisfy PEM parsing requirements. - Gate the “Deploy to AliCloud ECS” step to run only on
pushevents. - (Minor) Correct workflow logging to avoid referencing an undefined env var.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| .github/workflows/deploy.yml | Adds a deploy-step condition and contains a small fixable workflow log-variable issue. |
| .github/workflows/deploy.sh | Ensures key.pem ends with a newline; follow-up needed to keep validation and file-permission handling robust. |
Comments suppressed due to low confidence (1)
.github/workflows/deploy.sh:12
- The post-write validation now uses
-s key.pem, but because the key is written with a trailing newline, an empty$SSH_KEYwould still produce a 1-byte file and pass the check, leading to a laterlibcryptofailure. Validate that the file actually contains a PEM private key header (or validate$SSH_KEYbefore writing).
# Verify key file was created properly
if [ ! -f key.pem ] || [ ! -s key.pem ]; then
echo "Error: SSH key file not created or is empty"
exit 1
fi
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
2
to
6
| set -e | ||
|
|
||
| # Create SSH key file with proper handling, stripping Windows-style line endings | ||
| printf '%s' "$SSH_KEY" | tr -d '\r' > key.pem | ||
| printf '%s\n' "$SSH_KEY" | tr -d '\r' > key.pem | ||
| chmod 600 key.pem |
| go build -ldflags="-X 'main.gitHash=${{ github.sha }}' -X 'main.buildTime=${{ env.buildTime }}'" -o unchain . | ||
|
|
||
| - name: Deploy to AliCloud ECS | ||
| if: github.event_name == 'push' |
Comment on lines
42
to
+46
| echo "Building Go application with gitHash=${{ env.gitHash }} and buildTime=${{ env.buildTime }}" | ||
| go build -ldflags="-X 'main.gitHash=${{ github.sha }}' -X 'main.buildTime=${{ env.buildTime }}'" -o unchain . | ||
|
|
||
| - name: Deploy to AliCloud ECS | ||
| if: github.event_name == 'push' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The deploy job was failing with
Load key "key.pem": error in libcryptobecause OpenSSH's libcrypto requires PEM files to end with a newline — whichprintf '%s'doesn't produce.Change
deploy.sh:printf '%s'→printf '%s\n'when writing$SSH_KEYtokey.pem