From eaef3695f6ba13a463d0ffc7291916160589d50b Mon Sep 17 00:00:00 2001 From: Bryan Clark Date: Tue, 7 May 2024 08:44:13 -0700 Subject: [PATCH 1/5] Updating the deploy-preview.yml Moving to use $GITHUB_ENV which should work for the migrate and deploy steps Dropping some of the top level env variables. Moved NEON_PROJECT_ID from secret to var --- .github/workflows/deploy-preview.yml | 38 +++++++++++----------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index c8ab9e7..c78675e 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -2,11 +2,9 @@ name: Preview Deployment on: [pull_request] env: - NEON_DATABASE_USERNAME: ${{ secrets.NEON_DATABASE_USERNAME }} # change this to your database username - GH_TOKEN: ${{ secrets.GH_TOKEN }} # Required for commenting on pull requests for private repos - NEON_API_KEY: ${{ secrets.NEON_API_KEY }} # You can generate a an API key in your account settings - NEON_PROJECT_ID: ${{ secrets.NEON_PROJECT_ID }} # You can find this in your project settings + NEON_PROJECT_ID: ${{ var.NEON_PROJECT_ID }} # You can find this in your Neon project settings FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} # You can generate a Fly API token in your account settings + GH_TOKEN: ${{ secrets.GH_TOKEN }} # Required for commenting on pull requests for private repos jobs: deploy-preview: @@ -21,41 +19,35 @@ jobs: - uses: pnpm/action-setup@v2 with: version: 8 - - name: Use Node.js 18 - uses: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: node-version: 18 cache: "pnpm" - - name: Install dependencies - run: pnpm install - - name: Get branch name + - run: pnpm install + + - name: Get cleaned up branch name id: branch-name uses: tj-actions/branch-names@v8 - - name: Create Neon Branch - id: create-branch + - id: create-branch uses: neondatabase/create-branch-action@v4 with: project_id: ${{ env.NEON_PROJECT_ID }} # parent: dev # optional (defaults to your primary branch) 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: Run Migrations - run: | - touch .env + username: ${{ secrets.NEON_DATABASE_USERNAME }} # change to your Neon database username / role + api_key: ${{ secrets.NEON_API_KEY }} # Generate a an API key in your Neon account settings - echo DATABASE_URL=${{ steps.create-branch.outputs.db_url_with_pooler }}?sslmode=require >> .env + - run: | + echo "DATABASE_URL=${{ steps.create-branch.outputs.db_url_with_pooler }}?sslmode=require" >> "$GITHUB_ENV" - pnpm run db:migrate + - run: pnpm run db:migrate - - name: Deploy - id: deploy + - id: deploy uses: superfly/fly-pr-review-apps@1.2.0 with: - secrets: DATABASE_URL=${{ steps.create-branch.outputs.db_url }}?sslmode=require + secrets: DATABASE_URL=$DATABASE_URL - name: Comment on Pull Request uses: thollander/actions-comment-pull-request@v2 @@ -63,4 +55,4 @@ jobs: # GITHUB_TOKEN: ${{ env.GH_TOKEN }} # Required for commenting on pull requests for private repos message: | Fly Preview URL :balloon: : ${{ steps.deploy.outputs.url }} - Neon branch :elephant: : https://console.neon.tech/app/projects/${{ secrets.NEON_PROJECT_ID }}/branches/${{ steps.create-branch.outputs.branch_id }} + Neon branch :elephant: : https://console.neon.tech/app/projects/${{ env.NEON_PROJECT_ID }}/branches/${{ steps.create-branch.outputs.branch_id }} From e1544e83cdd856e27d5ff8e60f133ed268579a79 Mon Sep 17 00:00:00 2001 From: Mahmoud Abdelwahab Date: Tue, 7 May 2024 19:41:42 +0300 Subject: [PATCH 2/5] Add name for the get git branch name step Co-authored-by: Bryan Clark --- .github/workflows/deploy-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index c78675e..db71022 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -26,7 +26,7 @@ jobs: - run: pnpm install - - name: Get cleaned up branch name + - name: Get git branch name id: branch-name uses: tj-actions/branch-names@v8 From b852866312bc1f9df8d4b4a9d53eb5bd6b2c684c Mon Sep 17 00:00:00 2001 From: Bryan Clark Date: Tue, 7 May 2024 13:41:51 -0700 Subject: [PATCH 3/5] Update cleanup-preview.yml Use the var.NEON_PROJECT_ID to match --- .github/workflows/cleanup-preview.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cleanup-preview.yml b/.github/workflows/cleanup-preview.yml index 6f482b1..e5bba75 100644 --- a/.github/workflows/cleanup-preview.yml +++ b/.github/workflows/cleanup-preview.yml @@ -11,12 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Delete Fly app - id: deploy uses: superfly/fly-pr-review-apps@1.2.0 - name: Delete Neon Branch uses: neondatabase/delete-branch-action@v3.1.3 with: - project_id: ${{ secrets.NEON_PROJECT_ID }} + project_id: ${{ var.NEON_PROJECT_ID }} branch: preview/pr-${{ github.event.number }}-${{ github.event.pull_request.head.ref }} api_key: ${{ secrets.NEON_API_KEY }} From f971d8e12792038d17ad2250fa11d65c4d49b196 Mon Sep 17 00:00:00 2001 From: Bryan Clark Date: Tue, 7 May 2024 13:47:39 -0700 Subject: [PATCH 4/5] Update deploy-production.yml Truncate step names Move env variables for this one down to the steps that require them. We've explained in other files where they are needed. --- .github/workflows/deploy-production.yml | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index fc6fa79..868ebe8 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -5,34 +5,27 @@ on: branches: - 'main' -env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - DATABASE_URL: ${{ secrets.DATABASE_URL }} - jobs: deploy-production: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 with: version: 8 - - - name: Use Node.js 18 - uses: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: node-version: 18 cache: 'pnpm' - - name: Install dependencies - run: pnpm install - - - - name: Run Migrations - run: pnpm run db:migrate - + - run: pnpm install + - run: pnpm run db:migrate + env: # production database URL from secrets + DATABASE_URL: ${{ secrets.DATABASE_URL }} - uses: superfly/flyctl-actions/setup-flyctl@master - - run: flyctl deploy --remote-only \ No newline at end of file + - run: flyctl deploy --remote-only + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} From 55ca2838835cd96a1656c298e4c5f62e7fc524c5 Mon Sep 17 00:00:00 2001 From: Mahmoud Abdelwahab Date: Wed, 8 May 2024 15:05:09 +0300 Subject: [PATCH 5/5] Remove database username Co-authored-by: Bryan Clark --- .github/workflows/deploy-preview.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index db71022..d6d6f11 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -36,7 +36,6 @@ jobs: project_id: ${{ env.NEON_PROJECT_ID }} # parent: dev # optional (defaults to your primary branch) branch_name: preview/pr-${{ github.event.number }}-${{ steps.branch-name.outputs.current_branch }} - username: ${{ secrets.NEON_DATABASE_USERNAME }} # change to your Neon database username / role api_key: ${{ secrets.NEON_API_KEY }} # Generate a an API key in your Neon account settings - run: |