Преглед изворни кода

CI: NEO client project is una-ci; domains.sh can find it by domain

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Andrey Yasko пре 2 недеља
родитељ
комит
aebd612024
2 измењених фајлова са 20 додато и 5 уклоњено
  1. 2 2
      .github/workflows/ci.yml
  2. 18 3
      scripts/railway/domains.sh

+ 2 - 2
.github/workflows/ci.yml

@@ -103,7 +103,7 @@ jobs:
       # unacms.app hosts: the backend on Railway, the NEO client (neo-ci on Vercel) in front of it
       VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
       VERCEL_TEAM: yasko
-      CLIENT_PROJECT: neo
+      CLIENT_PROJECT: una-ci
       PREVIEW_API_HOST: api-pr-${{ github.event.pull_request.number }}.unacms.app
       PREVIEW_CLIENT_HOST: pr-${{ github.event.pull_request.number }}.unacms.app
       UNA_PREVIEW_API_KEY: ${{ secrets.UNA_PREVIEW_API_KEY }}
@@ -312,7 +312,7 @@ jobs:
       RAILWAY_PR_ENVIRONMENT: pr-${{ github.event.pull_request.number }}
       VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
       VERCEL_TEAM: yasko
-      CLIENT_PROJECT: neo
+      CLIENT_PROJECT: una-ci
     steps:
     - uses: actions/checkout@v4
       with:

+ 18 - 3
scripts/railway/domains.sh

@@ -10,11 +10,12 @@
 #
 # Environment: VERCEL_TOKEN, RAILWAY_PROJECT_ID (api-domain), RAILWAY_API_TOKEN (railway CLI),
 #   VERCEL_TEAM (team slug or id; found from DNS_ZONE ownership when unset),
-#   DNS_ZONE (default unacms.app), CLIENT_PROJECT (Vercel project of the NEO client, default neo).
+#   DNS_ZONE (default unacms.app), CLIENT_PROJECT (Vercel project of the NEO client; when unset
+#   or not found, the project that has DNS_ZONE attached).
 set -euo pipefail
 
 DNS_ZONE="${DNS_ZONE:-unacms.app}"
-CLIENT_PROJECT="${CLIENT_PROJECT:-neo}"
+CLIENT_PROJECT="${CLIENT_PROJECT:-}"
 RAILWAY_SERVICE="${RAILWAY_SERVICE:-una}"
 VERCEL_API=https://api.vercel.com
 
@@ -104,9 +105,23 @@ api_domain() { # api_domain <host> <environment>
     echo "api: https://$host ($label)"
 }
 
+# The client project: CLIENT_PROJECT when it exists, else the project serving DNS_ZONE.
+client_project_id() {
+    local id p
+    if [ -n "$CLIENT_PROJECT" ] && id=$(vercel GET "/v9/projects/$CLIENT_PROJECT" 2>/dev/null | jq -r '.id // empty') && [ -n "$id" ]; then
+        echo "$id"; return
+    fi
+    for p in $(vercel GET "/v9/projects?limit=100" | jq -r '.projects[].id'); do
+        if vercel GET "/v9/projects/$p/domains?limit=100" | jq -e --arg z "$DNS_ZONE" '.domains[] | select(.name == $z or .name == ("www." + $z))' >/dev/null; then
+            echo "$p"; return
+        fi
+    done
+    die "no Vercel project serves $DNS_ZONE"
+}
+
 client_alias() { # client_alias <host> [branch]
     local host=$1 branch=${2:-} project uid=""
-    project=$(vercel GET "/v9/projects/$CLIENT_PROJECT" | jq -r '.id')
+    project=$(client_project_id)
     if [ -n "$branch" ]; then
         uid=$(vercel GET "/v6/deployments?projectId=$project&state=READY&limit=100" \
             | jq -r --arg b "$branch" '[.deployments[] | select(.meta.githubCommitRef == $b)] | sort_by(.created) | last | .uid // empty')