Setup scp in a Github Action #
- create ssh keypair on the server as a specific user used just for uploading
- copy the private key to a github secret
- append the public key to the
.ssh/authorized_keysfile - make a github action that uploads the artifacts using this scp action
The action looks like this:
name: Publish Brain
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- run: npm ci
- run: npm run build-brain
- name: copy file with ssh password
uses: appleboy/scp-action@v0.1.7
with:
host: myserver.com
username: deployuser
port: 22
key: ${{secrets.DEPLOYUSER_PRIVATE_KEY}}
source: "*.html"
target: remote_path