Skip to content

Commit

Permalink
chore(ci): using github action matrix instead of for
Browse files Browse the repository at this point in the history
  • Loading branch information
damonto committed May 7, 2024
1 parent ccb1f33 commit f784246
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,45 @@ on:
tags: [v*]

jobs:
prepare-matrix:
name: Prepare Matrix Output
runs-on: ubuntu-latest
outputs:
servers: ${{ steps.create-matrix.outputs.matrix }}
steps:
- name: Create Matrix Variable
id: create-matrix
run: echo "matrix=$(jq -cr '@json' <<< "${{ vars.SSH_SERVER_LIST }}")" >> $GITHUB_OUTPUT

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [prepare-matrix]
strategy:
matrix:
server: ${{ fromJSON(needs.prepare-matrix.outputs.servers) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Deploy the latest version
- name: Deploy to ${{ matrix.server.name }}
env:
SSH_SERVER_LIST: ${{ vars.SSH_SERVER_LIST }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
if [ -z "$SSH_PRIVATE_KEY" ]; then
echo "SSH_PRIVATE_KEY is not set"
exit 1
fi
if [ -z "$SSH_SERVER_LIST" ]; then
echo "SSH_SERVER_LIST is not set"
exit 1
fi
# Save the private key to a file
mkdir -p $HOME/.ssh
echo "$SSH_PRIVATE_KEY" > $HOME/.ssh/id_ed25519
chmod 600 $HOME/.ssh/id_ed25519
# Split SSH_SERVER_LIST by comma
IFS=',' read -ra SERVER_LIST <<< "$SSH_SERVER_LIST"
for server in "${SERVER_LIST[@]}"; do
ssh -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no "$server" "mkdir -p /opt/estkme-cloud"
scp -i $HOME/.ssh/id_ed25519 -r scripts/deploy.sh $server:/opt/estkme-cloud
ssh -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no $server "sudo /opt/estkme-cloud/deploy.sh && rm -f /opt/estkme-cloud/deploy.sh"
done
ssh -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no ${{ matrix.server.user }}@${{ matrix.server.host }} -p ${{ matrix.server.port }} "mkdir -p /opt/estkme-cloud"
scp -i $HOME/.ssh/id_ed25519 -r scripts/deploy.sh -P ${{ matrix.server.port }} ${{ 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 }} "sudo /opt/estkme-cloud/deploy.sh && rm -f /opt/estkme-cloud/deploy.sh"

0 comments on commit f784246

Please sign in to comment.