-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy-workflow.yml
70 lines (59 loc) · 2.09 KB
/
deploy-workflow.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
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Deploy to Server
on:
push:
branches:
- main
- dev
release:
types:
- published
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
# Create dev deployment on GitHub via bobheadxi/deployments@v1
- name: Start Deployment
id: deployment
uses: bobheadxi/deployments@v1
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
# Both environments need to be created manually in the repo settings on GitHub
# Go to Repo Settings > Environment -> New Environment
# Conditionally set env based on push or release event
# Set your own logic here based on your git flow
env: ${{ github.event_name == 'push' && 'development' || 'production' }}
- name: Setup knownhosts
env:
SERVER_KEYSCAN: ${{ secrets.SERVER_KEYSCAN }}
run: |
mkdir -p ~/.ssh
echo "$SERVER_KEYSCAN" >> ~/.ssh/known_hosts
cat ~/.ssh/known_hosts
- name: Deploy to server
env:
SERVER_SSH_KEY: ${{ secrets.SERVER_SSH_KEY }}
SERVER_ADDRESS: ${{ secrets.SERVER_ADDRESS }}
SERVER_KEYSCAN: ${{ secrets.SERVER_KEYSCAN }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
run: |
echo "$SERVER_SSH_KEY" > private_key
chmod 600 private_key
REF_NAME=$(basename ${{ github.ref }})
if [ "${{ github.event_name }}" == "push" ]; then
ssh -i private_key $DEPLOY_USER@$SERVER_ADDRESS "./deploy.sh --repo ${{ github.repository }} --branch $REF_NAME"
elif [ "${{ github.event_name }}" == "release" ]; then
ssh -i private_key $DEPLOY_USER@$SERVER_ADDRESS "./deploy.sh --repo ${{ github.repository }} --tag $REF_NAME"
fi
rm -f private_key
- name: Update deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}