Skip to content

Commit 2cf0592

Browse files
committed
trigger railway redeploy via graphql instead of CLI
1 parent becff96 commit 2cf0592

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

.github/workflows/actions-image.yml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,43 @@ jobs:
101101
echo "✓ Pinned service image to $IMAGE."
102102
103103
- name: Trigger Railway redeploy
104-
if: success() && env.RAILWAY_API_TOKEN != ''
104+
if: success() && env.RAILWAY_TOKEN != ''
105105
env:
106-
# CLI parses the env var name to decide token type:
107-
# RAILWAY_TOKEN → project token, RAILWAY_API_TOKEN → personal/team.
108-
# The GitHub secret stays named RAILWAY_TOKEN; we just bind it under
109-
# the API-token name so the CLI accepts our personal access token.
110-
RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
106+
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
111107
RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
112108
RAILWAY_SERVICE_ID: ${{ secrets.RAILWAY_SERVICE_ID }}
109+
RAILWAY_ENVIRONMENT_ID: ${{ secrets.RAILWAY_ENVIRONMENT_ID }}
113110
run: |
111+
set -euo pipefail
114112
# Fires the actual deploy. The previous step changed the source
115113
# to the SHA-tagged image but `serviceInstanceUpdate` alone does
116114
# not trigger a deployment — Railway needs an explicit poke.
117-
npm i -g @railway/cli
118-
railway link --project "$RAILWAY_PROJECT_ID"
119-
railway service "$RAILWAY_SERVICE_ID"
120-
railway deploy --yes
115+
# Using GraphQL directly (same Bearer auth that worked above)
116+
# rather than @railway/cli, which rejects personal access tokens.
117+
payload=$(jq -n \
118+
--arg projectId "$RAILWAY_PROJECT_ID" \
119+
--arg environmentId "$RAILWAY_ENVIRONMENT_ID" \
120+
--arg serviceId "$RAILWAY_SERVICE_ID" \
121+
'{
122+
query: "mutation($input: EnvironmentTriggersDeployInput!) { environmentTriggersDeploy(input: $input) }",
123+
variables: {
124+
input: {
125+
projectId: $projectId,
126+
environmentId: $environmentId,
127+
serviceId: $serviceId
128+
}
129+
}
130+
}')
131+
132+
response=$(curl -fsSL -X POST https://backboard.railway.com/graphql/v2 \
133+
-H "Authorization: Bearer $RAILWAY_TOKEN" \
134+
-H "Content-Type: application/json" \
135+
-d "$payload")
136+
137+
echo "$response"
138+
if echo "$response" | jq -e '.errors' > /dev/null; then
139+
echo "::error::Railway API returned errors — see response above" >&2
140+
exit 1
141+
fi
142+
143+
echo "✓ Triggered redeploy."

0 commit comments

Comments
 (0)