-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Rocketseat/preview
ci: create preview env workflow
- Loading branch information
Showing
4 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Clean up Preview | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
jobs: | ||
delete-preview: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
|
||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
run_install: false | ||
|
||
- name: Delete Neon Branch | ||
uses: neondatabase/[email protected] | ||
with: | ||
project_id: ${{ secrets.NEON_PROJECT_ID }} | ||
branch: preview/pr-${{ github.event.number }}-${{ github.event.pull_request.head.ref }} | ||
api_key: ${{ secrets.NEON_API_KEY }} | ||
|
||
- name: Install Vercel CLI | ||
run: pnpm i -g vercel@latest | ||
|
||
- name: Delete Vercel Environment Information | ||
run: | | ||
vercel env rm DATABASE_URL preview ${{ steps.branch-name.outputs.current_branch }} --yes --token=${{ secrets.VERCEL_TOKEN }} | ||
vercel env rm DIRECT_DATABASE_URL preview ${{ steps.branch-name.outputs.current_branch }} --yes --token=${{ secrets.VERCEL_TOKEN }} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: Deploy Preview | ||
|
||
on: [pull_request] | ||
|
||
env: | ||
NEON_DATABASE_USERNAME: ${{ secrets.NEON_DATABASE_USERNAME }} | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
NEON_API_KEY: ${{ secrets.NEON_API_KEY }} | ||
NEON_PROJECT_ID: ${{ secrets.NEON_PROJECT_ID }} | ||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
|
||
jobs: | ||
deploy-preview: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Get branch name | ||
id: branch-name | ||
uses: tj-actions/branch-names@v8 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
|
||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
run_install: false | ||
|
||
- name: Get pnpm store directory | ||
shell: bash | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | ||
- uses: actions/cache@v3 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ env.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Create Neon Branch | ||
id: create-branch | ||
uses: neondatabase/create-branch-action@v4 | ||
with: | ||
project_id: ${{ env.NEON_PROJECT_ID }} | ||
parent: br-quiet-king-a5h32cqs | ||
branch_name: preview/pr-${{ github.event.number }}-${{ steps.branch-name.outputs.current_branch }} | ||
username: ${{ env.NEON_DATABASE_USERNAME }} | ||
api_key: ${{ env.NEON_API_KEY }} | ||
|
||
- name: Install Vercel CLI | ||
run: pnpm i -g vercel@latest | ||
|
||
- name: Pull Vercel Environment Information | ||
run: | | ||
vercel env rm DATABASE_URL preview ${{ steps.branch-name.outputs.current_branch }} --yes --token=${{ secrets.VERCEL_TOKEN }} | ||
vercel env rm DIRECT_DATABASE_URL preview ${{ steps.branch-name.outputs.current_branch }} --yes --token=${{ secrets.VERCEL_TOKEN }} | ||
echo "${{ steps.create-branch.outputs.db_url_with_pooler }}?sslmode=require" | vercel env add DATABASE_URL preview ${{ steps.branch-name.outputs.current_branch }} --token=${{ secrets.VERCEL_TOKEN }} | ||
echo "${{ steps.create-branch.outputs.db_url }}?sslmode=require" | vercel env add DIRECT_DATABASE_URL preview ${{ steps.branch-name.outputs.current_branch }} --token=${{ secrets.VERCEL_TOKEN }} | ||
vercel env pull --yes --environment=preview --git-branch=${{ steps.branch-name.outputs.current_branch }} --token=${{ env.VERCEL_TOKEN }} .env | ||
- name: Run Migrations | ||
run: pnpm run db:migrate | ||
|
||
- name: Run seed | ||
run: pnpm run db:seed | ||
|
||
- name: Build Project Artifacts | ||
run: | | ||
vercel pull --yes --environment=preview --git-branch=${{ steps.branch-name.outputs.current_branch }} --token=${{ env.VERCEL_TOKEN }} | ||
vercel build --token=${{ secrets.VERCEL_TOKEN }} | ||
- name: Deploy Preview to Vercel | ||
id: deploy | ||
run: echo preview_url=$(vercel deploy --prebuilt --token=${{ env.VERCEL_TOKEN }}) >> $GITHUB_OUTPUT | ||
|
||
- name: Comment on Pull Request | ||
uses: thollander/actions-comment-pull-request@v2 | ||
with: | ||
message: | | ||
Vercel Preview URL :rocket: : ${{ steps.deploy.outputs.preview_url }} | ||
Neon branch :elephant: : https://console.neon.tech/app/projects/${{ env.NEON_PROJECT_ID }}/branches/${{ steps.create-branch.outputs.branch_id }} |
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
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