Skip to content

Sync Railway Status #538

Sync Railway Status

Sync Railway Status #538

name: Sync Railway Status
on:
workflow_run:
workflows:
- CI
types:
- completed
permissions:
checks: read
contents: read
statuses: write
jobs:
sync:
if: >
github.event.workflow_run.conclusion == 'success' &&
(
github.event.workflow_run.head_branch == 'main' ||
github.event.workflow_run.head_branch == 'develop' ||
github.event.workflow_run.head_branch == 'dev' ||
github.event.workflow_run.head_branch == 'hackathon'
)
runs-on: ubuntu-latest
steps:
- name: Resolve Railway commit status
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.workflow_run.head_sha }}
WORKFLOW_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}
run: |
set -euo pipefail
changed_files="$(gh api --paginate "repos/$REPO/commits/$SHA" --jq '.files[]?.filename')"
requires_deploy=false
while IFS= read -r file; do
case "$file" in
packages/shared/*|packages/client/*|packages/server/*|packages/plugin-hyperscape/*|package.json|bun.lock|nixpacks.toml|railway.server.json|Dockerfile.server)
requires_deploy=true
break
;;
esac
done <<< "$changed_files"
if [ "$requires_deploy" != "true" ]; then
gh api "repos/$REPO/statuses/$SHA" \
-X POST \
-f state=success \
-f context="hyperscape - hyperscape" \
-f description="No Railway deployment required" \
-f target_url="$WORKFLOW_URL"
exit 0
fi
deploy_run="$(gh api "repos/$REPO/commits/$SHA/check-runs" --jq '[.check_runs[] | select(.name | startswith("Deploy to Railway ("))] | sort_by(.completed_at) | last')"
if [ -z "$deploy_run" ] || [ "$deploy_run" = "null" ]; then
gh api "repos/$REPO/statuses/$SHA" \
-X POST \
-f state=failure \
-f context="hyperscape - hyperscape" \
-f description="Expected Railway deploy workflow did not run" \
-f target_url="$WORKFLOW_URL"
exit 1
fi
conclusion="$(echo "$deploy_run" | jq -r '.conclusion')"
details_url="$(echo "$deploy_run" | jq -r '.html_url')"
run_name="$(echo "$deploy_run" | jq -r '.name')"
case "$conclusion" in
success)
state=success
description="Deployment verified via $run_name"
;;
failure|cancelled|timed_out|action_required)
state=failure
description="Deployment failed in $run_name"
;;
*)
echo "Skipping unresolved deployment conclusion: $conclusion"
exit 0
;;
esac
gh api "repos/$REPO/statuses/$SHA" \
-X POST \
-f state="$state" \
-f context="hyperscape - hyperscape" \
-f description="$description" \
-f target_url="$details_url"