jannisbecker
PROOP
17 days ago
I'm trying to automatically create a PR environment from Github actions, like this:
env:
# Railway configuration
RAILWAY_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
RAILWAY_BACKEND_SERVICE_ID: ${{ secrets.RAILWAY_BACKEND_SERVICE_ID }}
RAILWAY_WEB_SERVICE_ID: ${{ secrets.RAILWAY_WEB_SERVICE_ID }}
RAILWAY_DUPLICATE_ENV_ID: ${{ secrets.RAILWAY_DUPLICATE_ENV_ID }}
# Neon configuration
NEON_API_KEY: ${{ secrets.NEON_API_KEY }}
NEON_PROJECT_ID: ${{ secrets.NEON_PROJECT_ID }}
pr_opened:
if: github.event.action == 'opened' || github.event.action == 'reopened'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Railway CLI
run: |
curl -fsSL https://railway.com/install.sh | sh
echo "$HOME/.railway/bin" >> $GITHUB_PATH
# Step 1: Create Neon database branch
- name: Create Neon Branch
id: neon
uses: neondatabase/create-branch-action@v5
with:
project_id: ${{ env.NEON_PROJECT_ID }}
branch_name: pr-${{ github.event.pull_request.number }}
api_key: ${{ env.NEON_API_KEY }}
# Step 2: Create Railway environment with Neon DATABASE_URL injected
- name: Create Railway PR Environment
run: |
railway link --project ${{ env.RAILWAY_PROJECT_ID }} --environment ${{ env.RAILWAY_DUPLICATE_ENV_ID }}
railway environment new pr-${{ github.event.pull_request.number }} \
--copy ${{ env.RAILWAY_DUPLICATE_ENV_ID }} \
--service-variable ${{ env.RAILWAY_BACKEND_SERVICE_ID }} "DATABASE_URL=${{ steps.neon.outputs.db_url }}" \
--service-config ${{ env.RAILWAY_BACKEND_SERVICE_ID }} "source.branch" "${{ github.head_ref }}" \
--service-config ${{ env.RAILWAY_WEB_SERVICE_ID }} "source.branch" "${{ github.head_ref }}"I've tried RAILWAY_TOKEN with workspace scoped and unscoped tokens, and also tried the tokens locally on my machine.
6 Replies
I got a bit further. Looks like my LLM did something weird and used RAILWAYTOKEN instead of RAILWAYAPI_TOKEN. Worked once I changed it
However now I'm trying to generate a public for the PR service, but when I runRAILWAY_API_TOKEN=********** bunx @railway/cli domain --service
it tells me the service wasnt found
I copied the uuid for the service from the website's url and I made sure its correct
name: "Get Railway Service URLs"
description: "Generates domains and retrieves URLs for Railway services in a PR environment"
inputs:
railway_api_token:
description: "Railway API token"
required: true
project_id:
description: "Railway project ID"
required: true
environment_name:
description: "Railway environment name (e.g., pr-42)"
required: true
web_service_id:
description: "Railway web service ID"
required: true
backend_service_id:
description: "Railway backend service ID"
required: true
outputs:
web_url:
description: "Generated URL for the web service"
value: ${{ steps.get_urls.outputs.web_url }}
backend_url:
description: "Generated URL for the backend service"
value: ${{ steps.get_urls.outputs.backend_url }}
runs:
using: "composite"
steps:
- name: Get Service URLs
id: get_urls
shell: bash
env:
RAILWAY_API_TOKEN: ${{ inputs.railway_api_token }}
run: |
# Install Railway CLI
curl -fsSL https://railway.com/install.sh | sh
export PATH="$HOME/.railway/bin:$PATH"
# Link to the PR environment
railway link --project ${{ inputs.project_id }} --environment ${{ inputs.environment_name }}
# Get service names from IDs
SERVICES=$(railway service status --all --json 2>/dev/null || echo "[]")
WEB_SERVICE_NAME=$(echo "$SERVICES" | jq -r '.[] | select(.id == "${{ inputs.web_service_id }}") | .name')
BACKEND_SERVICE_NAME=$(echo "$SERVICES" | jq -r '.[] | select(.id == "${{ inputs.backend_service_id }}") | .name')
echo "Web service name: $WEB_SERVICE_NAME"
echo "Backend service name: $BACKEND_SERVICE_NAME"
# Generate domains and get URLs
# Handles both JSON formats: {"domain": "..."} and {"domains": ["..."]}
if [ -n "$WEB_SERVICE_NAME" ]; then
WEB_URL=$(railway domain --service "$WEB_SERVICE_NAME" --json 2>/dev/null | jq -r '.domain // .domains[0] // empty')
echo "web_url=${WEB_URL}" >> $GITHUB_OUTPUT
else
echo "web_url=" >> $GITHUB_OUTPUT
fi
if [ -n "$BACKEND_SERVICE_NAME" ]; then
BACKEND_URL=$(railway domain --service "$BACKEND_SERVICE_NAME" --json 2>/dev/null | jq -r '.domain // .domains[0] // empty')
echo "backend_url=${BACKEND_URL}" >> $GITHUB_OUTPUT
else
echo "backend_url=" >> $GITHUB_OUTPUT
fi