-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·177 lines (170 loc) · 5.53 KB
/
ci.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Build
on: [push]
jobs:
code_check_backend:
runs-on: ubuntu-latest
container:
image: ghcr.io/gotoeveryone/composer-php:8.2
steps:
- uses: actions/checkout@v4
- name: Cache modules
uses: actions/cache@v4
id: vendor_cache
with:
path: vendor
key: ${{ runner.OS }}-vendor-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
if: ${{ steps.vendor_cache.outputs.cache-hit != 'true' }}
run: composer install
- name: Execute code check
run: composer cs-check
code_check_frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci
- name: Execute code check
run: npm run lint
test_backend:
timeout-minutes: 3
runs-on: ubuntu-latest
# 本来はこの方法でテストを実行したいが、service として立ち上げる MySQL は非 ASCII 文字に対応しておらずエラーになるため一旦断念
# container:
# image: ghcr.io/gotoeveryone/composer-php:7.4
# services:
# database:
# image: mysql:5.7
# ports:
# - 3306:3306
# env:
# MYSQL_DATABASE: 'gotea_test'
# MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
# options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
env:
DB_TEST_HOST: '127.0.0.1'
DB_TEST_PORT: 33306
DB_TEST_USERNAME: 'root'
DB_TEST_PASSWORD: ''
DB_TEST_NAME: 'gotea_test'
DB_TEST_ENCODING: 'utf8mb4'
DB_TEST_TIMEZONE: 'Asia/Tokyo'
SECURITY_SALT: ${{ secrets.SECURITY_SALT }}
TZ: Asia/Tokyo
SENTRY_DSN: ''
steps:
- name: Set up MySQL
run: >
docker run \
-e MYSQL_DATABASE=${DB_TEST_NAME} \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
-d \
-p ${DB_TEST_PORT}:3306 \
mysql:5.7 mysqld --character-set-server=${DB_TEST_ENCODING} --collation-server=${DB_TEST_ENCODING}_general_ci
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: zip, intl, pdo_mysql
ini-values: xdebug.mode="develop"
- name: Wait for MySQL
run: |
while ! mysqladmin ping --host=${DB_TEST_HOST} --port ${DB_TEST_PORT} --silent; do
sleep 1
done
- name: Cache modules
uses: actions/cache@v4
id: vendor_cache
with:
path: vendor
key: ${{ runner.OS }}-vendor-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
if: ${{ steps.vendor_cache.outputs.cache-hit != 'true' }}
run: composer install
- name: Execute setup
if: ${{ steps.vendor_cache.outputs.cache-hit == 'true' }}
run: composer setup
- name: Execute test
run: composer test
test_frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci
- name: Execute code check
run: npm test
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
env:
TAR_NAME: 'gotea_${{ github.run_number }}.tar.gz'
SHELL_DEST_PATH: '~/deploy_${{ github.run_number }}.sh'
runs-on: ubuntu-latest
needs:
- code_check_backend
- code_check_frontend
- test_backend
- test_frontend
steps:
- uses: actions/checkout@v4
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SECRET_KEY }}
name: id_rsa-target
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
config: |
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Host target
HostName ${{ secrets.SSH_HOST }}
User ${{ secrets.SSH_USER }}
Port ${{ secrets.SSH_PORT }}
IdentityFile ~/.ssh/id_rsa-target
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci
- name: Build assets
run: npm run prod
- name: Transfer modules
run: |
tar czf ~/${TAR_NAME} bin/ config/ plugins/ resources/ src/ templates/ webroot/ composer.json composer.lock
scp -r ~/${TAR_NAME} target:~/
scp ./shell/deploy.sh target:${SHELL_DEST_PATH}
- name: Deploy modules
run: ssh target "${SHELL_DEST_PATH} ${TAR_NAME} gotea && rm -f ${SHELL_DEST_PATH}"
notify:
if: ${{ always() && !contains(github.ref, 'dependabot/') }}
needs:
- deploy
runs-on: ubuntu-latest
steps:
- uses: technote-space/workflow-conclusion-action@v3
- name: Notify to Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ env.WORKFLOW_CONCLUSION }}
author_name: GitHub Actions
fields: message,ref
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}