Skip to content

Deploy

Deploy #76

Workflow file for this run

name: Deploy
on:
workflow_dispatch:
workflow_run:
workflows: ["Build and Release"]
types:
- completed
branches: ['v*.*.*']
jobs:
init:
name: Initialize
runs-on: ubuntu-latest
outputs:
servers: ${{ steps.prepare.outputs.matrix }}
steps:
- name: Prepare server list
id: prepare
run: echo "matrix=$(echo '${{ vars.SSH_SERVER_LIST }}' | jq -c .)" >> $GITHUB_OUTPUT
deploy:
name: Deploy to ${{ matrix.server.name }}
runs-on: ubuntu-latest
needs: [init]
strategy:
fail-fast: false
matrix:
server: ${{ fromJSON(needs.init.outputs.servers) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run deploy.sh on ${{ matrix.server.name }}
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
if [ -z "$SSH_PRIVATE_KEY" ]; then
echo "SSH_PRIVATE_KEY is not set"
exit 1
fi
mkdir -p $HOME/.ssh
echo "$SSH_PRIVATE_KEY" > $HOME/.ssh/id_ed25519
chmod 600 $HOME/.ssh/id_ed25519
scp -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no -P ${{ matrix.server.port }} -r scripts/deploy.sh ${{ matrix.server.user }}@${{ matrix.server.host }}:/opt/estkme-cloud
ssh -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no ${{ matrix.server.user }}@${{ matrix.server.host }} -p ${{ matrix.server.port }} "/opt/estkme-cloud/deploy.sh '${{ matrix.server.ad }}' && rm -f /opt/estkme-cloud/deploy.sh"