How to get DATABASE_URL in Github Actions
When we create a PR, Railway automatic makes a new environment, says
myproject-pr-40
, inside we have Postgres service with new temporary DATABASE_URL variable, we want to have that value when running our Github Actions, is it possible?
Any hint is greatly appreciated. π30 Replies
Project ID:
28677a80-2aaf-46d7-8fff-e2898fa09eb1
28677a80-2aaf-46d7-8fff-e2898fa09eb1
New>database >postgres
@techmatic007 I don't understand what do you mean? I already have Postgres service running.
If you added postgres service on Railway project then add environment DATABASE_URL . It will automatically show postgres click on it.
Thanks for quick response. The service already has the DATABASE_URL variable. I would like to get that value from inside our Github Actions.
oh I understand,idk @Brody will help you
BTW you can get url from postgres plugin variables.
The struggle I'm facing is, we have Prisma, sometimes it has schema changes => migration need to be deployed. Our project monorepo structure:
For now, everything related to server works great. And we would like to have the
prisma migrate deploy
runs somewhere after the PR triggered.
Thanks, but I do not want to manually copy/paste for every single PR
I saw we have variables
command in railway CLI, will play with it a bitI very much do not appreciate being volunteered out like that, don't do that again please
For now I use the CLI to get the value, but I face new issue, somehow it get wrong variable from
production
environment!
I checked the Github Actions output, it shows that the step Activate Railway environment
run correctly.
When I use the railway CLI locally, I can see the railway variables -s server
return correct variable values for each environment. But in Github Actions, for some reason it always get production
no matter what I try.i have an incredably small amount of knowledge with gh actions, the best advice i could give would be to add some
railway status
commands here and thereThanks @Brody. I think this is because I use
RAILWAY_TOKEN
generated from production
environment, making the railway variables -s server
command ignores everything else. If this is the case then it's so hard for us to make Github Action to work with auto generated environment, as the token has to be generated manually.that makes sense, can you use a global account token in this case?
π oh do we have it? let me try
π’ railway CLI uses only project token.
Look like that global account token only used for GraphQL API at the moment
railway cli, at least on the desktop does use a global token, i guess just not that global token
I can't find any place with another global token
best I could think of would be to pull it from the cli's config file on your desktop
thanks @Brody for your patience, I got the
user.token
inside config.json
but it failed with this error:
can you add a log to see what railway cli version github is installing?
I ran
npm info
inside github action because the npm install
does not show the version, I guess they get the same π€·ββοΈ3.3.1 is the latest
I have to use the API token and query then manually find the IDs, it works for now.
I hope Railway can allow us to use personal token (or API token) in CLI so it can query variables from all environments.
that would be ideal, but I love your persistence and problem solving abilities
thanks π
I will mark this as solved for now, but would be happy to revisit when CLI has updated
I copied my postgres url from railway and added it to my github secrets for the project. You can call the env variable inside of actions using
${{secrets.DATABASE_URL}}
I had to upgrade to github pro plan to use environment variables as wellThanks Shaki, but for automatically generated environment, the DATABASE_URL is different from the one in production environment. And I donβt want to manually copy/paste for every single new PR.