diff --git a/.github/workflows/railway-preview.yml b/.github/workflows/railway-preview.yml index e39144b..f734c91 100644 --- a/.github/workflows/railway-preview.yml +++ b/.github/workflows/railway-preview.yml @@ -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: @@ -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" @@ -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: | @@ -66,7 +74,7 @@ jobs: ${marker} 🚀 **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 }}) --- @@ -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' \ No newline at end of file