Merge pull request #70 from bdsumon4u/dev #239
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |