forked from git/git-scm.com
-
Notifications
You must be signed in to change notification settings - Fork 8
142 lines (136 loc) · 5.01 KB
/
update-book.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Update Progit Book
on:
workflow_dispatch:
inputs:
force-rebuild:
description: Force re-building all books (e.g. after a script change)
type: boolean
default: false
schedule:
# check daily for updates
- cron: '29 4 * * *'
jobs:
check-for-updates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
_sync_state
script
- uses: actions/github-script@v7
id: get-pending
with:
script: |
const { getPendingBookUpdates } = require('./script/ci-helper.js')
const pending = await getPendingBookUpdates(github, ${{ inputs.force-rebuild == true }})
// an empty matrix is invalid and makes the workflow run fail, unfortunately
return pending.length ? pending : ['']
- name: ruby setup
# Technically, we do not need Ruby in this job. But we do want to cache
# Ruby & The Gems for use in the matrix in the next job.
if: steps.get-pending.outputs.result != '[""]'
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
outputs:
matrix: ${{ steps.get-pending.outputs.result }}
update-book:
needs: check-for-updates
if: needs.check-for-updates.outputs.matrix != '[""]'
runs-on: ubuntu-latest
strategy:
matrix:
language: ${{ fromJson(needs.check-for-updates.outputs.matrix) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
_sync_state
script
data
content/book/${{ matrix.language.lang }}
static/book/${{ matrix.language.lang }}
- name: clone ${{ matrix.language.repository }}
run: |
printf '%s\n' /progit-clone/ /vendor >>.git/info/exclude &&
# Clone the book's sources
git clone --depth 1 --single-branch \
https://github.com/${{ matrix.language.repository }} progit-clone
- name: ruby setup
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: update book/${{ matrix.language.lang }}
run: |
# this seems to be needed to let `bundle exec` see `vendor/bundle/`
{ bundle check || bundle install --frozen; } &&
# generate the HTML
bundle exec ruby ./script/update-book2.rb ${{ matrix.language.lang }} progit-clone
- name: commit changes
run: |
# record the commit hash
mkdir -p _sync_state &&
git -C progit-clone rev-parse HEAD >_sync_state/book-${{ matrix.language.lang }}.sha &&
# commit it all
git add -A \
_sync_state \
data/book-${{ matrix.language.lang }}.yml \
content/book &&
# there might be images
if test -d static/book
then
git add -A static/book
fi &&
git -c user.name=${{ github.actor }} \
-c user.email=${{ github.actor }}@noreply.github.com \
commit -m 'book: update ${{ matrix.language.lang }}' \
-m 'Updated via the `update-book.yml` GitHub workflow.'
- name: verify that there are no uncommitted changes
run: |
git update-index --refresh &&
if test -n "$(git diff HEAD)$(git ls-files --exclude-standard --other)"
then
echo '::error::there are uncommitted changes!' >&2
git status >&2
exit 1
fi
- name: generate the bundle
run: |
git branch -m book-${{ matrix.language.lang }}
git bundle create ${{ matrix.language.lang }}.bundle refs/remotes/origin/${{ github.ref_name }}..book-${{ matrix.language.lang }}
- uses: actions/upload-artifact@v4
with:
name: bundle-${{ matrix.language.lang }}
path: ${{ matrix.language.lang }}.bundle
push-updates:
needs: [check-for-updates, update-book]
if: needs.check-for-updates.outputs.matrix != '[""]'
permissions:
contents: write # to push changes (if any)
pages: write # to deploy to GitHub Pages
id-token: write # to verify that the deployment source is legit
issues: write # to open tickets upon broken links
environment:
name: github-pages
url: ${{ steps.deploy.outputs.url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
- name: apply updates
id: apply
run: |
for lang in $(echo '${{ needs.check-for-updates.outputs.matrix }}' |
sed -n 's/\[\?{[^}]*"lang":"\([^"]*\)[^}]*},\?\]\?/\1 /gp')
do
git -c core.editor=: \
-c user.name=${{ github.actor }} \
-c user.email=${{ github.actor }}@noreply.github.com \
pull --no-rebase bundle-$lang/$lang.bundle book-$lang ||
exit 1
done
- name: deploy to GitHub Pages
id: deploy
uses: ./.github/actions/deploy-to-github-pages