diff --git a/.github/composite/deploy-vercel/action.yaml b/.github/composite/deploy-vercel/action.yaml new file mode 100644 index 000000000..12c144ec7 --- /dev/null +++ b/.github/composite/deploy-vercel/action.yaml @@ -0,0 +1,58 @@ +name: 'Deploy vercel' +description: 'Deploy GitBook to Vercel' +inputs: + vercel-org: + description: 'Vercel organization' + required: true + vercel-project: + description: 'Vercel project' + required: true + vercel-token: + description: 'Vercel token' + required: true + environment: + description: 'Environment to deploy to' + required: true +outputs: + deployment-url: + description: "Deployment URL" + value: ${{ steps.deploy.outputs.deployment-url }} +runs: + using: 'composite' + steps: + - name: Setup Bun + uses: ./.github/composite/setup-bun + - name: Install dependencies + run: bun install --frozen-lockfile + shell: bash + env: + PUPPETEER_SKIP_DOWNLOAD: 1 + - name: Sets env vars for environment + shell: bash + run: | + echo "VERCEL_ENVIRONMENT=${{ inputs.environment }}" >> $GITHUB_ENV + - name: Pull Vercel Environment Information + run: bun run vercel pull --yes --environment=$VERCEL_ENVIRONMENT --token=${{ inputs.vercel-token }} + shell: bash + env: + VERCEL_ORG_ID: ${{ inputs.vercel-org }} + VERCEL_PROJECT_ID: ${{ inputs.vercel-project }} + - name: Build Project Artifacts + run: bun run vercel build --target=$VERCEL_ENVIRONMENT --token=${{ inputs.vercel-token }} + shell: bash + env: + VERCEL_ORG_ID: ${{ inputs.vercel-org }} + VERCEL_PROJECT_ID: ${{ inputs.vercel-project }} + - name: Deploy Project Artifacts to Vercel + id: deploy + shell: bash + run: | + DEPLOYMENT_URL=$(bun run vercel deploy --prebuilt --target=$VERCEL_ENVIRONMENT --token=${{ inputs.vercel-token }}) + echo "deployment-url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT" + env: + VERCEL_ORG_ID: ${{ inputs.vercel-org }} + VERCEL_PROJECT_ID: ${{ inputs.vercel-project }} + - name: Outputs + shell: bash + run: | + echo "URL: ${{ steps.deploy.outputs.deployment-url }}" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a13ef5d9a..2821d0731 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -87,49 +87,41 @@ jobs: statuses: write outputs: deployment-url: ${{ steps.deploy.outputs.deployment-url }} - env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup Bun - uses: ./.github/composite/setup-bun - - name: Install dependencies - run: bun install --frozen-lockfile - env: - PUPPETEER_SKIP_DOWNLOAD: 1 - - name: Sets env vars for production - run: | - echo "VERCEL_ENVIRONMENT=production" >> $GITHUB_ENV - echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV - echo "GITBOOK_URL=https://open-2v.gitbook.com" >> $GITHUB_ENV - echo "GITBOOK_ASSETS_PREFIX=https://static-2v.gitbook.com" >> $GITHUB_ENV - if: startsWith(github.ref, 'refs/heads/main') - - name: Sets env vars for preview - run: | - echo "VERCEL_ENVIRONMENT=preview" >> $GITHUB_ENV - echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV - if: 1 && !startsWith(github.ref, 'refs/heads/main') - - name: Pull Vercel Environment Information - run: bun run vercel pull --yes --environment=$VERCEL_ENVIRONMENT --token=${{ secrets.VERCEL_TOKEN }} - - name: Build Project Artifacts - run: bun run vercel build --target=$VERCEL_ENVIRONMENT --token=${{ secrets.VERCEL_TOKEN }} - env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }} - SENTRY_ORG: ${{ vars.SENTRY_ORG }} - SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} - SENTRY_DSN: ${{ vars.SENTRY_DSN }} - SENTRY_RELEASE: ${{ github.sha }} - - name: Deploy Project Artifacts to Vercel + - name: Deploy ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }} id: deploy - run: | - DEPLOYMENT_URL=$(bun run vercel deploy --prebuilt --target=$VERCEL_ENVIRONMENT --token=${{ secrets.VERCEL_TOKEN }}) - echo "deployment-url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT" - - name: Outputs - run: | - echo "URL: ${{ steps.deploy.outputs.deployment-url }}" + uses: ./.github/composite/deploy-vercel + with: + environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }} + vercel-org: ${{ secrets.VERCEL_ORG_ID }} + vercel-project: ${{ secrets.VERCEL_PROJECT_ID }} + vercel-token: ${{ secrets.VERCEL_TOKEN }} + deploy-v2-vercel-staging: + name: Deploy v2 to Vercel (staging) + runs-on: ubuntu-latest + permissions: + contents: read + deployments: write + issues: write + pull-requests: write + checks: write + statuses: write + if: startsWith(github.ref, 'refs/heads/main') + outputs: + deployment-url: ${{ steps.deploy.outputs.deployment-url }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Deploy staging + id: deploy + uses: ./.github/composite/deploy-vercel + with: + environment: staging + vercel-org: ${{ secrets.VERCEL_ORG_ID }} + vercel-project: ${{ secrets.VERCEL_PROJECT_ID }} + vercel-token: ${{ secrets.VERCEL_TOKEN }} deploy-v2-cloudflare: name: Deploy v2 to Cloudflare Worker runs-on: ubuntu-latest @@ -142,9 +134,6 @@ jobs: statuses: write outputs: deployment-url: ${{ steps.deploy.outputs.deployment-url }} - env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} steps: - name: Checkout uses: actions/checkout@v4