Last active
February 7, 2024 17:53
-
-
Save Faolain/12ee1f09566dac269030873d8dae921d to your computer and use it in GitHub Desktop.
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
name: Deploy Pull Request to Ephemeral Environment | |
on: | |
pull_request: | |
types: | |
- opened | |
# - synchronize | |
- reopened | |
- closed | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
if: github.event_name != 'pull_request' || github.event.action != 'closed' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} # Check out the source branch of the PR | |
- name: Create a Neon Branch 🚀 | |
uses: neondatabase/create-branch-action@v4 | |
with: | |
project_id: ${{ secrets.NEON_PROJECT_ID }} | |
parent: staging | |
branch_name: pr-${{ github.event.pull_request.number }} | |
api_key: ${{ secrets.NEON_API_KEY }} | |
id: create_branch | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "18" # Or another version if you prefer | |
- name: Create PR environment on Railway | |
id: railway_deploy | |
if: github.event.action == 'opened' || github.event.action == 'reopened' | |
uses: Faolain/railway-pr-deploy@v2.0.4 | |
with: | |
RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_TOKEN }} | |
PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }} | |
SRC_ENVIRONMENT_NAME: staging | |
DEST_ENV_NAME: pr-${{ github.event.pull_request.number }} | |
PROVIDER: python | |
ENV_VARS: '{"DB_URL": "postgresql+asyncpg://${{ secrets.NEON_USERNAME }}:${{ secrets.NEON_DB_PASSWORD }}@${{ steps.create_branch.outputs.host}}/neondb"}' | |
branch_name: ${{ github.head_ref }} | |
cleanup: | |
if: github.event_name == 'pull_request' && github.event.action == 'closed' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete PR environment on Railway | |
uses: Faolain/railway-pr-delete@v1.0.11 | |
with: | |
RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_TOKEN }} | |
PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }} | |
DEST_ENV_NAME: pr-${{ github.event.pull_request.number }} | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "18" # Or another version if you prefer | |
- name: Delete a Neon Branch 🚀 | |
uses: neondatabase/delete-branch-action@v3 | |
with: | |
project_id: ${{ secrets.NEON_PROJECT_ID }} | |
branch: pr-${{ github.event.pull_request.number }} | |
api_key: ${{ secrets.NEON_API_KEY }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment