Skip to content

Commit 5bf844c

Browse files
committed
Add a GitHub workflow to update the translated manual pages regularly
After taking care of the English manual pages, let's also have a scheduled workflow that takes care of updating the translated manual pages. Just like the scheduled workflow that takes care of the original, English manual pages, here we also need a flag to toggle complete rebuilds in case the script, the style sheets, or the layouts changed. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0920fb1 commit 5bf844c

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Update translated manual pages
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
force-rebuild:
7+
description: Force re-building all manual pages (e.g. after a script change)
8+
type: boolean
9+
default: false
10+
schedule:
11+
# check daily for updates
12+
- cron: '41 19 * * *'
13+
14+
jobs:
15+
check-for-updates:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
sparse-checkout: |
21+
external/docs/sync
22+
script
23+
- uses: actions/github-script@v7
24+
id: get-pending
25+
with:
26+
script: |
27+
const { areTranslatedManualPagesUpToDate } = require('./script/ci-helper.js')
28+
29+
return await areTranslatedManualPagesUpToDate(github)
30+
outputs:
31+
up-to-date: ${{ steps.get-pending.outputs.result }}
32+
update-translated-manual-pages:
33+
needs: [check-for-updates]
34+
if: inputs.force-rebuild == true || needs.check-for-updates.outputs.up-to-date == 'false'
35+
runs-on: ubuntu-latest
36+
permissions:
37+
contents: write # to push changes (if any)
38+
pages: write # to deploy to GitHub Pages
39+
id-token: write # to verify that the deployment source is legit
40+
environment:
41+
name: github-pages
42+
url: ${{ steps.deploy.outputs.url }}
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: ruby setup
46+
uses: ruby/setup-ruby@v1
47+
with:
48+
bundler-cache: true
49+
- name: clone jnavila/git-html-l10n
50+
run: git clone --bare https://github.com/jnavila/git-html-l10n '${{ runner.temp }}/git-html-l10n'
51+
- name: update translated manual pages
52+
run: |
53+
if test true = '${{ inputs.force-rebuild }}'
54+
then
55+
export RERUN=true
56+
fi
57+
bundle exec ruby script/update-docs.rb '${{ runner.temp }}/git-html-l10n' l10n
58+
- name: commit translated manual pages
59+
id: manual-pages
60+
run: |
61+
mkdir -p external/docs/sync &&
62+
git -C '${{ runner.temp }}/git-html-l10n' rev-parse HEAD >external/docs/sync/git-html-l10n.sha &&
63+
git add external/docs/sync/git-html-l10n.sha &&
64+
65+
git add -A external/docs &&
66+
if test true = '${{ inputs.force-rebuild }}' && git diff-index --cached --quiet HEAD --
67+
then
68+
echo '::notice::Rebuild of the translated manual pages was requested but resulted in no changes' >&2
69+
exit 0
70+
fi &&
71+
git \
72+
-c user.name=${{ github.actor }} \
73+
-c user.email=${{ github.actor }}@noreply.github.com \
74+
commit -m "Update translated manual pages" \
75+
-m 'Updated via the `update-translated-manual-pages.yml` GitHub workflow.' &&
76+
echo "result=modified" >>$GITHUB_OUTPUT
77+
- name: verify that there are no uncommitted changes
78+
run: |
79+
git update-index --refresh &&
80+
if test -n "$(git diff HEAD)$(git ls-files --exclude-standard --other)"
81+
then
82+
echo '::error::there are uncommitted changes!' >&2
83+
git status >&2
84+
exit 1
85+
fi
86+
- name: deploy to GitHub Pages
87+
if: steps.manual-pages.outputs.result != ''
88+
id: deploy
89+
uses: ./.github/actions/deploy-to-github-pages

script/ci-helper.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,40 @@ const getPendingBookUpdates = async (octokit, forceRebuild) => {
5454
return result
5555
}
5656

57+
const areTranslatedManualPagesUpToDate = async (octokit) => {
58+
try {
59+
const localSha = await getFileContents(`external/docs/sync/git-html-l10n.sha`)
60+
61+
const [owner, repo] = 'jnavila/git-html-l10n'.split('/')
62+
const { data: { default_branch: remoteDefaultBranch } } =
63+
await octokit.rest.repos.get({
64+
owner,
65+
repo
66+
})
67+
const { data: { object: { sha: remoteSha } } } =
68+
await octokit.rest.git.getRef({
69+
owner,
70+
repo,
71+
ref: `heads/${remoteDefaultBranch}`
72+
})
73+
74+
if (localSha === remoteSha) return true
75+
} catch (e) {
76+
// It's okay for the `.sha` file not to exist yet.`
77+
if (e.code !== 'ENOENT') throw e
78+
}
79+
return false
80+
}
81+
5782
// for testing locally, needs `npm install @octokit/rest` to work
5883
if (require.main === module) {
5984
(async () => {
6085
const { Octokit } = require('@octokit/rest')
61-
console.log(await getPendingBookUpdates(new Octokit()))
86+
console.log(await areTranslatedManualPagesUpToDate(new Octokit()))
6287
})().catch(console.log)
6388
}
6489

6590
module.exports = {
66-
getPendingBookUpdates
91+
getPendingBookUpdates,
92+
areTranslatedManualPagesUpToDate
6793
}

0 commit comments

Comments
 (0)