Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CI/CD for Backend

on:
# --------------------------
# pull_request:
# => PRが作られたとき → テストのみ
# --------------------------
pull_request:
branches: [develop, main]

# --------------------------
# push:
# => develop, main に push
# → デプロイ (stageを切り替え)
# --------------------------
push:
branches: [develop, main]

jobs:
deploy-backend:
runs-on: ubuntu-latest

steps:
# (1) コード取得
- name: Check out code
uses: actions/checkout@v3

# (2) Node セットアップ
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18

# (3) 依存関係インストール
- name: Install dependencies
run: |
cd backend
npm ci

# (4) テスト実行
# → pull_request / push 両方で実行
- name: Run tests
run: |
cd backend
npm run test

# (5) AWS認証 (push時のみ)
- name: Configure AWS Credentials
if: ${{ github.event_name == 'push' }}
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

# (6) デプロイ (develop→dev, main→prod)
- name: Deploy
if: ${{ github.event_name == 'push' }}
run: |
cd backend
# Secrets から必要な変数を export
export BUCKET_NAME="${{ secrets.BUCKET_NAME }}"
export AWS_REGION="${{ secrets.AWS_REGION }}"

if [ "${{ github.ref_name }}" = "develop" ]; then
echo "Deploying to dev stage..."
npm run deploy:dev # 例) package.json: "deploy:dev": "serverless deploy --stage dev"

elif [ "${{ github.ref_name }}" = "main" ]; then
echo "Deploying to prod stage..."
npm run deploy:prod # 例) package.json: "deploy:prod": "serverless deploy --stage prod"

else
echo "Not on develop or main => Skip"
fi
99 changes: 99 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Frontend CI/CD

on:
pull_request:
branches: [develop, main]
push:
branches: [develop, main]

jobs:
# ---- 1) pull_request -> テストのみ ----
testOnPR:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
working-directory: ./frontend
run: npm ci

- name: Run tests
working-directory: ./frontend
run: npm run test


# ---- 2) push to develop -> ステージングビルド & デプロイ ----
buildAndDeployDev:
if: github.event_name == 'push' && github.ref_name == 'develop'
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
working-directory: ./frontend
run: npm ci

- name: Build dev
working-directory: ./frontend
run: |
# Secretsから dev用のAPIエンドポイントなどを環境変数に注入
export VITE_API_BASE_URL="${{ secrets.DEV_API_BASE_URL }}"
npm run build:dev # 例: "build:dev": "vite build --mode dev"

- name: Deploy to S3 (dev)
working-directory: ./frontend
run: |
aws s3 sync dist s3://${{ secrets.S3_DEV_BUCKET }} --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}


# ---- 3) push to main -> 本番ビルド & デプロイ ----
buildAndDeployProd:
if: github.event_name == 'push' && github.ref_name == 'main'
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
working-directory: ./frontend
run: npm ci

- name: Build prod
working-directory: ./frontend
run: |
export VITE_API_BASE_URL="${{ secrets.PROD_API_BASE_URL }}"
npm run build:prod

- name: Deploy to S3 (prod)
working-directory: ./frontend
run: |
aws s3 sync dist s3://${{ secrets.S3_PROD_BUCKET }} --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# my custom
*/.env.*
!*/.env.sample
!frontend/.env.local
.idea/
dist/
.serverless/

mdstream_project_summary.txt

/tmp
/out-tsc

/node_modules
*/node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand Down
1 change: 1 addition & 0 deletions .summaryignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/package-lock.json
Loading
Loading