-
Notifications
You must be signed in to change notification settings - Fork 0
Enhancement: Feature branches now creates a deployment only on PRs. #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,42 +1,37 @@ | ||
| name: Cleanup Database Branch | ||
| on: | ||
| delete: | ||
| branches-ignore: | ||
| - main | ||
| - dev | ||
| pull_request: | ||
| types: | ||
| - closed | ||
| workflow_dispatch: | ||
| inputs: | ||
| pr_number: | ||
| description: "Pull Request Number" | ||
| required: false | ||
| type: number | ||
|
|
||
| jobs: | ||
| cleanup_database: | ||
| if: ${{ github.event.ref_type == 'branch' }} | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Checkout the main branch to retrieve the scripts | ||
| ref: main | ||
|
|
||
| - name: Install Turso CLI | ||
| run: | | ||
| curl -sSfL https://get.tur.so/install.sh | bash | ||
| echo "$HOME/.turso" >> $GITHUB_PATH | ||
|
|
||
| - name: Generate Safe DB Name | ||
| - name: Get DB Name | ||
| run: | | ||
| # Make the script executable, might not be necessary | ||
| chmod +x .github/scripts/generate_db_name.sh | ||
|
|
||
| # Get the deleted branch name | ||
| RAW_REF="${{ github.event.ref }}" | ||
| CLEAN_REF="${RAW_REF#refs/heads/}" | ||
|
|
||
| # Generate the safe branch name and store it in an environment variable | ||
| BRANCH_NAME=$(.github/scripts/generate_db_name.sh "$CLEAN_REF") | ||
| echo "SAFE_BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | ||
| PR_NUM="${{ github.event.inputs.pr_number || github.event.pull_request.number }}" | ||
| if [ -z "$PR_NUM" ]; then | ||
| echo "No PR number provided" | ||
| exit 1 | ||
| fi | ||
| DB_NAME="pr-$PR_NUM" | ||
| echo "DB_NAME=$DB_NAME" >> $GITHUB_ENV | ||
|
|
||
| - name: Destroy Turso Database | ||
| env: | ||
| TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }} | ||
| DB_NAME: ${{ env.DB_NAME }} | ||
| run: | | ||
| turso db destroy ${{env.SAFE_BRANCH_NAME}} --yes || echo "Database already gone" | ||
| turso db destroy "$DB_NAME" --yes || echo "Database already gone or never existed" |
This file contains hidden or 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,40 @@ | ||
| name: Make Development Deployment | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - dev | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: deployment-dev | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: "npm" | ||
|
|
||
| - run: npm ci | ||
|
|
||
| - name: Push schema changes to database | ||
| env: | ||
| TURSO_DATABASE_URL: ${{ secrets.DEV_DB_URL }} | ||
| TURSO_AUTH_TOKEN: ${{ secrets.DEV_DB_TOKEN }} | ||
| run: | | ||
| npx drizzle-kit push | ||
|
|
||
| - name: Make Development Deployment | ||
| env: | ||
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | ||
| run: | | ||
| npx vercel deploy --target preview --yes --token ${{ secrets.VERCEL_TOKEN }} | ||
This file contains hidden or 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,136 @@ | ||
| name: Make Pull Request Preview Deployment | ||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| workflow_dispatch: | ||
| inputs: | ||
| pr_number: | ||
| description: "Pull Request Number" | ||
| required: false | ||
| type: number | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| deploy: | ||
| environment: Preview | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: "npm" | ||
|
|
||
| - run: npm ci | ||
|
|
||
| - name: Install Turso CLI | ||
| run: | | ||
| curl -sSfL https://get.tur.so/install.sh | bash | ||
| echo "$HOME/.turso" >> $GITHUB_PATH | ||
|
|
||
| - name: Generate DB Name | ||
| run: | | ||
| PR_NUM="${{ github.event.inputs.pr_number || github.event.pull_request.number }}" | ||
| if [ -z "$PR_NUM" ]; then | ||
| echo "Error: No PR number found. If running manually, please provide the PR number input." | ||
| exit 1 | ||
| fi | ||
| echo "PR_NUM=$PR_NUM" >> $GITHUB_ENV | ||
| echo "SAFE_BRANCH_NAME=pr-${PR_NUM}" >> $GITHUB_ENV | ||
|
|
||
| - name: Provision Turso Database | ||
| env: | ||
| TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }} | ||
| run: | | ||
| # Create a branch from the dev database with the generated safe name | ||
| turso db create ${{ env.SAFE_BRANCH_NAME }} --from-db dev || true | ||
|
|
||
| - name: Get Database Credentials | ||
| env: | ||
| TURSO_API_TOKEN: ${{ secrets.TURSO_API_TOKEN }} | ||
| run: | | ||
| DB_URL=$(turso db show ${{ env.SAFE_BRANCH_NAME }} --url) | ||
| DB_TOKEN=$(turso db tokens create ${{ env.SAFE_BRANCH_NAME }}) | ||
|
|
||
| # Mask database credentials | ||
| echo "::add-mask::$DB_URL" | ||
| echo "::add-mask::$DB_TOKEN" | ||
|
|
||
| # Add the database credentials to the environment variables | ||
| echo "DB_URL=$DB_URL" >> $GITHUB_ENV | ||
| echo "DB_TOKEN=$DB_TOKEN" >> $GITHUB_ENV | ||
|
|
||
| - name: Sync schema to database | ||
| env: | ||
| TURSO_DATABASE_URL: ${{ env.DB_URL }} | ||
| TURSO_AUTH_TOKEN: ${{ env.DB_TOKEN }} | ||
| run: | | ||
| # Push changes to the created database | ||
| npx drizzle-kit push | ||
|
|
||
| - name: Make Preview Deployment | ||
| id: vercel-deployment | ||
| env: | ||
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | ||
| run: | | ||
| # Make a preview deployment with the created database | ||
| DEPLOYMENT_URL=$(npx vercel deploy --target preview --token ${{ secrets.VERCEL_TOKEN }} \ | ||
| --build-env TURSO_DATABASE_URL=${{ env.DB_URL }} \ | ||
| --build-env TURSO_AUTH_TOKEN=${{ env.DB_TOKEN }} \ | ||
| --env TURSO_DATABASE_URL=${{ env.DB_URL }} \ | ||
| --env TURSO_AUTH_TOKEN=${{ env.DB_TOKEN }} \ | ||
| --yes --logs) | ||
OverDsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| echo "DEPLOYMENT_URL=$DEPLOYMENT_URL" >> $GITHUB_ENV | ||
|
|
||
| - name: Comment on PR | ||
| if: always() | ||
| uses: actions/github-script@v8 | ||
| env: | ||
| DEPLOYMENT_URL: ${{ env.DEPLOYMENT_URL }} | ||
| DEPLOY_STATUS: ${{ steps.vercel-deployment.outcome }} | ||
| RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
| PR_NUM: ${{ env.PR_NUM }} | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const {DEPLOYMENT_URL, DEPLOY_STATUS, RUN_URL} = process.env; | ||
| const status = DEPLOY_STATUS === "success" ? "✅ Ready" : "❌ Failed to deploy"; | ||
|
|
||
| const body = `### 🚀 Preview Deployment: | ||
| - **Vercel Deployment:** ${DEPLOYMENT_URL ? `[View Deployment](${DEPLOYMENT_URL})` : "N/A"} | ||
| - **Status:** ${status} | ||
| - **Workflow Logs:** [View Run](${RUN_URL})`; | ||
OverDsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: Number(PR_NUM), | ||
| }); | ||
|
|
||
| const existingComment = comments.find(comment => comment.body.includes('### 🚀 Preview Deployment')); | ||
| const payload = { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: body | ||
| }; | ||
|
|
||
| if (existingComment) { | ||
| await github.rest.issues.updateComment({...payload, comment_id: existingComment.id}) | ||
| } else { | ||
| await github.rest.issues.createComment({...payload, issue_number: Number(PR_NUM)}) | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.