-
Notifications
You must be signed in to change notification settings - Fork 0
291 lines (254 loc) · 7.77 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
name: Deploy
on:
push:
paths:
- "src/**"
- ".github/workflows/**"
branches:
- "main"
- "feature/*"
# コンカレンシー
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
# 環境変数
env:
NODE_VERSION: "20"
PYTHON_VERSION: "3.12"
# デフォルトのシェルをbashに設定
defaults:
run:
shell: bash
permissions: read-all
jobs:
set-environment:
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
environment: ${{ steps.set_environment.outputs.environment }}
steps:
- name: Set environment
id: set_environment
run: |
ENVIRONMENT=$([[ "${{ github.ref }}" == "refs/heads/main" ]] && echo "prod" || echo "dev")
echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT
python-lint:
uses: ./.github/workflows/python-lint.yml
with:
python-version: 3.12
python-test:
needs: python-lint
uses: ./.github/workflows/python-test.yml
with:
python-version: 3.12
node-lint:
uses: ./.github/workflows/node-lint.yml
with:
node-version: 20
node-test:
needs: node-lint
uses: ./.github/workflows/node-test.yml
with:
node-version: 20
deploy:
needs: [set-environment, node-test, python-test]
runs-on: ubuntu-latest
# メインブランチの場合は90分、それ以外は60分
timeout-minutes: ${{ github.ref == 'refs/heads/main' && 90 || 60 }}
environment: ${{ needs.set-environment.outputs.environment }}
permissions:
id-token: write
contents: read
pull-requests: write
steps:
# ブランチのチェックアウト
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Nodeのセットアップ
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
# 依存関係のインストール
- name: Install dependencies
run: npm ci
# AWSクレデンシャルの設定
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: "${{ secrets.AWS_REGION }}"
role-to-assume: "arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/${{ secrets.ACTIONS_ROLE }}"
# CDK Synth
- name: CDK Synth
if: startsWith(github.ref, 'refs/heads/feature/')
run: |
npx -w src/backend npm run cdk synth --all
# CDK Deploy
- name: CDK Deploy
if: startsWith(github.ref, 'refs/heads/feature/') || github.ref == 'refs/heads/main'
continue-on-error: ${{ github.ref != 'refs/heads/main' }}
env:
CERTIFICATE_ARN: ${{ secrets.CERTIFICATE_ARN }}
ENVIRONMENT: ${{ needs.set-environment.outputs.environment }}
run: |
npx -w src/backend npm run cdk deploy --all
actions-timeline:
if: always()
needs: [deploy]
runs-on: ubuntu-latest
steps:
- uses: Kesin11/actions-timeline@v2
# name: Backend Deploy
# on:
# push:
# paths:
# - "src/**"
# - ".github/workflows/**"
# branches:
# - "main"
# - "feature/*"
# # デフォルトのシェルをbashに設定
# defaults:
# run:
# shell: bash
# # 環境変数
# env:
# NODE_VERSION: "20"
# PYTHON_VERSION: "3.12"
# jobs:
# # ジョブ: Nodeのセットアップとキャッシュ
# setup-node:
# runs-on: ubuntu-latest
# timeout-minutes: 20
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# # Nodeのセットアップ
# - name: Setup Node
# uses: actions/setup-node@v4
# with:
# node-version: "${{ env.NODE_VERSION }}"
# # 依存関係のインストール
# - name: Install dependencies
# run: npm ci
# # ジョブ: Pythonのセットアップとキャッシュ
# setup-python:
# runs-on: ubuntu-latest
# timeout-minutes: 20
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# # Pythonのセットアップ
# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: "${{ env.PYTHON_VERSION }}"
# # 依存関係のインストール
# - name: Install dependencies
# run: pip install -r requirements.txt
# # ジョブ: 環境変数の設定
# set-environment:
# needs:
# - setup-node
# - setup-python
# runs-on: ubuntu-latest
# timeout-minutes: 3
# steps:
# - name: Set environment
# id: set_environment
# run: |
# # メインブランチの場合、環境をprodに設定
# if [[ ${{ github.ref }} == "refs/heads/main" ]]; then
# echo "environment=prod" >> $GITHUB_OUTPUT
# # フィーチャーブランチの場合、環境をdevに設定
# elif [[ ${{ github.ref }} =~ ^refs/heads/feature/#[0-9]*$ ]]; then
# echo "environment=dev" >> $GITHUB_OUTPUT
# # その他の場合、環境をunknownに設定
# else
# echo "environment=unknown" >> $GITHUB_OUTPUT
# fi
# outputs:
# # 環境変数の出力
# environment: ${{ steps.set_environment.outputs.environment }}
# # ジョブ: Lint
# lint:
# needs:
# - setup-node
# - setup-python
# uses: ./.github/workflows/lint.yml
# # ジョブ: テスト
# test:
# needs:
# - setup-node
# - setup-python
# uses: ./.github/workflows/test.yml
# # ジョブ: PR Agent
# pr-agent:
# # プルリクエストが開いた場合にのみ実行
# if: github.event_name == 'pull_request'
# permissions:
# contents: write
# issues: write
# pull-requests: write
# needs:
# - test
# uses: ./.github/workflows/pr-agent.yml
# # ジョブ: デプロイ
# deploy:
# needs:
# - set-environment
# - lint
# - test
# runs-on: ubuntu-latest
# timeout-minutes: 60
# environment: ${{ needs.set-environment.outputs.environment }}
# permissions:
# id-token: write
# contents: read
# pull-requests: write
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# # Nodeのセットアップ
# - name: Setup Node
# uses: actions/setup-node@v4
# with:
# node-version: "20"
# # npmキャッシュの復元
# - name: Restore npm dependencies
# uses: actions/cache@v4
# with:
# path: |
# ~/.npm
# node_modules
# src/backend/node_modules
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
# # AWSクレデンシャルの設定
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-region: "${{ secrets.AWS_REGION }}"
# role-to-assume: "arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/${{ secrets.ACTIONS_ROLE }}"
# # CDK Synth
# - name: CDK Synth
# if: startsWith(github.ref, 'refs/heads/feature/')
# run: |
# source venv/bin/activate
# npx -w src/backend npm run cdk synth --all
# # CDK Deploy
# - name: CDK Deploy
# if: startsWith(github.ref, 'refs/heads/feature/') || github.ref == 'refs/heads/main'
# env:
# CERTIFICATE_ARN: ${{ secrets.CERTIFICATE_ARN }}
# ENVIRONMENT: ${{ needs.set-environment.outputs.environment }}
# run: |
# source venv/bin/activate
# npx -w src/backend npm run cdk deploy --all
# # ジョブ: アクションのタイムライン
# actions-timeline:
# needs: [lint, test, deploy]
# runs-on: ubuntu-latest
# steps:
# - uses: Kesin11/actions-timeline@v2