-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (129 loc) · 4.65 KB
/
main.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Deploy Application
on:
push:
branches: [main, revert]
jobs:
create-deployment-environment:
name: Create Deployment Environment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Compile Assets
run: |
npm install
npm run prod
- name: Configure PHP
uses: shivammathur/setup-php@master
with:
php-version: 8.2
- name: Configure Composer
run: |
composer update
composer install --optimize-autoloader --no-dev --no-interaction --prefer-dist
- name: Create Deployment archive
env:
GITHUB_SHA: ${{ github.sha }}
run: tar -czf "${GITHUB_SHA}".tar.gz --exclude=*.git --exclude=node_modules *
- name: Store archive for distribution
uses: actions/upload-artifact@v3
with:
name: app-build
path: ${{github.sha}}.tar.gz
prepare-release-on-server:
name: Prepare release on server
runs-on: ubuntu-latest
needs: create-deployment-environment
steps:
- uses: actions/download-artifact@v3
with:
name: app-build
- name: Upload
uses: appleboy/scp-action@master
with:
host: ${{ SECRETS.SERVER_HOST }}
port: ${{ SECRETS.SERVER_PORT }}
username: ${{ SECRETS.SERVER_USERNAME }}
password: ${{ SECRETS.SERVER_PASSWORD }}
source: ${{github.sha}}.tar.gz
target: domains/codebumble.net/public_html
- name: Extract archive and create directory
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{ github.sha }}
with:
host: ${{ SECRETS.SERVER_HOST }}
port: ${{ SECRETS.SERVER_PORT }}
username: ${{ SECRETS.SERVER_USERNAME }}
password: ${{ SECRETS.SERVER_PASSWORD }}
envs: GITHUB_SHA
script: |
rm -rf domains/codebumble.net/public_html/cbl_system
mkdir -p domains/codebumble.net/public_html/cbl_system
tar xzf domains/codebumble.net/public_html/${GITHUB_SHA}.tar.gz -C "domains/codebumble.net/public_html/cbl_system"
active-release:
name: Codebumble Server 1 - Active Release
runs-on: ubuntu-latest
needs: [create-deployment-environment, prepare-release-on-server]
steps:
- name: Active Release
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{github.sha}}
BASE_PATH: public_html/cbl_system
PROJECT_ENV: ${{ SECRETS.PROJECT_ENV }}
CONF_CACHE: ${{ SECRETS.CONF_CACHE }}
ROUTE_CACHE: ${{ SECRETS.ROUTE_CACHE }}
VIEW_CACHE: ${{ SECRETS.VIEW_CACHE }}
HTACCESS: ${{ SECRETS.HTACCESS }}
with:
host: ${{ SECRETS.SERVER_HOST }}
port: ${{ SECRETS.SERVER_PORT }}
username: ${{ SECRETS.SERVER_USERNAME }}
password: ${{ SECRETS.SERVER_PASSWORD }}
envs: GITHUB_SHA,BASE_PATH,PROJECT_ENV,CONF_CACHE,ROUTE_CACHE,VIEW_CACHE,HTACCESS
script: |
echo ${GITHUB_SHA}
printf "%s" "$PROJECT_ENV" > "${BASE_PATH}/.env"
printf "%s" "${GITHUB_SHA}" > "${BASE_PATH}/${GITHUB_SHA}.txt"
printf "%s" "$HTACCESS" > "${BASE_PATH}/.htaccess"
cd ${BASE_PATH} && ${CONF_CACHE} && ${ROUTE_CACHE} && ${VIEW_CACHE}
migrating-db:
name: Migrating Database
runs-on: ubuntu-latest
needs:
[create-deployment-environment, prepare-release-on-server, active-release]
steps:
- name: Migration Init
uses: appleboy/ssh-action@master
env:
BASE_PATH: domains/codebumble.net/public_html/cbl_system
ARTISAN_MIGRATE: ${{ SECRETS.ARTISAN_MIGRATE }}
with:
envs: BASE_PATH,ARTISAN_MIGRATE,
host: ${{ SECRETS.SERVER_HOST }}
port: ${{ SECRETS.SERVER_PORT }}
username: ${{ SECRETS.SERVER_USERNAME }}
password: ${{ SECRETS.SERVER_PASSWORD }}
script: |
cd ${BASE_PATH} && ${ARTISAN_MIGRATE}
clean-up:
name: Cleaning Up Artifacts
runs-on: ubuntu-latest
needs:
[
create-deployment-environment,
prepare-release-on-server,
active-release,
migrating-db,
]
steps:
- name: Clean up server junk
uses: appleboy/ssh-action@master
with:
host: ${{ SECRETS.SERVER_HOST }}
port: ${{ SECRETS.SERVER_PORT }}
username: ${{ SECRETS.SERVER_USERNAME }}
password: ${{ SECRETS.SERVER_PASSWORD }}
script: |
rm -rf domains/codebumble.net/public_html/${{github.sha}}.tar.gz
rm -rf domains/codebumble.net/public_html/cbl_system/${{github.sha}}.txt