cool #95
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 Staging | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v2 | |
- name: SSH and Deploy | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -t rsa ${{ secrets.HOST }} >> ~/.ssh/known_hosts | |
ssh -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }} -p ${{ secrets.PORT }} -i ~/.ssh/id_rsa <<EOF | |
cd ~/IMS-Corp | |
git pull origin dev | |
exit | |
EOF | |
- name: Prepare Email | |
id: prepare_email | |
run: | | |
deployment_time=$(TZ=Asia/Kolkata date) | |
git fetch --unshallow | |
last_commit_hash=$(git rev-parse HEAD) | |
author_name=$(git log -1 --format='%an') | |
author_email=$(git log -1 --format='%ae') | |
branch_name=$(git rev-parse --abbrev-ref HEAD) | |
commit_message=$(git log -1 --pretty=%B) | |
files_changed=$(git diff-tree --no-commit-id --name-only -r $last_commit_hash) | |
template_path="./templates/email/notify_deployment-staging.html" | |
content=$(cat $template_path) | |
content=${content//DEPLOYMENT_TIME/$deployment_time} | |
content=${content//AUTHOR_NAME/$author_name} | |
content=${content//AUTHOR_EMAIL/$author_email} | |
content=${content//BRANCH_NAME/$branch_name} | |
content=${content//COMMIT_MESSAGE/$commit_message} | |
content=${content//FILES_CHANGED/$files_changed} | |
ssh -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }} -p ${{ secrets.PORT }} -i ~/.ssh/id_rsa <<EOF | |
cd ~/IMS-Corp | |
mkdir -p emails | |
echo "$content" > emails/notify_deployment-staging.html | |
exit | |
EOF | |
scp -P ${{ secrets.PORT }} -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~/IMS-Corp/emails/notify_deployment-staging.html ./email.html | |
scp -P ${{ secrets.PORT }} -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~/IMS-Corp/mail_list.csv ./mail_list.csv | |
echo "::set-output name=mail_list::$(cat mail_list.csv)" | |
- name: Send Email | |
uses: dawidd6/action-send-mail@v2 | |
with: | |
server_address: ${{ secrets.MAIL_SERVER_ADDRESS }} | |
server_port: ${{ secrets.MAIL_SERVER_PORT }} | |
username: ${{ secrets.MAIL_SERVER_UID }} | |
password: ${{ secrets.MAIL_SERVER_PASS }} | |
subject: IMS Corporate website Deployment on Staging Server | ${{ github.repository }} | |
body: file://email.html | |
content_type: text/html | |
from: Github | Brahmware <${{ secrets.MAIL_SERVER_UID }}> | |
to: Brahmware Admin <${{ secrets.BRAHMWARE_ADMIN }}> | |
bcc: ${{ steps.prepare_email.outputs.mail_list }} | |