21 days ago
Heya! I run a small open-source project. People can contribute using PRs. I've just looked into the Railway docs and it looks like PR environments arent supported for non-members.
While i understand not spinning up an environment for everyone, i'd like to "mark" certain PRs as safe to preview. Is that possible?
0 Replies
21 days ago
It isn't; you would need to do something custom possibly with tags that trigger an action to do something with railway environment new.
21 days ago
ill look into it, thanks
21 days ago
Looks like this'll work. One more thing i'd like to do is comment the preview url of the service once the new environment is ready
21 days ago
i feel like this current setup is just going to watch for commits on main, not on the pr branch:
# NOTE
# if you have 2fa on your account, the pr close part of the action will hang (due to 2fa not being supported non-interactively)
name: Manage PR environments (Railway)
on:
pull_request:
types: [opened, closed]
env:
RAILWAY_API_TOKEN: "" # get this in account settings (make sure this is NOT a project token), and scope it to your account (not a workspace)
DUPLICATE_FROM_ID: "" # railway environment to duplicate from
LINK_PROJECT_ID: "" # project ID
jobs:
pr_opened:
if: github.event.action == 'opened'
runs-on: ubuntu-latest
container: ghcr.io/railwayapp/cli:latest
steps:
- name: Link to project
run: railway link --project ${{ env.LINK_PROJECT_ID }} --environment ${{ env.DUPLICATE_FROM_ID }}
- name: Create Railway Environment for PR
run: railway environment new pr-${{ github.event.pull_request.number }} --copy ${{ env.DUPLICATE_FROM_ID }}
pr_closed:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
container: ghcr.io/railwayapp/cli:latest
steps:
- name: Link to project
run: railway link --project ${{ env.LINK_PROJECT_ID }} --environment ${{ env.DUPLICATE_FROM_ID }}
- name: Delete Railway Environment for PR
run: railway environment delete pr-${{ github.event.pull_request.number }} || true21 days ago
You can modify it to fit your needs; it's just a barebones example to get you started.