Skip to content

Fix SSH key load failure: add trailing newline to key.pem - #2

Merged
mojocn merged 3 commits into
mainfrom
copilot/fix-failing-github-actions-job-build
Jul 16, 2026
Merged

mojocn merged 3 commits into
mainfrom
copilot/fix-failing-github-actions-job-build

Conversation

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

The deploy job was failing with Load key "key.pem": error in libcrypto because OpenSSH's libcrypto requires PEM files to end with a newline — which printf '%s' doesn't produce.

Change

  • deploy.sh: printf '%s'printf '%s\n' when writing $SSH_KEY to key.pem
# Before
printf '%s' "$SSH_KEY" | tr -d '\r' > key.pem

# After
printf '%s\n' "$SSH_KEY" | tr -d '\r' > key.pem

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
Copilot AI requested a review from mojocn July 16, 2026 08:35
@mojocn
mojocn marked this pull request as ready for review July 16, 2026 09:12
Copilot AI review requested due to automatic review settings July 16, 2026 09:12
@mojocn
mojocn merged commit d35f9d4 into main Jul 16, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_KEY to key.pem with a guaranteed trailing newline to satisfy PEM parsing requirements.
  • Gate the “Deploy to AliCloud ECS” step to run only on push events.
  • (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_KEY would still produce a 1-byte file and pass the check, leading to a later libcrypto failure. Validate that the file actually contains a PEM private key header (or validate $SSH_KEY before 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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants