2 months ago
Hi, I'm writing my own PR environment github workflow.
One part of it is the environment creation/update:
- name: Ensure Railway PR Environment
id: railway_env
env:
RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
run: |
railway link --project ${{ env.RAILWAY_PROJECT_ID }} --environment ${{ env.RAILWAY_DUPLICATE_ENV_ID }}
if railway env ${{ env.PR_ENV_NAME }} --json > /dev/null 2>&1; then
echo "Railway environment already exists: ${{ env.PR_ENV_NAME }}"
echo "env_created=false" >> $GITHUB_OUTPUT
railway link --project ${{ env.RAILWAY_PROJECT_ID }} --environment ${{ env.PR_ENV_NAME }}
railway variables set "DATABASE_URL=${{ steps.neon.outputs.db_url }}" --service ${{ env.RAILWAY_BACKEND_SERVICE_ID }}
else
echo "Creating new Railway environment: ${{ env.PR_ENV_NAME }}"
echo "env_created=true" >> $GITHUB_OUTPUT
railway environment new ${{ env.PR_ENV_NAME }} \
--copy ${{ env.RAILWAY_DUPLICATE_ENV_ID }} \
--service-variable ${{ env.RAILWAY_BACKEND_SERVICE_ID }} "DATABASE_URL=${{ steps.neon.outputs.db_url }}" \
--service-variable ${{ env.RAILWAY_BACKEND_SERVICE_ID }} "AUTH_COOKIE_DOMAIN=.up.railway.app"
fiPreviously I had --service-variable set the git branch name on the services, but I since removed that, however the connection is still automatically made, and I don't know where. Is there some default behavior going on?
3 Replies
2 months ago
It's based on whatever you have set in RAILWAY_DUPLICATE_ENV_ID. If that environment has the service with a specific branch set, then so will your duplicate environment.
If I remember correctly, that should be my production environment. I'm pretty I unset that, and also my PR environment is set to the PR branch, so it can't come from the original env.
But you're saying that unless copied from the originating env or setting it, there should be no automation in place that can set it?
Ill double check on my end then and reply if its still an issue
2 months ago
Correct, the act of duplicating the environment isn't going to set a branch unless the base environment has it set.