Skip to content

Commit ff2d332

Browse files
authored
Merge pull request #15269 from nextcloud/fix/deploy-supported-branches-only
ci: restrict scheduled deploy matrix to supported branches
2 parents 981c443 + d43db37 commit ff2d332

3 files changed

Lines changed: 125 additions & 16 deletions

File tree

.github/workflows/build-docs.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,21 @@ jobs:
125125
fi
126126
exit $err
127127
128+
- name: Resolve Python version
129+
id: pyver
130+
run: |
131+
# Read the version from the checked-out branch (ref input) so each
132+
# version builds with its own Python; fall back to 3.13 if absent.
133+
if [ -f .python-version ]; then
134+
echo "version=$(tr -d '[:space:]' < .python-version)" >> "$GITHUB_OUTPUT"
135+
else
136+
echo "version=3.13" >> "$GITHUB_OUTPUT"
137+
fi
138+
128139
- name: Set up Python
129140
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
130141
with:
131-
python-version: "3.13"
142+
python-version: ${{ steps.pyver.outputs.version }}
132143
cache: "pip"
133144

134145
- name: Install pip dependencies
@@ -176,10 +187,19 @@ jobs:
176187
with:
177188
ref: ${{ inputs.ref }}
178189

190+
- name: Resolve Python version
191+
id: pyver
192+
run: |
193+
if [ -f .python-version ]; then
194+
echo "version=$(tr -d '[:space:]' < .python-version)" >> "$GITHUB_OUTPUT"
195+
else
196+
echo "version=3.13" >> "$GITHUB_OUTPUT"
197+
fi
198+
179199
- name: Set up Python
180200
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
181201
with:
182-
python-version: "3.13"
202+
python-version: ${{ steps.pyver.outputs.version }}
183203
cache: "pip"
184204

185205
- name: Install pip dependencies
@@ -188,6 +208,11 @@ jobs:
188208
- name: Build epub documentation
189209
run: |
190210
set -e
211+
# HTML sets DOCS_DISPLAY_VERSION via detect-versions and PDF via DOCS_RELEASE;
212+
# the epub job needs it too so stable branches render their real version.
213+
if [[ "${{ inputs.branch }}" =~ ^stable([0-9]+)$ ]]; then
214+
export DOCS_DISPLAY_VERSION="${BASH_REMATCH[1]}"
215+
fi
191216
cd ${{ matrix.manual.directory }}
192217
make epub
193218
ls -la ${{ matrix.manual.build_epub_path }}
@@ -282,10 +307,19 @@ jobs:
282307
with:
283308
ref: ${{ inputs.ref }}
284309

310+
- name: Resolve Python version
311+
id: pyver
312+
run: |
313+
if [ -f .python-version ]; then
314+
echo "version=$(tr -d '[:space:]' < .python-version)" >> "$GITHUB_OUTPUT"
315+
else
316+
echo "version=3.13" >> "$GITHUB_OUTPUT"
317+
fi
318+
285319
- name: Set up Python
286320
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
287321
with:
288-
python-version: "3.13"
322+
python-version: ${{ steps.pyver.outputs.version }}
289323
# pip cache is not compatible with the Docker container
290324
# cache: "pip"
291325

.github/workflows/deploy-docs.yml

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ on:
1515
schedule:
1616
- cron: '0 2 * * *' # 02:00 UTC daily
1717
workflow_dispatch:
18+
inputs:
19+
branch:
20+
description: "Build & deploy a single branch (e.g. master or stable34). Leave empty to build master + all supported stable branches."
21+
required: false
22+
type: string
23+
default: ""
1824

1925
permissions:
2026
contents: read
@@ -30,15 +36,46 @@ jobs:
3036
outputs:
3137
branches: ${{ steps.set.outputs.branches }}
3238
steps:
33-
- name: Collect master and stable branches
39+
- name: Checkout repository
40+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
41+
42+
- name: Setup PHP
43+
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2.37.2
44+
with:
45+
php-version: '8.3'
46+
47+
- name: Compute branch matrix
3448
id: set
3549
env:
36-
GH_TOKEN: ${{ github.token }}
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
INPUT_BRANCH: ${{ inputs.branch }}
3752
run: |
38-
stable_branches=$(gh api "repos/${{ github.repository }}/branches" --paginate \
39-
--jq '.[].name | select(startswith("stable"))' | sort -Vr)
40-
# Build a JSON array: ["master", "stable34", "stable33", ...]
41-
branches_json=$(printf '%s\n' master ${stable_branches} | jq -R . | jq -cs .)
53+
# Manual single-branch dispatch: build only the requested branch.
54+
if [ -n "${INPUT_BRANCH}" ]; then
55+
branches_json=$(printf '%s' "${INPUT_BRANCH}" | jq -R . | jq -cs .)
56+
echo "Single-branch dispatch: ${branches_json}"
57+
echo "branches=${branches_json}" >> $GITHUB_OUTPUT
58+
exit 0
59+
fi
60+
61+
# Scheduled / plain dispatch: master + every stable branch that is still
62+
# within the support window. Ancient branches (e.g. stable10) are on the
63+
# remote but out of support and would blow past the 256-jobs-per-run cap.
64+
nums=$(git ls-remote --heads origin "heads/stable[0-9][0-9]" \
65+
| sed -n 's?.*refs/heads/stable\([0-9]\{2\}\)$?\1?p' | sort -n)
66+
67+
# Reuse the shared helper to get the supported range (lowest..highest).
68+
eval $(php build/detect-versions.php ${nums})
69+
echo "Supported stable range: ${lowest_stable}..${highest_stable}"
70+
71+
selected="master"
72+
for n in ${nums}; do
73+
if [ "$n" -ge "$lowest_stable" ] && [ "$n" -le "$highest_stable" ]; then
74+
selected="${selected} stable${n}"
75+
fi
76+
done
77+
78+
branches_json=$(printf '%s\n' ${selected} | jq -R . | jq -cs .)
4279
echo "Matrix branches: ${branches_json}"
4380
echo "branches=${branches_json}" >> $GITHUB_OUTPUT
4481
@@ -109,10 +146,12 @@ jobs:
109146
id: apply
110147
if: steps.staged.outputs.has_stage == 'true'
111148
run: |
149+
deployed=""
112150
for d in stage/*/; do
113151
[ -d "$d" ] || continue
114152
branch="$(basename "$d")"
115153
echo "Applying version folder: ${branch}"
154+
deployed="${deployed} ${branch}"
116155
117156
mkdir -p "server/${branch}"
118157
for artifact in "stage/${branch}"/*; do
@@ -132,6 +171,10 @@ jobs:
132171
done
133172
done
134173
174+
# Record which folders we deployed this run, so later steps only touch
175+
# those (not the ancient version folders already present on gh-pages).
176+
echo "folders=$(echo ${deployed} | xargs)" >> $GITHUB_OUTPUT
177+
135178
# Cleanup empty directories
136179
find . -type d -empty -delete
137180
@@ -182,17 +225,50 @@ jobs:
182225
if: steps.apply.outputs.has_changes == 'true'
183226
run: |
184227
default_branch="${{ github.event.repository.default_branch }}"
185-
git fetch origin "${default_branch}"
228+
# gh-pages is checked out single-branch, so there is no origin/<default>
229+
# tracking ref. Fetch with an explicit refspec to create it.
230+
git fetch origin "${default_branch}:refs/remotes/origin/${default_branch}"
186231
git checkout "origin/${default_branch}" -- go.php/index.html user_manual/index.html
187232
188-
for d in server/*/; do
189-
[ -d "$d" ] || continue
190-
branch="$(basename "$d")"
233+
# Only the folders deployed this run — not every historical version
234+
# already on gh-pages (some old ones have an incompatible layout).
235+
for branch in ${{ steps.apply.outputs.folders }}; do
236+
rm -rf "server/${branch}/go.php"
191237
mkdir -p "server/${branch}/go.php" "server/${branch}/user_manual"
192238
cp go.php/index.html "server/${branch}/go.php/index.html"
193239
cp user_manual/index.html "server/${branch}/user_manual/index.html"
194240
done
195241
242+
# ========================================================================
243+
# COMPOSE PR BODY — per-version change counts
244+
# ========================================================================
245+
- name: Compose PR body
246+
id: body
247+
if: steps.apply.outputs.has_changes == 'true'
248+
run: |
249+
# Stage everything so new files count too (create-pull-request commits this).
250+
git add -A
251+
{
252+
echo "text<<PR_BODY_EOF"
253+
echo "This PR was automatically generated by the scheduled deploy workflow."
254+
echo ""
255+
echo "Documentation rebuilt for: **${{ steps.apply.outputs.folders }}**"
256+
echo ""
257+
echo "| Version folder | Files changed |"
258+
echo "| --- | ---: |"
259+
total=0
260+
for branch in ${{ steps.apply.outputs.folders }}; do
261+
n=$(git diff --cached --name-only -- "server/${branch}" | wc -l | tr -d ' ')
262+
total=$((total + n))
263+
echo "| \`${branch}\` | ${n} |"
264+
done
265+
# Files outside the deployed version folders (redirects, robots.txt, …).
266+
other=$(git diff --cached --name-only -- . ':(exclude)server/*' | wc -l | tr -d ' ')
267+
echo "| _other_ | ${other} |"
268+
echo "| **Total** | **$((total + other))** |"
269+
echo "PR_BODY_EOF"
270+
} >> "$GITHUB_OUTPUT"
271+
196272
- name: Create Pull Request for documentation deployment
197273
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
198274
id: cpr
@@ -206,9 +282,7 @@ jobs:
206282
branch: "automated/deploy/documentation"
207283
base: gh-pages
208284
title: "Documentation update"
209-
body: |
210-
This PR was automatically generated by the scheduled deploy workflow
211-
and includes the latest documentation for all built versions.
285+
body: ${{ steps.body.outputs.text }}
212286
delete-branch: true
213287
labels: "automated, 3. to review"
214288

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

0 commit comments

Comments
 (0)