-
Notifications
You must be signed in to change notification settings - Fork 2
107 lines (99 loc) · 4.35 KB
/
deploy.yml
File metadata and controls
107 lines (99 loc) · 4.35 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Deploy Workflow
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Branch Name
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Get Commit Message
run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B | head -n 1)" >> $GITHUB_ENV
- name: Deploy to Server via SSH
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.PORT }}
script: |
set -e
cd ~/git/socketing-socket-server
git clean -fd
git fetch
git reset --hard origin/master
cp .env.production .env -f
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" >/tmp/vault_password
ansible-vault decrypt .env --vault-password-file=/tmp/vault_password
rm /tmp/vault_password
./run.sh -m p -f
- name: Send Discord Notification on Success with Embed
if: success()
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK }}
GITHUB_REPOSITORY: ${{ github.repository }}
REPO_URL: https://github.com/${{ github.repository }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMMIT_MESSAGE: ${{ env.COMMIT_MESSAGE }}
COMMIT_SHA: ${{ github.sha }}
COMMIT_URL: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
GITHUB_ACTOR: ${{ github.actor }}
run: |
curl -H "Content-Type: application/json" \
-d '{
"embeds": [{
"title": "✅ Deployment Succeeded",
"description": "[View Repository]('"${REPO_URL}"') | [View Commit]('"${COMMIT_URL}"')",
"color": 3066993,
"fields": [
{"name": "Repository", "value": "[**'"${GITHUB_REPOSITORY}"'**]('"${REPO_URL}"')", "inline": true},
{"name": "Branch", "value": "`'"${BRANCH_NAME}"'`", "inline": true},
{"name": "Commit Message", "value": "'"${COMMIT_MESSAGE}"'", "inline": false},
{"name": "Triggered By", "value": "'"${GITHUB_ACTOR}"'", "inline": true},
{"name": "Commit SHA", "value": "[`'"${COMMIT_SHA}"'`]('"${COMMIT_URL}"')", "inline": false}
],
"footer": {
"text": "Deployment Status"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
$DISCORD_WEBHOOK_URL
- name: Send Discord Notification on Failure with Embed
if: failure()
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK }}
GITHUB_REPOSITORY: ${{ github.repository }}
REPO_URL: https://github.com/${{ github.repository }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMMIT_MESSAGE: ${{ env.COMMIT_MESSAGE }}
COMMIT_SHA: ${{ github.sha }}
COMMIT_URL: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
GITHUB_ACTOR: ${{ github.actor }}
run: |
curl -H "Content-Type: application/json" \
-d '{
"embeds": [{
"title": "❌ Deployment Failed",
"description": "[View Repository]('"${REPO_URL}"') | [View Commit]('"${COMMIT_URL}"')",
"color": 15158332,
"fields": [
{"name": "Repository", "value": "[**'"${GITHUB_REPOSITORY}"'**]('"${REPO_URL}"')", "inline": true},
{"name": "Branch", "value": "`'"${BRANCH_NAME}"'`", "inline": true},
{"name": "Commit Message", "value": "'"${COMMIT_MESSAGE}"'", "inline": false},
{"name": "Triggered By", "value": "'"${GITHUB_ACTOR}"'", "inline": true},
{"name": "Commit SHA", "value": "[`'"${COMMIT_SHA}"'`]('"${COMMIT_URL}"')", "inline": false}
],
"footer": {
"text": "Deployment Status"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
$DISCORD_WEBHOOK_URL