-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (47 loc) · 1.62 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Continuous Deployment
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y openssh-client jq curl
- name: Create SSH directory and known_hosts file
run: mkdir -p ~/.ssh && touch ~/.ssh/known_hosts
- name: Add SSH known hosts
run: ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
- name: Start SSH agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.KEY }}
- name: Fetch deployment details
id: fetch-deployment-details
run: curl -s https://sites.cyber32.net/api/sites > sites.json
- name: Debug sites.json content
run: |
echo "Content of sites.json:"
cat sites.json
echo "Validating JSON format"
jq . sites.json
- name: Deploy to Servers
run: |
sites=$(cat sites.json | jq -c '.[]')
for site in "$sites"; do
username=$(echo $site | jq -r '.uname')
deploy_script=$(echo $site | jq -r '.script')
echo "Deploying to $username"
ssh -o "StrictHostKeyChecking=no" -p ${{ secrets.PORT }} $username@${{ secrets.HOST }} "$deploy_script" || echo -e "\e[31mError deploying to $username\e[0m"
done
env:
HOST: ${{ secrets.HOST }}
PORT: ${{ secrets.PORT }}
- name: Cleanup temporary files
run: rm sites.json