@@ -270,20 +270,46 @@ jobs:
270270 # ========================================================================
271271 - name : Determine deployment targets (branch_name and version_name)
272272 id : branch
273+ env :
274+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
273275 run : |
274276 # Determine which branch we're building from
275277 current_branch=${GITHUB_REF#refs/heads/}
276278 if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
277279 current_branch=${GITHUB_BASE_REF}
278280 fi
279281
280- # Find the highest numbered stable branch from the remote
281- # e.g., "stable30", "stable31", "stable32" → extract "32"
282- highest_stable=$(git ls-remote --heads origin | sed -n 's?.*refs/heads/stable\([0-9]\{2\}\)$?\1?p' | sort -n | tail -1)
282+ # Find the highest numbered stable branch that has a v{N}.0.0 release.
283+ # Mirrors the is_version_released() check in build/build-index.php:
284+ # a branch whose first release doesn't exist yet (e.g. RC-only) is skipped.
285+ highest_stable=""
286+ for n in $(git ls-remote --heads origin | sed -n 's?.*refs/heads/stable\([0-9]\{2\}\)$?\1?p' | sort -n -r); do
287+ # Nextcloud moved to nextcloud-releases/server starting with v32
288+ if [ "$n" -ge 32 ]; then
289+ repo="nextcloud-releases/server"
290+ else
291+ repo="nextcloud/server"
292+ fi
293+ http_status=$(curl -s -o /dev/null -w "%{http_code}" \
294+ -H "Authorization: token ${GITHUB_TOKEN}" \
295+ "https://api.github.com/repos/${repo}/releases/tags/v${n}.0.0")
296+ if [ "$http_status" = "200" ]; then
297+ highest_stable="$n"
298+ echo "stable${n}: v${n}.0.0 released — using as highest stable"
299+ break
300+ else
301+ echo "stable${n}: v${n}.0.0 not released yet (HTTP ${http_status}) — skipping"
302+ fi
303+ done
304+
305+ if [ -z "$highest_stable" ]; then
306+ echo "ERROR: No released stable branch found"
307+ exit 1
308+ fi
283309 highest_stable_branch="stable${highest_stable}"
284310
285311 echo "Current branch: $current_branch"
286- echo "Highest stable branch found : $highest_stable_branch"
312+ echo "Highest released stable branch: $highest_stable_branch"
287313
288314 # Map branch to deployment folder names
289315 case "$current_branch" in
0 commit comments