Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions .github/workflows/railway-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:
issues: write

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
Expand All @@ -22,13 +22,21 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Sanitize branch name
id: sanitize
run: |
BRANCH_NAME="${{ github.head_ref }}"
# Convert to lowercase, replace invalid chars with hyphens, remove consecutive hyphens, trim hyphens
SANITIZED=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/-\+/-/g' | sed 's/^-\|-$//g')
echo "sanitized=$SANITIZED" >> $GITHUB_OUTPUT

- name: Deploy to Railway
uses: ayungavis/railway-preview-deploy@v1.0.2
with:
railway_api_token: ${{ secrets.RAILWAY_API_TOKEN }}
project_id: ${{ secrets.RAILWAY_PROJECT_ID }}
environment_name: 'production'
preview_environment_name: 'pr-${{ github.event.pull_request.number }}'
preview_environment_name: 'pr-${{ steps.sanitize.outputs.sanitized }}'
environment_variables: |
{
"DATABASE_URL": "postgres://username:password@hostname/db"
Expand All @@ -40,7 +48,7 @@ jobs:
echo "Preview deployed at ${{ steps.deploy.outputs.service_domain }}"

- name: Post or update deployment comment
if: ${{ steps.test-action.outputs.service_domain != '' }}
if: ${{ steps.deploy.outputs.service_domain != '' }}
uses: actions/github-script@v7
with:
script: |
Expand All @@ -66,7 +74,7 @@ jobs:
${marker} <!-- This marker helps identify the comment for future updates -->
🚀 **Deployment success!**

- \`web\` deployed at [${{ steps.test-action.outputs.service_domain }}](https://${{ steps.test-action.outputs.service_domain }})
- \`web\` deployed at [${{ steps.deploy.outputs.service_domain }}](https://${{ steps.deploy.outputs.service_domain }})

---

Expand Down Expand Up @@ -104,12 +112,20 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Sanitize branch name
id: sanitize
run: |
BRANCH_NAME="${{ github.head_ref }}"
# Convert to lowercase, replace invalid chars with hyphens, remove consecutive hyphens, trim hyphens
SANITIZED=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/-\+/-/g' | sed 's/^-\|-$//g')
echo "sanitized=$SANITIZED" >> $GITHUB_OUTPUT

- name: Cleanup Railway Environment
uses: ayungavis/railway-preview-deploy@v1.0.2
with:
railway_api_token: ${{ secrets.RAILWAY_API_TOKEN }}
project_id: ${{ secrets.RAILWAY_PROJECT_ID }}
environment_name: production
preview_environment_name: 'pr-${{ github.event.pull_request.number }}'
preview_environment_name: 'pr-${{ steps.sanitize.outputs.sanitized }}'
branch_name: ${{ github.head_ref }}
cleanup: 'true'
Loading