Skip to content

Commit d8dfcec

Browse files
committed
update-book: allow force-rebuilding
Even when everything is marked up to date, it is sometimes necessary to rebuild the books e.g. due to style/layout changes. With this here commit, that is possible by toggling the `force-rebuild` flag of the `workflow_dispatch` trigger. This commit is best viewed with `git show -w`. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 614e7f9 commit d8dfcec

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

.github/workflows/update-book.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: Update Progit Book
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
force-rebuild:
7+
description: Force re-building all books (e.g. after a script change)
8+
type: boolean
9+
default: false
510
schedule:
611
# check daily for updates
712
- cron: '29 4 * * *'
@@ -21,7 +26,7 @@ jobs:
2126
script: |
2227
const { getPendingBookUpdates } = require('./script/ci-helper.js')
2328
24-
const pending = await getPendingBookUpdates(github)
29+
const pending = await getPendingBookUpdates(github, ${{ inputs.force-rebuild == true }})
2530
// an empty matrix is invalid and makes the workflow run fail, unfortunately
2631
return pending.length ? pending : ['']
2732
- name: ruby setup

script/ci-helper.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,32 @@ const getAllBooks = async () => {
1919
}, {})
2020
}
2121

22-
const getPendingBookUpdates = async (octokit) => {
22+
const getPendingBookUpdates = async (octokit, forceRebuild) => {
2323
const books = await getAllBooks()
2424
const result = []
2525
for (const lang of Object.keys(books)) {
26-
try {
27-
const localSha = await getFileContents(`external/book/sync/book-${lang}.sha`)
26+
if (!forceRebuild) {
27+
try {
28+
const localSha = await getFileContents(`external/book/sync/book-${lang}.sha`)
2829

29-
const [owner, repo] = books[lang].split('/')
30-
const { data: { default_branch: remoteDefaultBranch } } =
31-
await octokit.rest.repos.get({
32-
owner,
33-
repo
34-
})
35-
const { data: { object: { sha: remoteSha } } } =
36-
await octokit.rest.git.getRef({
37-
owner,
38-
repo,
39-
ref: `heads/${remoteDefaultBranch}`
40-
})
30+
const [owner, repo] = books[lang].split('/')
31+
const { data: { default_branch: remoteDefaultBranch } } =
32+
await octokit.rest.repos.get({
33+
owner,
34+
repo
35+
})
36+
const { data: { object: { sha: remoteSha } } } =
37+
await octokit.rest.git.getRef({
38+
owner,
39+
repo,
40+
ref: `heads/${remoteDefaultBranch}`
41+
})
4142

42-
if (localSha === remoteSha) continue
43-
} catch (e) {
44-
// It's okay for the `.sha` file not to exist yet.`
45-
if (e.code !== 'ENOENT') throw e
43+
if (localSha === remoteSha) continue
44+
} catch (e) {
45+
// It's okay for the `.sha` file not to exist yet.`
46+
if (e.code !== 'ENOENT') throw e
47+
}
4648
}
4749
result.push({
4850
lang,

0 commit comments

Comments
 (0)