fixup! WIP ci: update the books via a GitHub workflow #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Progit Book | |
on: | |
workflow_dispatch: | |
push: | |
permissions: | |
contents: write # need to be able to push | |
jobs: | |
check-for-updates: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
sparse-checkout: | | |
_sync_state | |
script | |
- uses: actions/github-script@v6 | |
id: get-pending | |
with: | |
script: | | |
const { getPendingBookUpdates } = require('./script/ci-helper.js') | |
const pending = await getPendingBookUpdates(github) | |
// an empty matrix is invalid and makes the workflow run fail, unfortunately | |
return pending.length ? pending : [''] | |
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@v3 | |
with: | |
sparse-checkout: | | |
_sync_state | |
script | |
book/${{ matrix.language.lang }} | |
- name: update book/${{ matrix.language.lang }} | |
shell: bash | |
run: | | |
# Clone the book's sources | |
git clone --depth 1 --single-branch \ | |
https://github.com/${{ matrix.language.repository }} progit-clone && | |
# generate the HTML | |
ruby ./script/update-book2.rb ${{ matrix.language.lang }} progit-clone && | |
# record the commit hash | |
mkdir -p _sync_state && | |
git -C progit-clone rev-parse HEAD >_sync_state/book-${{ matrix.language.lang }}.sha && | |
git add _sync_state && | |
# commit it all | |
echo "/progit-clone/" >>.git/info/exclude && | |
git -c user.name=${{ github.actor }} \ | |
-c user.email=${{ github.actor }}@noreply.github.com \ | |
commit -am 'book: update ${{ matrix.language.lang }}' | |
# generate the bundle | |
git bundle create ${{ matrix.language.lang }}.bundle HEAD^..gh-pages | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: bundle-${{ matrix.language.lang }} | |
path: ${{ matrix.language.lang }}.bundle | |
push: | |
needs: [check-for-updates, update-book] | |
if: needs.check-for-updates.outputs.matrix != '[""]' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
sparse-checkout: . | |
- uses: actions/download-artifact@v3 | |
- name: push updates | |
shell: bash | |
run: | | |
for bundle in bundle-*/*.bundle | |
do | |
git -c core.editor=: \ | |
-c user.name=${{ github.actor }} \ | |
-c user.email=${{ github.actor }}@noreply.github.com \ | |
pull --no-rebase $bundle gh-pages || | |
exit 1 | |
done | |
git push origin HEAD |