-
Notifications
You must be signed in to change notification settings - Fork 5
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
Updating the deploy-preview.yml #12
Changes from all commits
eaef369
e1544e8
b852866
f971d8e
55ca283
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,11 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- name: Delete Fly app | ||
id: deploy | ||
uses: superfly/[email protected] | ||
|
||
- name: Delete Neon Branch | ||
uses: neondatabase/[email protected] | ||
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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,46 +19,39 @@ jobs: | |
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
- name: Use Node.js 18 | ||
uses: actions/setup-node@v4 | ||
- uses: actions/setup-node@v4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to code comments, I only like them when they are stating a reason that's not obvious. Otherwise they're superfluous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense |
||
with: | ||
node-version: 18 | ||
cache: "pnpm" | ||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Get branch name | ||
- run: pnpm install | ||
|
||
- name: Get git 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 | ||
api_key: ${{ secrets.NEON_API_KEY }} # Generate a an API key in your Neon account settings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this away from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense |
||
|
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels cleaner to me compared to creating the |
||
|
||
pnpm run db:migrate | ||
- run: pnpm run db:migrate | ||
|
||
- name: Deploy | ||
id: deploy | ||
- id: deploy | ||
uses: superfly/[email protected] | ||
with: | ||
secrets: DATABASE_URL=${{ steps.create-branch.outputs.db_url }}?sslmode=require | ||
secrets: DATABASE_URL=$DATABASE_URL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be picking up the env variable created with the |
||
|
||
- name: Comment on Pull Request | ||
uses: thollander/actions-comment-pull-request@v2 | ||
with: | ||
# 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 }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pulls from the env variable at the top of the file instead of the secret directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will require you moving the
NEON_PROJECT_ID
from secrets over to vars but it's not a protected secret so I think that's fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move
NEON_PROJECT_ID
to vars it no longer needs to be listed up here. However I think it's good to have here so we can explain where it came from.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I'm a fan of listing variables at the top of the workflow