Merge pull request #1607 from AtCoder-NoviSteps/dependabot/npm_and_ya… #3060
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
# See: | |
# https://docs.github.com/en/actions/guides/building-and-testing-nodejs#building-and-testing-your-code | |
# https://pnpm.io/ja/continuous-integration#github-actions | |
# https://vercel.com/guides/how-can-i-use-github-actions-with-vercel | |
# https://zenn.dev/ttskch/articles/691fb62fbb6b1b | |
# https://vercel.com/guides/set-up-a-staging-environment-on-vercel | |
# https://vercel.com/docs/projects/domains/add-a-domain#verify-domain-access | |
# https://vercel.com/docs/cli/global-options#scope | |
# https://www.prisma.io/docs/orm/prisma-client/deployment/deploy-database-changes-with-prisma-migrate | |
# https://www.prisma.io/docs/orm/prisma-migrate/workflows/baselining | |
# https://github.com/pnpm/action-setup/issues/99#issuecomment-1918361558 | |
name: CI | |
env: | |
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'staging' | |
pull_request: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [20.x, 22.x] | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Use corepack | |
run: corepack enable | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build | |
run: pnpm build | |
- name: Lint | |
run: pnpm lint | |
- name: Unit test | |
run: pnpm test:unit | |
# TODO: Run integration test | |
# - name: Integration test | |
# run: pnpm test:integration | |
preview: | |
if: ${{ github.ref != 'refs/heads/main' }} | |
needs: build | |
runs-on: ubuntu-latest | |
environment: | |
name: preview | |
url: ${{ steps.deploy.outputs.url }} | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Use corepack | |
run: corepack enable | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
check-latest: true | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build | |
run: pnpm build | |
- name: Apply all pending migrations to the database | |
run: pnpm dlx prisma migrate deploy | |
env: | |
DATABASE_URL: ${{ secrets.PREVIEW_DATABASE_URL }} | |
- name: Pull Vercel Environment Information | |
run: pnpm vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Build Project Artifacts | |
run: pnpm vercel build --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Deploy Project Artifacts to Vercel | |
id: deploy | |
run: echo "url=\"$(pnpm vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})\"" >> $GITHUB_OUTPUT | |
- name: Assign staging domain to deployment (if staging branch) | |
if: ${{ github.ref != 'refs/heads/main' }} | |
run: pnpm vercel alias set ${{ steps.deploy.outputs.url }} ${{ secrets.STAGING_DOMAIN }} --scope=${{ secrets.VERCEL_SCOPE }} --token=${{ secrets.VERCEL_TOKEN }} | |
production: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Use corepack | |
run: corepack enable | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
check-latest: true | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build | |
run: pnpm build | |
- name: Apply all pending migrations to the database | |
run: pnpm dlx prisma migrate deploy | |
env: | |
DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }} | |
- name: Pull Vercel Environment Information | |
run: pnpm vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Build Project Artifacts | |
run: pnpm vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Deploy Project Artifacts to Vercel | |
run: pnpm vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }} |