Allowing a PR from a non-member to generate an environment
danny
PROOP

a month 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

brody
EMPLOYEE

a month 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.


danny
PROOP

a month ago

ill look into it, thanks


danny
PROOP

a month 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


danny
PROOP

a month 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 }} || true

brody
EMPLOYEE

a month ago

You can modify it to fit your needs; it's just a barebones example to get you started.


Loading...