2 months ago
agents often get confused about whether a recent github commit made it's way into the actual railway deployment, is there an easier way than "railway deployment list -s backend --limit 5 --json" and examining the json to verify that the latest commit == live deployment on railway?
Pinned Solution
2 months ago
Hello!
The easiest way I've found is to skip the deployment list entirely and use railway status --json with jq:
railway status --json | jq -r '.services.edges[].node | {service: .name, commit: .serviceInstances.edges[].node.latestDeployment.meta.commitHash}'
If you want a quick "is my latest commit live?" check, you can wrap it:
DEPLOYED=$(railway status --json | jq -r '.services.edges[].node.serviceInstances.edges[].node.latestDeployment.meta.commitHash')
LATEST=$(git rev-parse HEAD)
[ "$DEPLOYED" = "$LATEST" ] && echo "in sync" || echo "mismatch - deployed: $DEPLOYED local: $LATEST"
Another approach that works well for agents specifically is when Railway injects RAILWAY_GIT_COMMIT_SHA into every GitHub-triggered deploy. If you expose it through a health endpoint, you can just curl it without needing the CLI at all:
@app.route("/health")
def health():
return {"commit": os.environ.get("RAILWAY_GIT_COMMIT_SHA", "unknown")}
Honestly though, a railway deployment active --service backend that just prints the commit hash would be the cleanest solution. The nested JSON from status works but it's not exactly intuitive.
WDYT?
Hope this helped.
3 Replies
Status changed to Awaiting Railway Response Railway • about 2 months ago
Status changed to Open Railway • about 2 months ago
2 months ago
Hello!
The easiest way I've found is to skip the deployment list entirely and use railway status --json with jq:
railway status --json | jq -r '.services.edges[].node | {service: .name, commit: .serviceInstances.edges[].node.latestDeployment.meta.commitHash}'
If you want a quick "is my latest commit live?" check, you can wrap it:
DEPLOYED=$(railway status --json | jq -r '.services.edges[].node.serviceInstances.edges[].node.latestDeployment.meta.commitHash')
LATEST=$(git rev-parse HEAD)
[ "$DEPLOYED" = "$LATEST" ] && echo "in sync" || echo "mismatch - deployed: $DEPLOYED local: $LATEST"
Another approach that works well for agents specifically is when Railway injects RAILWAY_GIT_COMMIT_SHA into every GitHub-triggered deploy. If you expose it through a health endpoint, you can just curl it without needing the CLI at all:
@app.route("/health")
def health():
return {"commit": os.environ.get("RAILWAY_GIT_COMMIT_SHA", "unknown")}
Honestly though, a railway deployment active --service backend that just prints the commit hash would be the cleanest solution. The nested JSON from status works but it's not exactly intuitive.
WDYT?
Hope this helped.
2 months ago
A much easier way is to make the running app report its own commit SHA. On Railway, GitHub-triggered deployments get RAILWAY_GIT_COMMIT_SHA, so you can expose that in a /version endpoint or print it at startup. Then you just compare the SHA from GitHub with the SHA reported by the live app. That’s usually more reliable than scanning deployment JSON, because it tells you what is actually running in production. If you want to check from Railway’s side, use the Public API to fetch the latest active deployment rather than listing recent deployments and inspecting them manually.
andreahlert
Hello! The easiest way I've found is to skip the deployment list entirely and use railway status --json with jq: `railway status --json | jq -r '.services.edges[].node | {service: .name, commit: .serviceInstances.edges[].node.latestDeployment.meta.commitHash}'` If you want a quick "is my latest commit live?" check, you can wrap it: DEPLOYED=$(railway status --json | jq -r '.services.edges\[\].node.serviceInstances.edges\[\].node.latestDeployment.meta.commitHash') LATEST=$(git rev-parse HEAD) \[ "$DEPLOYED" = "$LATEST" \] && echo "in sync" || echo "mismatch - deployed: $DEPLOYED local: $LATEST" Another approach that works well for agents specifically is when Railway injects RAILWAY\_GIT\_COMMIT\_SHA into every GitHub-triggered deploy. If you expose it through a health endpoint, you can just curl it without needing the CLI at all: `@app.route("/health")` ` def health():` ` return {"commit": os.environ.get("RAILWAY_GIT_COMMIT_SHA", "unknown")}` Honestly though, a railway deployment active --service backend that just prints the commit hash would be the cleanest solution. The nested JSON from status works but it's not exactly intuitive. WDYT? Hope this helped.
2 months ago
really like the health endpoint solution. i think this would be a be a neat feature in the railway cli to expose also.
Status changed to Solved brody • about 2 months ago
