Possible bug: RAILWAY_TOKEN no longer works in @railway/cli >=3.17.9

paced
PRO

8 months ago

Hi team,

@railway/cli versions don't match: repo releases vs. NPM registry

The NPM registry versions do not match up with the more consistently updated GitHub Releases versions. As a result, there is a jump from v3.14.0 to v3.17.9 when using the CLI this way.

Between v3.14.0 and v3.17.9, there seem to be breaking API changes

I've always used npm install -g @railway/cli on my GitHub Actions pipeline to get the latest version of the CLI, and I've noticed after the v3.17.9 update, railway link's options have changed: --project-id has been removed and not deprecated, with no warnings showing up in my logs in v3.14.0.

I would have expected this flag to have removed in v4.0.0 or later and for both flags to be supported until then, with a warning for the older one. I'd be okay with a pre-4.0.0 removal so long as there were warnings showing up in STDERR; maybe this was because of the missing NPM versions as well?

RAILWAY_TOKEN with railway link no longer seems to work

This is my main question: how can I fix this, or is this a bug on the CLI's end?

A valid project-level token as RAILWAY_TOKEN no longer works somewhere between v3.14.1 to v3.17.9 (inclusive) of the CLI, producing this error:

Unauthorized. Please login with `railway login`

For reference, the job:

deploy:
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    steps:
      - uses: actions/checkout@v4
      - run: npm i -g @railway/cli
      - run: railway link --project <snip> --service <snip>
        env:
          RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
      - run: railway up -d
        env:
          RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}

Logging in with railway login is not possible via GitHub Actions. A workaround is simply to pin the version of the CLI to v3.14.0.

Thanks in advance for the help!

Awaiting User Response

12 Replies

8 months ago

> --project-id has been removed and not deprecated.

This is not true, the flag has simply been hidden from the help printout, it can still be used, it was not a breaking change in any way, and the current --project flag provides the same functionality too.

> A valid project-level token as RAILWAY_TOKEN no longer works with v3.17.10 of the CLI

We will try to reproduce this.


Status changed to Awaiting User Response railway[bot] 8 months ago


paced
PRO

8 months ago

the flag has simply been hidden from the help printout

From my logs, around 3 days ago / 24th October 2024, 11:47 AM Australia/Melbourne time (first failed build, last successful build was 6 days ago / 21st October 2024, 1:04 PM same timezone):

error: unexpected argument '--project-id' found

  tip: a similar argument exists: '--project_id'

Usage: railway link <--environment <ENVIRONMENT>|--project <PROJECT>|--service <SERVICE>|--team <TEAM>>

For more information, try '--help'.

Status changed to Awaiting Railway Response railway[bot] 8 months ago


8 months ago

Well, it wasn't removed, just incorrectly named it seems, that's our fault.


Status changed to Awaiting User Response railway[bot] 8 months ago


paced
PRO

8 months ago

All good - thanks for the clarification! I'm alright with those breaking changes as they're simple enough to fix, was just a tad unexpected.


Status changed to Awaiting Railway Response railway[bot] 8 months ago


8 months ago

It shouldn't have broken, we never intended it to, hence it technically still being there, just somehow it was named incorrectly.


Status changed to Awaiting User Response railway[bot] 8 months ago


8 months ago

I was unable to reproduce the issue when using a project token with railway up

Can you shed some light on why you are using the link command in an action, instead of a project token and then passing --service to railway up without using railway link at all.


paced
PRO

8 months ago

I believe it may have been related to making a deploy as similar as possible to doing it manually via the terminal via this (or some similar) post. Additionally, railway up doesn't specify requiring --project or similar, and I only now just realised that it uses the project token as an ID as well.

Is it incorrect to use railway link in GitHub Actions at all? If so, I'm happy with this resolution - thanks!


Status changed to Awaiting Railway Response railway[bot] 8 months ago


8 months ago

I think there are definitely valid reasons to use railway link in an action, but I dont think its needed for your use case.

For railway up in CI, the project and environment are set when you create the project token.


Status changed to Awaiting User Response railway[bot] 8 months ago


paced
PRO

8 months ago

That context is definitely helpful - thanks!


Status changed to Awaiting Railway Response railway[bot] 8 months ago


8 months ago

Let me know if those changes work for you.


Status changed to Awaiting User Response railway[bot] 8 months ago


paced
PRO

8 months ago

Yup, changing to railway up worked for me - thanks again


Status changed to Awaiting Railway Response railway[bot] 8 months ago


8 months ago

No problem! we'll fix the typo!

As for RAILWAY_TOKEN not working with railway link -- that's expected behaviour, given that token itself is scoped to a given environment within a project, if it worked before it was simply because the error was being suppressed.


Status changed to Awaiting User Response railway[bot] 8 months ago