-
Notifications
You must be signed in to change notification settings - Fork 43
80 lines (79 loc) · 3.05 KB
/
deploy.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
71
72
73
74
75
76
77
78
79
80
name: Deploy with Capistrano
on:
push:
branches: [ rc, master, main]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
outputs:
github_envs: ${{ steps.branch_check.outputs.github_envs }}
deploy_env: ${{ steps.branch_check.outputs.deploy_env }}
steps:
- name: Choose Environment
id: branch_check
run: |
echo "Running on branch ${{ github.ref }}"
if [ "${{ github.ref }}" = "refs/heads/master" ] || [ "${{ github.ref }}" = "refs/heads/main" ]; then
ENV_ARRAY="${{secrets.CLIENT_ENVS}}"
ENV_ARRAY="${ENV_ARRAY//, /,}"
ENV_ARRAY="${ENV_ARRAY//,/\",\"}"
echo "github_envs={\"value\":[\"${ENV_ARRAY}\"]}" >> $GITHUB_OUTPUT
echo "deploy_env=production" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/rc" ]; then
echo "github_envs={\"value\":['staging']}" >> $GITHUB_OUTPUT
echo "deploy_env=staging" >> $GITHUB_OUTPUT
fi
deploy:
needs: build
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJSON(needs.build.outputs.github_envs)}}
fail-fast: false
environment:
name: ${{ matrix.value }}
env:
SERVER_IP: ${{ secrets.SERVER_IP }}
BRANCH: ${{ secrets.BRANCH }}
steps:
- uses: actions/checkout@v3
- name: Install Rbenv
run: |
sudo git clone https://github.com/rbenv/rbenv.git /home/runner/.rbenv
sudo apt-get update
sudo apt-get install -y libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev
sudo git clone https://github.com/rbenv/ruby-build.git /home/runner/.rbenv/plugins/ruby-build
sudo chown -R runner /home/runner/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $GITHUB_PATH
source $GITHUB_PATH
eval "$(rbenv init -)"
rbenv install -s `cat .ruby-version`
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.6
bundler-cache: true
- uses: actions/setup-node@v3
with:
node-version: 14.x
- name: Add public IP to AWS security group
uses: sohelamin/aws-security-group-add-ip-action@master
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
aws-security-group-id: ${{ secrets.AWS_SECURITY_GROUP_ID }}
port: '22'
to-port: '30'
protocol: 'tcp'
description: 'GitHub Action'
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- uses: miloserdow/capistrano-deploy@master
with:
target: ${{ needs.build.outputs.deploy_env }} # Defines the environment that will be used for the deployment
enc_rsa_key_val: ${{ secrets.DEPLOY_ID_RSA_ENC }}
deploy_key: ${{ secrets.DEPLOY_ENC_KEY }}