init]Serverless access keyの追加 #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }} |