diff --git a/.github/workflows/ci-production.yaml b/.github/workflows/ci-production.yaml new file mode 100644 index 0000000..483e0f1 --- /dev/null +++ b/.github/workflows/ci-production.yaml @@ -0,0 +1,171 @@ +name: Production CI +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + TURBO_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + NEXT_PUBLIC_SERVER_BASE_URL: ${{secrets.NEXT_PUBLIC_SERVER_BASE_URL }} + TEST_ACCESS_TOKEN: ${{secrets.TEST_ACCESS_TOKEN }} + TEST_REFRESH_TOKEN: ${{secrets.TEST_REFRESH_TOKEN }} +on: + push: + branches: + - main +jobs: + Setup: + runs-on: ubuntu-latest + outputs: + cache_status_bottle: ${{ steps.determine-status.outputs.cache_status_bottle }} + cache_status_web: ${{ steps.determine-status.outputs.cache_status_web }} + cache_status_e2e: ${{ steps.determine-status.outputs.cache_status_e2e }} + steps: + # checkout and install pnpm + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 + name: Install pnpm + id: pnpm-install + with: + version: 8 + run_install: false + + # setup node + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + + # install dependencies + - run: npx pnpm i -r + + # set .env.local + - name: create dotenv + run: | + touch apps/bottle/.env.local + echo "TEST_ACCESS_TOKEN=${{ secrets.TEST_ACCESS_TOKEN }}" >> apps/bottle/.env.local + echo "TEST_REFRESH_TOKEN=${{ secrets.TEST_REFRESH_TOKEN }}" >> apps/bottle/.env.local + echo "NEXT_PUBLIC_SERVER_BASE_URL=${{ secrets.NEXT_PUBLIC_SERVER_BASE_URL }}" >> apps/bottle/.env.local + env: + NEXT_PUBLIC_SERVER_BASE_URL: ${{ secrets.NEXT_PUBLIC_SERVER_BASE_URL }} + + # determine whether @bottlesteam/bottle, @bottlesteam/web is cached on remote + - name: Determine cache status for each services + id: determine-status + run: | + pnpx turbo run build --dry-run=json > result.json + cache_status_bottle=$(jq -r '.tasks[] | select(.taskId == "@bottlesteam/bottle#build") | .cache.status' result.json) + cache_status_web=$(jq -r '.tasks[] | select(.taskId == "@bottlesteam/web#build") | .cache.status' result.json) + pnpx turbo run test:e2e --dry-run=json > result2.json + cache_status_e2e=$(jq -r '.tasks[] | select(.taskId == "@bottlesteam/e2e#test:e2e") | .cache.status' result2.json) + echo "cache_status_bottle=$cache_status_bottle" >> $GITHUB_OUTPUT + echo "cache_status_web=$cache_status_web" >> $GITHUB_OUTPUT + echo "cache_status_e2e=$cache_status_e2e" >> $GITHUB_OUTPUT + + - name: Cache Status Print + run: | + echo "cache_status_bottle: ${{ steps.determine-status.outputs.cache_status_bottle }}" + echo "cache_status_web: ${{ steps.determine-status.outputs.cache_status_web }}" + echo "cache_status_e2e: ${{ steps.determine-status.outputs.cache_status_e2e }}" + + # install playwright depedencies only if @bottlesteam/bottle is not cached + - run: pnpx playwright install --with-deps + if: steps.determine-status.outputs.cache_status_e2e == 'MISS' + + # run turbo tasks + - run: pnpm run ci + + Deploy_Bottle_to_Vercel: + # deploy Bottle to vercel + runs-on: ubuntu-latest + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_BOTTLE }} + needs: Setup + if: needs.Setup.outputs.cache_status_bottle == 'MISS' + steps: + # checkout and install pnpm + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 + name: Install pnpm + id: pnpm-install + with: + version: 8 + run_install: false + # setup node + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + + - name: Deploy to Vercel if needed + run: | + npm install --global vercel@latest + vercel pull --yes --environment=production --token=${{ secrets.VERCEL_ACCESS_TOKEN }} + vercel build --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }} + vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }} + + - name: Send Discord Notification + env: + DATA: | + { + "content": "<@stakbucks>", + "embeds": [ + { + "title": "🎉 Bottle 배포 완료! 🎉", + "description": "👉 https://bottle.bottles.asia", + "color": 65280 + } + ] + } + run: | + curl -X POST -H 'Content-type: application/json' \ + -d "$DATA" \ + ${{ secrets.DISCORD_WEBHOOK_URL }} + + Deploy_Web_to_Vercel: + # deploy Web to vercel + runs-on: ubuntu-latest + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_WEB }} + needs: Setup + if: needs.Setup.outputs.cache_status_web == 'MISS' + steps: + # checkout and install pnpm + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 + name: Install pnpm + id: pnpm-install + with: + version: 8 + run_install: false + # setup node + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + + - name: Deploy to Vercel if needed + run: | + npm install --global vercel@latest + vercel pull --yes --environment=production --token=${{ secrets.VERCEL_ACCESS_TOKEN }} + vercel build --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }} + vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }} + env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + - name: Send Discord Notification + env: + DATA: | + { + "content": "<@stakbucks>", + "embeds": [ + { + "title": "🎉 배포 완료! 🎉", + "description": "👉 https://bottles.asia", + "color": 65280 + } + ] + } + run: | + curl -X POST -H 'Content-type: application/json' \ + -d "$DATA" \ + ${{ secrets.DISCORD_WEBHOOK_URL }} diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml deleted file mode 100644 index 68636c7..0000000 --- a/.github/workflows/production.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: Production Deployment - Web -env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - TURBO_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }} - TURBO_TEAM: ${{ vars.TURBO_TEAM }} -on: - push: - branches: - - main -jobs: - Deploy-Production: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v3 - name: Install pnpm - id: pnpm-install - with: - version: 8 - run_install: false - - name: Setup Node.js environment - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: 'pnpm' - - name: Cache turbo build setup - uses: actions/cache@v4 - with: - path: .turbo - key: ${{ runner.os }}-turbo-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-turbo- - - name: Install Vercel CLI - run: npm install --global vercel@latest - - name: Pull Vercel Environment Information - run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_ACCESS_TOKEN }} - - name: Build Project Artifacts - run: vercel build --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }} - - name: Deploy Project Artifacts to Vercel - run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }} - - name: Send Discord Notification - env: - DATA: | - { - "content": "<@stakbucks>", - "embeds": [ - { - "title": "🎉 배포 완료! 🎉", - "description": "👉 https://bottles.asia", - "color": 65280 - } - ] - } - run: | - curl -X POST -H 'Content-type: application/json' \ - -d "$DATA" \ - ${{ secrets.DISCORD_WEBHOOK_URL }} diff --git a/.github/workflows/production_bottle.yaml b/.github/workflows/production_bottle.yaml deleted file mode 100644 index 7aba7b8..0000000 --- a/.github/workflows/production_bottle.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: Production Deployment - Bottle -env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_BOTTLE }} - TURBO_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }} - TURBO_TEAM: ${{ vars.TURBO_TEAM }} -on: - push: - branches: - - main -jobs: - Deploy-Production: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v3 - name: Install pnpm - id: pnpm-install - with: - version: 8 - run_install: false - - name: Setup Node.js environment - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: 'pnpm' - - name: Cache turbo build setup - uses: actions/cache@v4 - with: - path: .turbo - key: ${{ runner.os }}-turbo-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-turbo- - - name: Install Vercel CLI - run: npm install --global vercel@latest - - name: Pull Vercel Environment Information - run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_ACCESS_TOKEN }} - - name: Build Project Artifacts - run: vercel build --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }} - - name: Deploy Project Artifacts to Vercel - run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_ACCESS_TOKEN }} - - name: Send Discord Notification - env: - DATA: | - { - "content": "<@stakbucks>", - "embeds": [ - { - "title": "🎉 Bottle 배포 완료! 🎉", - "description": "👉 https://bottle.bottles.asia", - "color": 65280 - } - ] - } - run: | - curl -X POST -H 'Content-type: application/json' \ - -d "$DATA" \ - ${{ secrets.DISCORD_WEBHOOK_URL }}