Skip to content

Commit 247189b

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

File tree

3 files changed

+93
-16
lines changed

3 files changed

+93
-16
lines changed

.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: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,8 @@ 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

110-
- name: Compute release version
111-
id: release_version
112-
run: |
113-
branch="${GITHUB_REF#refs/heads/}"
114-
if [[ "$branch" == stable* ]]; then
115-
echo "release=${branch#stable}" >> $GITHUB_OUTPUT
116-
else
117-
echo "release=latest" >> $GITHUB_OUTPUT
118-
fi
119-
120108
- name: Compute PDF release version
121109
if: ${{ matrix.manual.build_pdf_path }}
122110
id: pdf_version
@@ -175,7 +163,7 @@ jobs:
175163
fetch-depth: 0
176164
token: ${{ secrets.COMMAND_BOT_PAT }}
177165

178-
- name: Download all build artifacts
166+
- name: Download all ${{ needs.build.outputs.branch_name }} artifacts
179167
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
180168
with:
181169
path: artifacts/
@@ -185,58 +173,74 @@ jobs:
185173
run: |
186174
current_branch="${GITHUB_REF#refs/heads/}"
187175
176+
# Find the highest numbered stable branch from the remote
188177
highest_stable=$(git ls-remote --heads origin | sed -n 's?.*refs/heads/stable\([0-9]\{2\}\)$?\1?p' | sort -n | tail -1)
189178
highest_stable_branch="stable${highest_stable}"
190179
191180
echo "Current branch: $current_branch"
192181
echo "Highest stable branch found: $highest_stable_branch"
193182
183+
# Map actual branch names to deployment folder names
194184
case "$current_branch" in
195185
"master")
196186
echo "branch_name=latest" >> $GITHUB_OUTPUT
197187
;;
198188
"$highest_stable_branch")
199189
echo "branch_name=stable" >> $GITHUB_OUTPUT
190+
# Also record the numeric version so we can publish to server/<number>/ too
200191
echo "version_name=${highest_stable}" >> $GITHUB_OUTPUT
201192
;;
202193
*)
194+
# Remove stable prefix for current branch
203195
current_branch="${current_branch#stable}"
204196
echo "branch_name=$current_branch" >> $GITHUB_OUTPUT
205197
;;
206198
esac
207199
208-
- name: Merge artifacts into gh-pages layout
200+
echo "Deployment folder name: ${{ steps.branch.outputs.branch_name }}"
201+
echo "Version name for additional deployment (if applicable): ${{ steps.branch.outputs.version_name }}"
202+
203+
- name: Merge ${{ steps.branch.outputs.branch_name }} documentation artifacts into gh-pages
209204
run: |
205+
# List artifacts
210206
ls -la artifacts/*/
211207
208+
# Cleanup old documentation
209+
rm -rf ${{ steps.branch.outputs.branch_name }}
212210
rm -rf server/${{ steps.branch.outputs.branch_name }}
213211
mkdir -p server/${{ steps.branch.outputs.branch_name }}
214212
213+
# Copy all built documentation into dedicated subdirectories
215214
for artifact in artifacts/*; do
216215
if [ -d "$artifact" ]; then
217216
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/"
220217
fi
221218
done
222219
220+
# Move pdf files to the root of the branch_name
223221
mv server/${{ steps.branch.outputs.branch_name }}/*/*.pdf server/${{ steps.branch.outputs.branch_name }}/ || true
224222
223+
# If this is the highest stable branch, also deploy to its versioned folder
225224
if [ -n "${{ steps.branch.outputs.version_name }}" ]; then
225+
rm -rf server/${{ steps.branch.outputs.version_name }}
226226
cp -r server/${{ steps.branch.outputs.branch_name }} server/${{ steps.branch.outputs.version_name }}
227227
fi
228228
229+
# Cleanup
229230
find . -type d -empty -delete
230231
rm -rf artifacts
231232
232233
- name: Add various redirects for go.php and user_manual english version
233234
run: |
235+
# Fetch source branches so git checkout origin/... works from the gh-pages checkout
234236
git fetch origin ${{ github.event.repository.default_branch }} ${{ github.ref_name }}
235237
238+
# Generate go.php redirect from main branch
236239
git checkout origin/${{ github.event.repository.default_branch }} -- go.php/index.html
237240
mkdir -p server/${{ steps.branch.outputs.branch_name }}/go.php
238241
mv go.php/index.html server/${{ steps.branch.outputs.branch_name }}/go.php/index.html
239242
243+
# Generate user_manual english redirect
240244
git checkout origin/${{ github.ref_name }} -- user_manual/index.html
241245
mkdir -p server/${{ steps.branch.outputs.branch_name }}/user_manual
242246
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)