diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml new file mode 100644 index 0000000..98b9fac --- /dev/null +++ b/.github/workflows/nextjs.yml @@ -0,0 +1,101 @@ +name: Deploy Next.js site to Vercel + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + workflow_dispatch: + +# Allow only one concurrent deployment +concurrency: + group: "vercel" + cancel-in-progress: false + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + SKIP_ENV_VALIDATION: true + NODE_ENV: "test" + +jobs: + build: + runs-on: ubuntu-latest + env: + NEXTAUTH_SECRET: "dummy-value-for-testing" + GOOGLE_CLIENT_ID: "dummy-value-for-testing" + GOOGLE_CLIENT_SECRET: "dummy-value-for-testing" + GOOGLE_GEMINI_API: "dummy-value-for-testing" + AUTH_DISCORD_ID: "dummy-value-for-testing" + AUTH_DISCORD_SECRET: "dummy-value-for-testing" + AUTH_GITHUB_ID: "dummy-value-for-testing" + AUTH_GITHUB_SECRET: "dummy-value-for-testing" + DATABASE_URL: "postgresql://dummy:dummy@localhost:5432/dummy" + EMAIL_USER: "dummy@example.com" + EMAIL_PASS: "dummy-value-for-testing" + UPSTASH_REDIS_REST_URL: "https://dummy.upstash.io" + UPSTASH_REDIS_REST_TOKEN: "dummy-value-for-testing" + CSRF_SECRET: "dummy-value-for-testing" + NEXT_PUBLIC_APP_URL: "http://localhost:3000" + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Detect package manager + id: detect-package-manager + run: | + if [ -f "${{ github.workspace }}/yarn.lock" ]; then + echo "manager=yarn" >> $GITHUB_OUTPUT + echo "command=install" >> $GITHUB_OUTPUT + echo "runner=yarn" >> $GITHUB_OUTPUT + exit 0 + elif [ -f "${{ github.workspace }}/package.json" ]; then + echo "manager=npm" >> $GITHUB_OUTPUT + echo "command=ci" >> $GITHUB_OUTPUT + echo "runner=npx --no-install" >> $GITHUB_OUTPUT + exit 0 + else + echo "Unable to determine package manager" + exit 1 + fi + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: ${{ steps.detect-package-manager.outputs.manager }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + .next/cache + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} + restore-keys: | + ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- + + - name: Install dependencies + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} + + - name: Type check + run: npm run typecheck + + - name: Lint + run: npm run lint + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build Project Artifacts + run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} + + deploy: + needs: build + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - name: Deploy to Vercel + run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}