From d3218a10ddab6617ed4627e85c6a6a15c7e8b9be Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Fri, 26 Jan 2024 21:13:33 +0000 Subject: [PATCH 01/11] feat: first iteration of pr neon db branching --- .github/workflows/ci.yml | 35 ++++++++++++++++++++++++++++++++++- cspell.config.yaml | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb5bf89d..fb345925 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,11 +7,42 @@ on: types: [opened, synchronize] jobs: + create-neon-branch: + permissions: write-all + runs-on: ubuntu-latest + outputs: + database_url: ${{ steps.get-database-url.outputs.database_url }} + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v7 + + - name: Install neon cli + run: npm install -g neonctl + + - name: Create a neon branch + id: create-branch + run: neonctl branches create --project-id ${{ secrets.NEON_PROJECT_ID }} --name ${{ steps.branch-name.outputs.current_branch }} --api-key ${{ secrets.NEON_API_KEY }} --compute --type read_write + + - name: get Neon branch ID + id: get-neon-branch-id + run: | + echo branch_id=$(neonctl branches get ${{ steps.branch-name.outputs.current_branch }} --project-id ${{ secrets.NEON_PROJECT_ID }} --api-key ${{ secrets.NEON_API_KEY }} --output json | jq -r '.id') >> $GITHUB_OUTPUT + + - name: Output the new database url + id: get-database-url + run: | + echo database_url=$(neonctl cs ${{ steps.branch-name.outputs.current_branch }} --project-id ${{ secrets.NEON_PROJECT_ID }} --role-name ${{ secrets.PG_USERNAME }} --database-name ${{ secrets.PG_DATABASE }} --api-key ${{ secrets.NEON_API_KEY }}) >> $GITHUB_OUTPUT + build: name: CI runs-on: ubuntu-latest env: - DATABASE_URL: ${{ secrets.DATABASE_URL }} TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ vars.TURBO_TEAM }} @@ -63,4 +94,6 @@ jobs: run: pnpm turbo typecheck - name: Build + env: + DATABASE_URL: ${{ needs.create-neon-branch.outputs.database_url }} run: pnpm turbo build diff --git a/cspell.config.yaml b/cspell.config.yaml index ee2f46cd..c4c65346 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -8,6 +8,7 @@ ignorePaths: - dist words: - astro + - neonctl - clsx - commitlint - esbenp From f9ffc2eaed3169a58b1ec4135cfabfc3c21deab1 Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Fri, 26 Jan 2024 21:25:58 +0000 Subject: [PATCH 02/11] feat: move to neon's workflow --- .github/workflows/ci.yml | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb345925..449b0011 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,36 +8,23 @@ on: jobs: create-neon-branch: - permissions: write-all + name: ๐Ÿš€ Create Neon Branch runs-on: ubuntu-latest outputs: - database_url: ${{ steps.get-database-url.outputs.database_url }} + database_url: ${{ steps.create-branch.outputs.db_url }} steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - name: Get branch name id: branch-name uses: tj-actions/branch-names@v7 - - name: Install neon cli - run: npm install -g neonctl - - - name: Create a neon branch + - name: Create neon branch + uses: neondatabase/create-branch-action@v4 + with: + project_id: ${{ secrets.NEON_PROJECT_ID }} + branch_name: ${{ steps.branch-name.outputs.current_branch }} + username: ${ secrets.PG_USERNAME }} + api_key: ${{ secrets.NEON_API_KEY }} id: create-branch - run: neonctl branches create --project-id ${{ secrets.NEON_PROJECT_ID }} --name ${{ steps.branch-name.outputs.current_branch }} --api-key ${{ secrets.NEON_API_KEY }} --compute --type read_write - - - name: get Neon branch ID - id: get-neon-branch-id - run: | - echo branch_id=$(neonctl branches get ${{ steps.branch-name.outputs.current_branch }} --project-id ${{ secrets.NEON_PROJECT_ID }} --api-key ${{ secrets.NEON_API_KEY }} --output json | jq -r '.id') >> $GITHUB_OUTPUT - - - name: Output the new database url - id: get-database-url - run: | - echo database_url=$(neonctl cs ${{ steps.branch-name.outputs.current_branch }} --project-id ${{ secrets.NEON_PROJECT_ID }} --role-name ${{ secrets.PG_USERNAME }} --database-name ${{ secrets.PG_DATABASE }} --api-key ${{ secrets.NEON_API_KEY }}) >> $GITHUB_OUTPUT build: name: CI From 01762d76f1ec08fe71ce5645fc14931f445f7115 Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Fri, 26 Jan 2024 21:54:07 +0000 Subject: [PATCH 03/11] feat: hmm --- .github/workflows/ci.yml | 78 +++++++++++++++++++++++++------------- .github/workflows/neon.yml | 34 +++++++++++++++++ 2 files changed, 86 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/neon.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 449b0011..a360b40a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,32 +6,14 @@ on: pull_request: types: [opened, synchronize] -jobs: - create-neon-branch: - name: ๐Ÿš€ Create Neon Branch - runs-on: ubuntu-latest - outputs: - database_url: ${{ steps.create-branch.outputs.db_url }} - steps: - - name: Get branch name - id: branch-name - uses: tj-actions/branch-names@v7 +env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} - - name: Create neon branch - uses: neondatabase/create-branch-action@v4 - with: - project_id: ${{ secrets.NEON_PROJECT_ID }} - branch_name: ${{ steps.branch-name.outputs.current_branch }} - username: ${ secrets.PG_USERNAME }} - api_key: ${{ secrets.NEON_API_KEY }} - id: create-branch - - build: - name: CI +jobs: + code-quality: + name: ๐Ÿ–จ๏ธ Code Quality runs-on: ubuntu-latest - env: - TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} - TURBO_TEAM: ${{ vars.TURBO_TEAM }} steps: - name: Check out code @@ -80,7 +62,51 @@ jobs: - name: Typecheck run: pnpm turbo typecheck + build: + name: ๐Ÿ—๏ธ Build + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + 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: Get branch name + id: branch-name + uses: tj-actions/branch-names@v7 + + - name: Download .env file + uses: actions/download-artifact@v2 + with: + name: ${{ steps.branch-name.outputs.current_branch }}-env + path: apps/web/.env + + - name: Install dependencies + run: pnpm install + - name: Build - env: - DATABASE_URL: ${{ needs.create-neon-branch.outputs.database_url }} run: pnpm turbo build diff --git a/.github/workflows/neon.yml b/.github/workflows/neon.yml new file mode 100644 index 00000000..1b6cfb86 --- /dev/null +++ b/.github/workflows/neon.yml @@ -0,0 +1,34 @@ +name: ๐Ÿ’ฟ Neon PR Branching + +on: + pull_request: + types: [opened] + workflow_dispatch: + +jobs: + create-neon-branch: + name: ๐Ÿš€ Create Neon Database Branch + runs-on: ubuntu-latest + steps: + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v7 + + - name: Create neon branch + uses: neondatabase/create-branch-action@v4 + with: + project_id: ${{ secrets.NEON_PROJECT_ID }} + branch_name: ${{ steps.branch-name.outputs.current_branch }} + username: ${ secrets.PG_USERNAME }} + api_key: ${{ secrets.NEON_API_KEY }} + id: create-branch + + - name: Create .env file + run: | + echo "DATABASE_URL=${{ steps.create-branch.outputs.db_url }}" >> .env + + - name: Upload .env file as an artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ steps.branch-name.outputs.current_branch }}-env + path: apps/web/.env From 7eac1edc502cd4955d3a583d9ef76d420ddc69b9 Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Fri, 26 Jan 2024 21:59:01 +0000 Subject: [PATCH 04/11] feat: go back --- .github/workflows/ci.yml | 78 +++++++++++++------------------------- .github/workflows/neon.yml | 34 ----------------- 2 files changed, 26 insertions(+), 86 deletions(-) delete mode 100644 .github/workflows/neon.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a360b40a..50e828a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,14 +6,32 @@ on: pull_request: types: [opened, synchronize] -env: - TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} - TURBO_TEAM: ${{ secrets.TURBO_TEAM }} - jobs: - code-quality: - name: ๐Ÿ–จ๏ธ Code Quality + create-neon-branch: + name: ๐Ÿš€ Create Neon Branch + runs-on: ubuntu-latest + outputs: + database_url: ${{ steps.create-branch.outputs.db_url }} + steps: + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v7 + + - name: Create neon branch + uses: neondatabase/create-branch-action@v4 + with: + project_id: ${{ secrets.NEON_PROJECT_ID }} + branch_name: ${{ steps.branch-name.outputs.current_branch }} + username: ${ secrets.PG_USERNAME }} + api_key: ${{ secrets.NEON_API_KEY }} + id: create-branch + + main: + name: ๐Ÿงพ Main CI Checks runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} steps: - name: Check out code @@ -62,51 +80,7 @@ jobs: - name: Typecheck run: pnpm turbo typecheck - build: - name: ๐Ÿ—๏ธ Build - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: 20 - - - uses: pnpm/action-setup@v2 - name: Install pnpm - with: - 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: Get branch name - id: branch-name - uses: tj-actions/branch-names@v7 - - - name: Download .env file - uses: actions/download-artifact@v2 - with: - name: ${{ steps.branch-name.outputs.current_branch }}-env - path: apps/web/.env - - - name: Install dependencies - run: pnpm install - - name: Build + env: + DATABASE_URL: ${{ needs.create-neon-branch.outputs.database_url }} run: pnpm turbo build diff --git a/.github/workflows/neon.yml b/.github/workflows/neon.yml deleted file mode 100644 index 1b6cfb86..00000000 --- a/.github/workflows/neon.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: ๐Ÿ’ฟ Neon PR Branching - -on: - pull_request: - types: [opened] - workflow_dispatch: - -jobs: - create-neon-branch: - name: ๐Ÿš€ Create Neon Database Branch - runs-on: ubuntu-latest - steps: - - name: Get branch name - id: branch-name - uses: tj-actions/branch-names@v7 - - - name: Create neon branch - uses: neondatabase/create-branch-action@v4 - with: - project_id: ${{ secrets.NEON_PROJECT_ID }} - branch_name: ${{ steps.branch-name.outputs.current_branch }} - username: ${ secrets.PG_USERNAME }} - api_key: ${{ secrets.NEON_API_KEY }} - id: create-branch - - - name: Create .env file - run: | - echo "DATABASE_URL=${{ steps.create-branch.outputs.db_url }}" >> .env - - - name: Upload .env file as an artifact - uses: actions/upload-artifact@v2 - with: - name: ${{ steps.branch-name.outputs.current_branch }}-env - path: apps/web/.env From 7b057dfa608ac4b0fd5831e2c78bb58724355eaf Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Fri, 26 Jan 2024 22:05:54 +0000 Subject: [PATCH 05/11] feat: up create-branch-action to v4.4.0 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50e828a3..91555679 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: uses: tj-actions/branch-names@v7 - name: Create neon branch - uses: neondatabase/create-branch-action@v4 + uses: neondatabase/create-branch-action@v4.4.0 with: project_id: ${{ secrets.NEON_PROJECT_ID }} branch_name: ${{ steps.branch-name.outputs.current_branch }} From 2b0ab4b3ca130255cb9cac479813826bb3fca730 Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Fri, 26 Jan 2024 22:15:27 +0000 Subject: [PATCH 06/11] feat: modify neon workflow --- .github/workflows/ci.yml | 2 +- .github/workflows/neon-branch.yml | 123 ++++++++++++++++++++++++++++++ cspell.config.yaml | 1 + 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/neon-branch.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91555679..391d7e36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: uses: tj-actions/branch-names@v7 - name: Create neon branch - uses: neondatabase/create-branch-action@v4.4.0 + uses: ixahmedxi/orbitkit/.github/workflows/neon-branch.yml@neon with: project_id: ${{ secrets.NEON_PROJECT_ID }} branch_name: ${{ steps.branch-name.outputs.current_branch }} diff --git a/.github/workflows/neon-branch.yml b/.github/workflows/neon-branch.yml new file mode 100644 index 00000000..76fb7854 --- /dev/null +++ b/.github/workflows/neon-branch.yml @@ -0,0 +1,123 @@ +name: 'Neon Database Create Branch Action' +author: 'Neon Database' +description: 'Creates a new Neon Postgres branch based a parent branch. If the branch already exists it will return the branch details' +branding: + icon: 'box' + color: 'green' + +inputs: + project_id: + required: true + description: 'The project id' + branch_name: + required: false + description: 'The branch name' + api_key: + description: 'The Neon API key' + required: true + username: + description: 'The db role name' + required: true + database: + description: 'The database name' + default: neondb + prisma: + description: 'Use prisma or not' + default: 'false' + parent: + description: 'The parent branch name or id or LSN or timestamp. By default the primary branch is used' + suspend_timeout: + description: > + Duration of inactivity in seconds after which the compute endpoint is + For more information, see [Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration). + default: '0' + +outputs: + db_url: + description: 'New branch DATABASE_URL' + value: ${{ steps.create-branch.outputs.db_url }} + db_url_with_pooler: + description: 'New branch DATABASE_URL with pooling enabled' + value: ${{ steps.create-branch.outputs.db_url_with_pooler }} + host: + description: 'New branch host' + value: ${{ steps.create-branch.outputs.host }} + host_with_pooler: + description: 'New branch host with pooling enabled' + value: ${{ steps.create-branch.outputs.host_with_pooler }} + branch_id: + description: 'New branch id' + value: ${{ steps.create-branch.outputs.branch_id }} + password: + description: 'Password for connecting to the new branch database with the input username' + value: ${{ steps.create-branch.outputs.password }} + +runs: + using: 'composite' + steps: + - uses: actions/setup-node@v4 + - run: npm i -g neonctl + shell: bash + - name: Create new Neon branch + env: + NEON_API_KEY: ${{ inputs.api_key }} + id: create-branch + shell: bash + run: | + neonctl branches create \ + --project-id ${{ inputs.project_id }} \ + --name ${{ inputs.branch_name }} \ + --suspend-timeout ${{ inputs.suspend_timeout }} \ + $(if [[ -n "${{ inputs.parent }}" ]]; then echo "--parent ${{ inputs.parent }}"; fi) \ + --output json \ + 2> branch_err > branch_out || true + + echo "branch create out:" + cat branch_out + echo "branch create err:" + cat branch_err + + if [[ $(cat branch_err) == *"already exists"* ]]; then + + # Get the branch id by its name. We list all branches and filter by name + branch_id=$(neonctl branches list --project-id ${{ inputs.project_id }} -o json \ + | jq -r '.[] | select(.name == "${{ inputs.branch_name }}") | .id') + + echo "branch exists, branch id: ${branch_id}" + + echo "branch_id=${branch_id}" >> $GITHUB_OUTPUT + NEON_CS=$(neonctl cs ${branch_id} --project-id ${{ inputs.project_id }} --role-name ${{ inputs.username }} --database-name ${{ inputs.database }} --prisma ${{ inputs.prisma }} --extended -o json) + DB_URL=$(echo $NEON_CS | jq -r '.connection_string') + DB_HOST=$(echo $NEON_CS | jq -r '.host') + DB_PASSWORD=$(echo $NEON_CS | jq -r '.password') + NEON_CS_POOLER=$(neonctl cs ${branch_id} --project-id ${{ inputs.project_id }} --role-name ${{ inputs.username }} --database-name ${{ inputs.database }} --pooled --prisma ${{ inputs.prisma }} --extended -o json) + DB_URL_WITH_POOLER=$(echo $NEON_CS_POOLER | jq -r '.connection_string') + DB_HOST_WITH_POOLER=$(echo $NEON_CS_POOLER | jq -r '.host') + exit 0 + elif [[ $(cat branch_err) == *"ERROR:"* ]]; then + echo "ERROR: branch creation failed" + cat branch_err + exit 1 + else + branch_id=$(cat branch_out | jq --raw-output '.branch.id') + if [[ -z "${branch_id}" ]]; then + echo "ERROR: didn't get the branch id" + exit 1 + fi + + echo "branch doesn't exist, branch id: ${branch_id}" + + echo "branch_id=${branch_id}" >> $GITHUB_OUTPUT + NEON_CS=$(neonctl cs ${branch_id} --project-id ${{ inputs.project_id }} --role-name ${{ inputs.username }} --database-name ${{ inputs.database }} --prisma ${{ inputs.prisma }} --extended -o json) + DB_URL=$(echo $NEON_CS | jq -r '.connection_string') + DB_HOST=$(echo $NEON_CS | jq -r '.host') + DB_PASSWORD=$(echo $NEON_CS | jq -r '.password') + NEON_CS_POOLER=$(neonctl cs ${branch_id} --project-id ${{ inputs.project_id }} --role-name ${{ inputs.username }} --database-name ${{ inputs.database }} --pooled --prisma ${{ inputs.prisma }} --extended -o json) + DB_URL_WITH_POOLER=$(echo $NEON_CS_POOLER | jq -r '.connection_string') + DB_HOST_WITH_POOLER=$(echo $NEON_CS_POOLER | jq -r '.host') + fi + echo "db_url=${DB_URL}" >> $GITHUB_OUTPUT + echo "db_url_with_pooler=${DB_URL_WITH_POOLER}" >> $GITHUB_OUTPUT + echo "password=${DB_PASSWORD}" >> $GITHUB_OUTPUT + echo "host=${DB_HOST}" >> $GITHUB_OUTPUT + echo "host_with_pooler=${DB_HOST_WITH_POOLER}" >> $GITHUB_OUTPUT diff --git a/cspell.config.yaml b/cspell.config.yaml index c4c65346..e3ea659f 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -6,6 +6,7 @@ ignorePaths: - .tsbuildinfo - .gitignore - dist + - .github words: - astro - neonctl From da1969fdc9cc9e39e1979dbe569f844fd134879b Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Fri, 26 Jan 2024 22:21:24 +0000 Subject: [PATCH 07/11] feat: okay let's go back --- .github/workflows/ci.yml | 2 +- .github/workflows/neon-branch.yml | 123 ------------------------------ cspell.config.yaml | 1 - 3 files changed, 1 insertion(+), 125 deletions(-) delete mode 100644 .github/workflows/neon-branch.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 391d7e36..91555679 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: uses: tj-actions/branch-names@v7 - name: Create neon branch - uses: ixahmedxi/orbitkit/.github/workflows/neon-branch.yml@neon + uses: neondatabase/create-branch-action@v4.4.0 with: project_id: ${{ secrets.NEON_PROJECT_ID }} branch_name: ${{ steps.branch-name.outputs.current_branch }} diff --git a/.github/workflows/neon-branch.yml b/.github/workflows/neon-branch.yml deleted file mode 100644 index 76fb7854..00000000 --- a/.github/workflows/neon-branch.yml +++ /dev/null @@ -1,123 +0,0 @@ -name: 'Neon Database Create Branch Action' -author: 'Neon Database' -description: 'Creates a new Neon Postgres branch based a parent branch. If the branch already exists it will return the branch details' -branding: - icon: 'box' - color: 'green' - -inputs: - project_id: - required: true - description: 'The project id' - branch_name: - required: false - description: 'The branch name' - api_key: - description: 'The Neon API key' - required: true - username: - description: 'The db role name' - required: true - database: - description: 'The database name' - default: neondb - prisma: - description: 'Use prisma or not' - default: 'false' - parent: - description: 'The parent branch name or id or LSN or timestamp. By default the primary branch is used' - suspend_timeout: - description: > - Duration of inactivity in seconds after which the compute endpoint is - For more information, see [Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration). - default: '0' - -outputs: - db_url: - description: 'New branch DATABASE_URL' - value: ${{ steps.create-branch.outputs.db_url }} - db_url_with_pooler: - description: 'New branch DATABASE_URL with pooling enabled' - value: ${{ steps.create-branch.outputs.db_url_with_pooler }} - host: - description: 'New branch host' - value: ${{ steps.create-branch.outputs.host }} - host_with_pooler: - description: 'New branch host with pooling enabled' - value: ${{ steps.create-branch.outputs.host_with_pooler }} - branch_id: - description: 'New branch id' - value: ${{ steps.create-branch.outputs.branch_id }} - password: - description: 'Password for connecting to the new branch database with the input username' - value: ${{ steps.create-branch.outputs.password }} - -runs: - using: 'composite' - steps: - - uses: actions/setup-node@v4 - - run: npm i -g neonctl - shell: bash - - name: Create new Neon branch - env: - NEON_API_KEY: ${{ inputs.api_key }} - id: create-branch - shell: bash - run: | - neonctl branches create \ - --project-id ${{ inputs.project_id }} \ - --name ${{ inputs.branch_name }} \ - --suspend-timeout ${{ inputs.suspend_timeout }} \ - $(if [[ -n "${{ inputs.parent }}" ]]; then echo "--parent ${{ inputs.parent }}"; fi) \ - --output json \ - 2> branch_err > branch_out || true - - echo "branch create out:" - cat branch_out - echo "branch create err:" - cat branch_err - - if [[ $(cat branch_err) == *"already exists"* ]]; then - - # Get the branch id by its name. We list all branches and filter by name - branch_id=$(neonctl branches list --project-id ${{ inputs.project_id }} -o json \ - | jq -r '.[] | select(.name == "${{ inputs.branch_name }}") | .id') - - echo "branch exists, branch id: ${branch_id}" - - echo "branch_id=${branch_id}" >> $GITHUB_OUTPUT - NEON_CS=$(neonctl cs ${branch_id} --project-id ${{ inputs.project_id }} --role-name ${{ inputs.username }} --database-name ${{ inputs.database }} --prisma ${{ inputs.prisma }} --extended -o json) - DB_URL=$(echo $NEON_CS | jq -r '.connection_string') - DB_HOST=$(echo $NEON_CS | jq -r '.host') - DB_PASSWORD=$(echo $NEON_CS | jq -r '.password') - NEON_CS_POOLER=$(neonctl cs ${branch_id} --project-id ${{ inputs.project_id }} --role-name ${{ inputs.username }} --database-name ${{ inputs.database }} --pooled --prisma ${{ inputs.prisma }} --extended -o json) - DB_URL_WITH_POOLER=$(echo $NEON_CS_POOLER | jq -r '.connection_string') - DB_HOST_WITH_POOLER=$(echo $NEON_CS_POOLER | jq -r '.host') - exit 0 - elif [[ $(cat branch_err) == *"ERROR:"* ]]; then - echo "ERROR: branch creation failed" - cat branch_err - exit 1 - else - branch_id=$(cat branch_out | jq --raw-output '.branch.id') - if [[ -z "${branch_id}" ]]; then - echo "ERROR: didn't get the branch id" - exit 1 - fi - - echo "branch doesn't exist, branch id: ${branch_id}" - - echo "branch_id=${branch_id}" >> $GITHUB_OUTPUT - NEON_CS=$(neonctl cs ${branch_id} --project-id ${{ inputs.project_id }} --role-name ${{ inputs.username }} --database-name ${{ inputs.database }} --prisma ${{ inputs.prisma }} --extended -o json) - DB_URL=$(echo $NEON_CS | jq -r '.connection_string') - DB_HOST=$(echo $NEON_CS | jq -r '.host') - DB_PASSWORD=$(echo $NEON_CS | jq -r '.password') - NEON_CS_POOLER=$(neonctl cs ${branch_id} --project-id ${{ inputs.project_id }} --role-name ${{ inputs.username }} --database-name ${{ inputs.database }} --pooled --prisma ${{ inputs.prisma }} --extended -o json) - DB_URL_WITH_POOLER=$(echo $NEON_CS_POOLER | jq -r '.connection_string') - DB_HOST_WITH_POOLER=$(echo $NEON_CS_POOLER | jq -r '.host') - fi - echo "db_url=${DB_URL}" >> $GITHUB_OUTPUT - echo "db_url_with_pooler=${DB_URL_WITH_POOLER}" >> $GITHUB_OUTPUT - echo "password=${DB_PASSWORD}" >> $GITHUB_OUTPUT - echo "host=${DB_HOST}" >> $GITHUB_OUTPUT - echo "host_with_pooler=${DB_HOST_WITH_POOLER}" >> $GITHUB_OUTPUT diff --git a/cspell.config.yaml b/cspell.config.yaml index e3ea659f..c4c65346 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -6,7 +6,6 @@ ignorePaths: - .tsbuildinfo - .gitignore - dist - - .github words: - astro - neonctl From 2614bbda3ae9172ff38fdef2702fa430679df69d Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Wed, 31 Jan 2024 18:38:21 +0000 Subject: [PATCH 08/11] fix: bad substitution --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91555679..940436f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: with: project_id: ${{ secrets.NEON_PROJECT_ID }} branch_name: ${{ steps.branch-name.outputs.current_branch }} - username: ${ secrets.PG_USERNAME }} + username: ${{ secrets.PG_USERNAME }} api_key: ${{ secrets.NEON_API_KEY }} id: create-branch From b77b4bff2121ffa5f03fb2e33fa786832f837992 Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Wed, 31 Jan 2024 20:38:34 +0000 Subject: [PATCH 09/11] fix: lint --- packages/config/eslint/base.js | 1 + packages/db/drizzle.config.ts | 2 +- packages/db/migrate.ts | 2 +- packages/ui/tsup.config.ts | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/config/eslint/base.js b/packages/config/eslint/base.js index a50fb8bf..3bee881b 100644 --- a/packages/config/eslint/base.js +++ b/packages/config/eslint/base.js @@ -26,6 +26,7 @@ const config = { 'plugin:@typescript-eslint/stylistic-type-checked', ], rules: { + '@typescript-eslint/consistent-type-definitions': 'off', '@typescript-eslint/array-type': [ 'error', { diff --git a/packages/db/drizzle.config.ts b/packages/db/drizzle.config.ts index 490f35fd..401ad40b 100644 --- a/packages/db/drizzle.config.ts +++ b/packages/db/drizzle.config.ts @@ -1,6 +1,6 @@ import type { Config } from 'drizzle-kit'; -import { env } from './src/env.mjs'; +import { env } from './src/env.js'; export default { schema: './src/schema/index.ts', diff --git a/packages/db/migrate.ts b/packages/db/migrate.ts index 90b91801..22dd651e 100644 --- a/packages/db/migrate.ts +++ b/packages/db/migrate.ts @@ -2,7 +2,7 @@ import { drizzle } from 'drizzle-orm/postgres-js'; import { migrate } from 'drizzle-orm/postgres-js/migrator'; import postgres from 'postgres'; -import { env } from './src/env.mjs'; +import { env } from './src/env.js'; const sql = postgres(env.DATABASE_URL, { max: 1 }); const db = drizzle(sql); diff --git a/packages/ui/tsup.config.ts b/packages/ui/tsup.config.ts index 076a8918..12a44668 100644 --- a/packages/ui/tsup.config.ts +++ b/packages/ui/tsup.config.ts @@ -18,12 +18,12 @@ const entries = [ }, ]; -type PackageJson = { +interface PackageJson { exports: Record; main: string; module: string; types: string; -}; +} export default defineConfig((opts) => ({ entry: entries.map((entry) => entry.source), From 9dbfbe2e1cd927f56851f4e9f931b2232c66c6a4 Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Wed, 31 Jan 2024 20:48:35 +0000 Subject: [PATCH 10/11] refactor: rename github env --- packages/auth/src/env.js | 8 ++++---- packages/auth/src/providers/github.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/auth/src/env.js b/packages/auth/src/env.js index 94c87ebd..b264754d 100644 --- a/packages/auth/src/env.js +++ b/packages/auth/src/env.js @@ -6,13 +6,13 @@ export const env = createEnv({ extends: [vercel], server: { NODE_ENV: z.enum(['development', 'test', 'production']).optional(), - GITHUB_CLIENT_ID: z.string(), - GITHUB_CLIENT_SECRET: z.string(), + AUTH_GITHUB_CLIENT_ID: z.string(), + AUTH_GITHUB_CLIENT_SECRET: z.string(), }, runtimeEnv: { NODE_ENV: process.env['NODE_ENV'], - GITHUB_CLIENT_ID: process.env['GITHUB_CLIENT_ID'], - GITHUB_CLIENT_SECRET: process.env['GITHUB_CLIENT_SECRET'], + AUTH_GITHUB_CLIENT_ID: process.env['GITHUB_CLIENT_ID'], + AUTH_GITHUB_CLIENT_SECRET: process.env['GITHUB_CLIENT_SECRET'], }, emptyStringAsUndefined: true, }); diff --git a/packages/auth/src/providers/github.ts b/packages/auth/src/providers/github.ts index bce955f5..3b299e3b 100644 --- a/packages/auth/src/providers/github.ts +++ b/packages/auth/src/providers/github.ts @@ -10,8 +10,8 @@ import { env } from '../env.js'; import { lucia } from '../lucia'; export const github = new GitHub( - env.GITHUB_CLIENT_ID, - env.GITHUB_CLIENT_SECRET, + env.AUTH_GITHUB_CLIENT_ID, + env.AUTH_GITHUB_CLIENT_SECRET, ); export async function createGithubAuthorizationURL(): Promise { From 835d3c4cf7e762ba90c2a1858e70e262198fc97b Mon Sep 17 00:00:00 2001 From: Ahmed Elsakaan Date: Wed, 31 Jan 2024 20:51:02 +0000 Subject: [PATCH 11/11] fix: adds github env to ci --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 940436f4..8a727deb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: env: TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ vars.TURBO_TEAM }} + AUTH_GITHUB_CLIENT_ID: ${{ secrets.AUTH_GITHUB_CLIENT_ID }} + AUTH_GITHUB_CLIENT_SECRET: ${{ secrets.AUTH_GITHUB_CLIENT_SECRET }} steps: - name: Check out code