This file contains 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: Preview 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 }} | |
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-ignore: | |
- main | |
jobs: | |
Deploy-Preview: | |
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: Cache playwright binaries | |
uses: actions/cache@v3 | |
id: playwright-cache | |
with: | |
path: | | |
~/.cache/ms-playwright | |
key: ${{ runner.os }}-playwright-14 | |
- run: pnpm install | |
- 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 to build @bottlesteam/bottle | |
- name: Determine build status for @bottlesteam/bottle | |
id: determine-status | |
run: | | |
# turbo run build --dry-run=json 명령어 실행 및 결과 저장 | |
pnpx turbo run build --dry-run=json > result.json | |
# jq 명령어를 사용하여 @bottlesteam/bottle 패키지의 빌드 필요 여부 확인 | |
build_status=$(jq -r '.tasks[] | select(.taskId == "@bottlesteam/bottle#build") | .cache.status' result.json) | |
echo "Build status for @bottlesteam/bottle: $build_status" | |
# Set the build_status as an output variable for the job | |
echo "::set-output name=build_status::$build_status" | |
#to here | |
- run: pnpx playwright install | |
if: steps.playwright-cache.outputs.cache-hit != 'true' | |
- run: pnpx playwright install-deps | |
- run: pnpm run ci | |
- name: Exit without error if no build needed | |
if: steps.determine-status.outputs.build_status != 'MISS' | |
run: | | |
echo "No need to build @bottlesteam/bottle. Exiting..." | |
exit 0 | |
- name: Deploy to Vercel if needed | |
if: steps.determine-status.outputs.build_status != 'MISS' | |
run: | | |
npm install --global vercel@latest | |
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_ACCESS_TOKEN }} | |
vercel build --token=${{ secrets.VERCEL_ACCESS_TOKEN }} | |
vercel deploy --prebuilt --token=${{ secrets.VERCEL_ACCESS_TOKEN }} | |
- name: Get Vercel Preview | |
if: steps.determine-status.outputs.build_status != 'MISS' | |
uses: zentered/[email protected] | |
id: vercel_preview_url | |
env: | |
VERCEL_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }} | |
with: | |
vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID_BOTTLE }} | |
- name: Get URL | |
if: steps.determine-status.outputs.build_status != 'MISS' | |
run: echo "https://${{ steps.vercel_preview_url.outputs.preview_url }}" | |
- name: Send Discord Notification | |
if: steps.determine-status.outputs.build_status != 'MISS' | |
env: | |
DATA: | | |
{ | |
"content": "<@stakbucks>", | |
"embeds": [ | |
{ | |
"title": "👀 Bottle 미리보기가 준비되었어요", | |
"description": "👉 https://${{ steps.vercel_preview_url.outputs.preview_url }}", | |
"color": 65280 | |
} | |
] | |
} | |
run: | | |
curl -X POST -H 'Content-type: application/json' \ | |
-d "$DATA" \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} |