fixup! WIP ci: update the books via a GitHub workflow #14
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: | |
update-book: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
language: | |
- lang: en | |
repository: progit/progit2 | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
sparse-checkout: | | |
_sync_state | |
script | |
book/${{ matrix.language.lang }} | |
- name: ruby setup | |
uses: ruby/setup-ruby@v1 | |
env: | |
BUNDLE_WITH: scripts | |
with: | |
ruby-version: 3.1.3 | |
bundler-cache: true | |
cache-version: 1 | |
- name: action-tmate | |
uses: mxschmitt/action-tmate@v3 | |
with: | |
limit-access-to-actor: true | |
detached: true | |
- 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 | |
bundle exec 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^..${{ github.ref_name }} | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: bundle-${{ matrix.language.lang }} | |
path: ${{ matrix.language.lang }}.bundle | |
push: | |
needs: [update-book] | |
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 ${{ github.ref_name }} || | |
exit 1 | |
done | |
git push origin HEAD |