Merge pull request #18 from MLH-Fellowship/development #8
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: Deploy | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
name: Run Tests | |
env: | |
TESTING: true | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10.12' | |
- name: Setup Python Virtual Environment | |
run: python -m venv python3-virtualenv | |
- name: Install Dependencies | |
run: python3-virtualenv/bin/pip install -r requirements.txt | |
- name: Run Tests | |
run: ./run_test.sh | |
deploy: | |
name: "Deploy to VPS" | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy-key.pem | |
chmod 600 ~/.ssh/deploy-key.pem | |
cat >> ~/.ssh/config <<END | |
Host my-vps | |
HostName $SSH_IP | |
User $SSH_USER | |
IdentityFile ~/.ssh/deploy-key.pem | |
StrictHostKeyChecking no | |
END | |
env: | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SSH_IP: ${{ secrets.SSH_IP }} | |
- name: Deploy Site | |
run: ssh my-vps '~/redeploy-site.sh' | |
- name: Check Container Status | |
run: ssh my-vps 'docker ps' | |
- name: Get Current Date | |
id: get-date | |
run: echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV | |
shell: bash | |
- name: Send Discord Notification | |
if: success() | |
run: | | |
curl -s -H "Content-Type: application/json" \ | |
-X POST "${{ secrets.DISCORD_WEBHOOK }}" \ | |
-d '{ | |
"username": "Deploy Buddy", | |
"avatar_url": "https://repository-images.githubusercontent.com/130118224/a2c75780-e0a9-11eb-8494-3581a0b1c93b", | |
"embeds": [ | |
{ | |
"title": "🚀 Deployment Successful", | |
"description": "Deployed commit `${{ github.sha }}` by `${{ github.actor }}` to production.", | |
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}", | |
"color": 3066993, | |
"fields": [ | |
{ | |
"name": "Branch", | |
"value": "`${{ github.ref }}`", | |
"inline": true | |
}, | |
{ | |
"name": "Time", | |
"value": "`${{ env.date }}`", | |
"inline": true | |
} | |
] | |
} | |
] | |
}' | |
- name: Send Failure Discord Notification | |
if: failure() | |
run: | | |
curl -s -H "Content-Type: application/json" \ | |
-X POST "${{ secrets.DISCORD_WEBHOOK }}" \ | |
-d '{ | |
"username": "Deploy Buddy", | |
"avatar_url": "https://i.imgur.com/z1CEtgs.jpeg", | |
"embeds": [ | |
{ | |
"title": "🚨 Deployment Failed", | |
"description": "Failed to deploy commit`${{ github.sha }}` by `${{ github.actor }}` to production.", | |
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}", | |
"color": 16711680, | |
"fields": [ | |
{ | |
"name": "Branch", | |
"value": "`${{ github.ref }}`", | |
"inline": true | |
}, | |
{ | |
"name": "Time", | |
"value": "`${{ env.date }}`", | |
"inline": true | |
} | |
] | |
} | |
] | |
}' | |