Skip to content

Commit 800d5ce

Browse files
committed
chore(ci): add auto stable titles
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent a72de42 commit 800d5ce

3 files changed

Lines changed: 92 additions & 5 deletions

File tree

.github/workflows/generate-top-index.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
git config --local user.name "nextcloud-command"
6363
6464
- name: Create Pull Request for documentation index deployment
65+
if: github.event_name == 'push'
6566
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
6667
id: cpr
6768
with:
@@ -78,6 +79,7 @@ jobs:
7879
labels: 'automated, 3. to review'
7980

8081
- name: Enable Pull Request Automerge
82+
if: github.event_name == 'push'
8183
run: gh pr merge --merge --auto "${{ steps.cpr.outputs.pull-request-number }}"
8284
env:
8385
GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }}

.github/workflows/sphinxbuild.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ jobs:
103103
run: pip install -r requirements.txt
104104

105105
- name: Build html documentation
106-
env:
107-
SPHINXOPTS: "-W --keep-going"
108106
run: cd ${{ matrix.manual.directory }} && make ${{ matrix.manual.make_target }}
109107

110108
- name: Compute release version
@@ -185,58 +183,74 @@ jobs:
185183
run: |
186184
current_branch="${GITHUB_REF#refs/heads/}"
187185
186+
# Find the highest numbered stable branch from the remote
188187
highest_stable=$(git ls-remote --heads origin | sed -n 's?.*refs/heads/stable\([0-9]\{2\}\)$?\1?p' | sort -n | tail -1)
189188
highest_stable_branch="stable${highest_stable}"
190189
191190
echo "Current branch: $current_branch"
192191
echo "Highest stable branch found: $highest_stable_branch"
193192
193+
# Map actual branch names to deployment folder names
194194
case "$current_branch" in
195195
"master")
196196
echo "branch_name=latest" >> $GITHUB_OUTPUT
197197
;;
198198
"$highest_stable_branch")
199199
echo "branch_name=stable" >> $GITHUB_OUTPUT
200+
# Also record the numeric version so we can publish to server/<number>/ too
200201
echo "version_name=${highest_stable}" >> $GITHUB_OUTPUT
201202
;;
202203
*)
204+
# Remove stable prefix for current branch
203205
current_branch="${current_branch#stable}"
204206
echo "branch_name=$current_branch" >> $GITHUB_OUTPUT
205207
;;
206208
esac
207209
208-
- name: Merge artifacts into gh-pages layout
210+
echo "Deployment folder name: ${{ steps.branch.outputs.branch_name }}"
211+
echo "Version name for additional deployment (if applicable): ${{ steps.branch.outputs.version_name }}"
212+
213+
- name: Merge ${{ steps.branch.outputs.branch_name }} documentation artifacts into gh-pages
209214
run: |
215+
# List artifacts
210216
ls -la artifacts/*/
211217
218+
# Cleanup old documentation
219+
rm -rf ${{ steps.branch.outputs.branch_name }}
212220
rm -rf server/${{ steps.branch.outputs.branch_name }}
213221
mkdir -p server/${{ steps.branch.outputs.branch_name }}
214222
223+
# Copy all built documentation into dedicated subdirectories
215224
for artifact in artifacts/*; do
216225
if [ -d "$artifact" ]; then
217226
manual_name="$(basename "$artifact")"
218-
mkdir -p "server/${{ steps.branch.outputs.branch_name }}/$manual_name"
219-
cp -r "$artifact/"* "server/${{ steps.branch.outputs.branch_name }}/$manual_name/"
220227
fi
221228
done
222229
230+
# Move pdf files to the root of the branch_name
223231
mv server/${{ steps.branch.outputs.branch_name }}/*/*.pdf server/${{ steps.branch.outputs.branch_name }}/ || true
224232
233+
# If this is the highest stable branch, also deploy to its versioned folder
225234
if [ -n "${{ steps.branch.outputs.version_name }}" ]; then
235+
rm -rf server/${{ steps.branch.outputs.version_name }}
226236
cp -r server/${{ steps.branch.outputs.branch_name }} server/${{ steps.branch.outputs.version_name }}
227237
fi
228238
239+
# Cleanup
229240
find . -type d -empty -delete
230241
rm -rf artifacts
231242
232243
- name: Add various redirects for go.php and user_manual english version
233244
run: |
245+
# Fetch source branches so git checkout origin/... works from the gh-pages checkout
234246
git fetch origin ${{ github.event.repository.default_branch }} ${{ github.ref_name }}
235247
248+
# Generate go.php redirect from main branch
236249
git checkout origin/${{ github.event.repository.default_branch }} -- go.php/index.html
237250
mkdir -p server/${{ steps.branch.outputs.branch_name }}/go.php
238251
mv go.php/index.html server/${{ steps.branch.outputs.branch_name }}/go.php/index.html
239252
253+
# Generate user_manual english redirect
240254
git checkout origin/${{ github.ref_name }} -- user_manual/index.html
241255
mkdir -p server/${{ steps.branch.outputs.branch_name }}/user_manual
242256
mv user_manual/index.html server/${{ steps.branch.outputs.branch_name }}/user_manual/index.html
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: MIT
3+
name: Update PRs titles on stable branches
4+
5+
on:
6+
pull_request:
7+
types: [opened, edited]
8+
branches:
9+
- "stable*"
10+
11+
concurrency:
12+
group: stable-pr-title-${{ github.event.pull_request.number }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
update-pr-title:
17+
runs-on: ubuntu-latest-low
18+
permissions:
19+
pull-requests: write
20+
contents: read
21+
22+
steps:
23+
- name: Wait for potential title edits
24+
run: sleep 15
25+
26+
- name: Get PR details and update title
27+
# Renovate already have target branch in the title
28+
if: github.event.pull_request.user.login != 'renovate[bot]'
29+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
30+
with:
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
script: |
33+
const { data: pr } = await github.rest.pulls.get({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
pull_number: context.issue.number,
37+
});
38+
39+
const baseBranch = pr.base.ref;
40+
const currentTitle = pr.title;
41+
42+
// Check if this is a stable branch
43+
// Should not happen as we only trigger on stable* branches 🤷‍♀️
44+
if (!baseBranch.startsWith('stable')) {
45+
console.log(`Not a stable branch: ${baseBranch}`);
46+
return;
47+
}
48+
49+
const prefix = `[${baseBranch}]`;
50+
51+
// Check if title already has the correct prefix and no other stable tags
52+
const correctTagRegex = new RegExp(`^\\[${baseBranch}\\]\\s*`);
53+
const hasOtherStableTags = /\[stable[\d.]*\]/.test(currentTitle.replace(correctTagRegex, ''));
54+
55+
if (correctTagRegex.test(currentTitle) && !hasOtherStableTags) {
56+
console.log(`Title already has correct prefix only: ${currentTitle}`);
57+
return;
58+
}
59+
60+
// Remove all stable tags and add the correct one
61+
const cleanTitle = currentTitle.replace(/\[stable[\d.]*\]\s*/g, '').trim();
62+
const newTitle = `${prefix} ${cleanTitle}`;
63+
64+
console.log(`Updating title from: "${currentTitle}" to: "${newTitle}"`);
65+
66+
await github.rest.pulls.update({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
pull_number: context.issue.number,
70+
title: newTitle,
71+
});

0 commit comments

Comments
 (0)