Skip to content

Commit

Permalink
Merge branch 'add-automated-updates'
Browse files Browse the repository at this point in the history
This topic adds several workflows to help keep https://git-scm.com/ up
to date.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Nov 21, 2023
2 parents 0b966fd + 5340821 commit 45e7bc2
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/actions/deploy-to-github-pages/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: 'Run Hugo/Pagefind and deploy to GitHub Pages'
description: 'Runs Hugo and Pagefind and then deploys the result to GitHub Pages.'
# This composite Action requires the following things in the calling workflow:
#
# 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
# environment:
# name: github-pages
# url: ${{ steps.<id-of-deployment-step>.outputs.url }}
outputs:
url:
description: The URL to which the site was deployed
value: ${{ steps.deploy.outputs.page_url }}
runs:
using: "composite"
steps:
- name: push changes (if needed)
shell: bash
run: |
test "$(git rev-parse HEAD)" = "$(git rev-parse refs/remotes/origin/${{ github.ref_name }})" ||
git push origin HEAD:${{ github.ref }}
- name: un-sparse worktree to prepare for deployment
shell: bash
run: git sparse-checkout disable

- name: setup GitHub Pages
id: pages
uses: actions/configure-pages@v3

- name: install Hugo
env:
HUGO_VERSION: 0.120.3
shell: bash
run: |
set -x &&
curl -Lo /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v$HUGO_VERSION/hugo_extended_${HUGO_VERSION}_linux-amd64.deb &&
sudo dpkg -i /tmp/hugo.deb
- name: run Hugo to build the pages
env:
HUGO_RELATIVEURLS: false
shell: bash
run: hugo --minify --baseURL "${{ steps.pages.outputs.base_url }}/"

- name: run Pagefind to build the search index
shell: bash
run: npx -y pagefind --site public

- name: upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./public

- name: deploy
id: deploy
uses: actions/deploy-pages@v2
22 changes: 22 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deploy to GitHub Pages

on:
workflow_dispatch:
push:
branches:
- gh-pages

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
pages: write # to deploy to GitHub Pages
id-token: write # to verify that the deployment source is legit
environment:
name: github-pages
url: ${{ steps.deploy.outputs.url }}
steps:
- uses: actions/checkout@v3
- name: deploy to GitHub Pages
id: deploy
uses: ./.github/actions/deploy-to-github-pages
141 changes: 141 additions & 0 deletions .github/workflows/update-book.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
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@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, ${{ inputs.force-rebuild }})
// 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@v3
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@v3
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
environment:
name: github-pages
url: ${{ steps.deploy.outputs.url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- 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
69 changes: 69 additions & 0 deletions .github/workflows/update-download-data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Update download data

on:
workflow_dispatch:
schedule:
# check daily for updates
- cron: '31 13 * * *'

jobs:
update-download-data:
runs-on: ubuntu-latest
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
environment:
name: github-pages
url: ${{ steps.deploy.outputs.url }}
steps:
- uses: actions/checkout@v3
with:
sparse-checkout: |
.github/actions
_sync_state
script
- name: ruby setup
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: update download data
run: |
# this seems to be needed to let `bundle exec` see `vendor/bundle/`
{ bundle check || bundle install --frozen; } &&
# update download data
bundle exec ruby script/update-download-data.rb
- name: commit changes (if any)
id: commit
run: |
# Exit early if there are no changes
git update-index --ignore-submodules --refresh &&
git diff-files --quiet --ignore-submodules -- hugo.yml &&
exit 0
what="$(git diff hugo.yml |
sed -n '/^+ *filename: Git-\([.0-9]*\)-.*\.exe$/{s/.* Git-\([.0-9]*\)-.*/Git for Windows v\1/p;q}')"
mac="$(git diff hugo.yml |
sed -n 's/^+ *filename: git-\([.0-9]*\)-.*\.dmg$/Git for macOS v\1/p')"
test -z "$mac" || what="$what${what:+, }$mac"
commit_message="Update download data${what:+ ($what)}"
echo "result=$commit_message" >>$GITHUB_OUTPUT
git \
-c user.name=${{ github.actor }} \
-c user.email=${{ github.actor }}@noreply.github.com \
commit -m "$commit_message" -- hugo.yml
- 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: deploy to GitHub Pages
if: steps.commit.outputs.result != ''
id: deploy
uses: ./.github/actions/deploy-to-github-pages
98 changes: 98 additions & 0 deletions .github/workflows/update-git-version-and-manual-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Synchronize with new Git version (if any)

on:
workflow_dispatch:
inputs:
force-rebuild:
description: Force re-building all manual pages (e.g. after a script change)
type: boolean
default: false
schedule:
# check daily for updates
- cron: '37 17 * * *'

jobs:
update-git-version-and-manual-pages:
runs-on: ubuntu-latest
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
environment:
name: github-pages
url: ${{ steps.deploy.outputs.url }}
steps:
- uses: actions/checkout@v3
with:
sparse-checkout: |
.github/actions
_sync_state
script
- name: ruby setup
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: update recorded Git version
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# this seems to be needed to let `bundle exec` see `vendor/bundle/`
{ bundle check || bundle install --frozen; } &&
# update recorded Git version
bundle exec ruby script/update-git-version.rb
- name: commit changes (if any)
id: commit
run: |
# Exit early if there are no changes
git update-index --ignore-submodules --refresh &&
git diff-files --quiet --ignore-submodules -- hugo.yml &&
exit 0
version="$(git diff hugo.yml | sed -n '/^+ *latest_version: /{s/.*: //;p;q}')"
echo "result=$version" >>$GITHUB_OUTPUT
git \
-c user.name=${{ github.actor }} \
-c user.email=${{ github.actor }}@noreply.github.com \
commit -m "Update git-version ($version)" -- hugo.yml
- name: prepare worktree
if: steps.commit.outputs.result != '' || inputs.force-rebuild
run: git sparse-checkout disable
- name: clone git.git
if: steps.commit.outputs.result != '' || inputs.force-rebuild
run: git clone --bare https://github.com/git/git '${{ runner.temp }}/git'
- name: update manual pages
if: steps.commit.outputs.result != '' || inputs.force-rebuild
run: |
test false = '${{ inputs.force-rebuild }}' || export RERUN=true
bundle exec ruby script/update-docs.rb '${{ runner.temp }}/git' en
- name: commit manual pages
id: manual-pages
if: steps.commit.outputs.result != '' || inputs.force-rebuild
run: |
git add -A _generated-asciidoc data/docs.yml content/docs &&
if test false != '${{ inputs.force-rebuild }}' && git diff-index --cached --quiet HEAD --
then
echo '::notice::A manual pages rebuild was requested but resulted in no changes' >&2
exit 0
fi &&
version='${{ steps.commit.outputs.result }}' &&
git \
-c user.name=${{ github.actor }} \
-c user.email=${{ github.actor }}@noreply.github.com \
commit -m "Update manual pages (${version:-manually forced rebuild})" &&
echo "result=modified" >>$GITHUB_OUTPUT
- 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: deploy to GitHub Pages
if: steps.commit.outputs.result != '' || steps.manual-pages.outputs.result != ''
id: deploy
uses: ./.github/actions/deploy-to-github-pages
Loading

0 comments on commit 45e7bc2

Please sign in to comment.