Skip to content

fixup! Update the download data via a GitHub workflow #13

fixup! Update the download data via a GitHub workflow

fixup! Update the download data via a GitHub workflow #13

name: Update download data
on:
workflow_dispatch:
schedule:
# check daily for updates
- cron: '31 13 * * *'
push:
branches:
- main
- hugo
permissions:
contents: write # need to be able to push
jobs:
update-download-data:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
sparse-checkout: |
_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 &&
git bundle create download-data.bundle ${{ github.sha }}..${{ github.ref }} &&
git push origin HEAD
- name: upload bundle
if: steps.commit.outputs.result != ''
uses: actions/upload-artifact@v3
with:
name: bundle
path: download-data.bundle
outputs:
commit-message: ${{ steps.commit.outputs.result }}
push-updates:
needs: [update-download-data]
if: needs.update-download-data.outputs.commit-message != ''
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- name: apply updates
id: apply
shell: bash
run: |
langs=
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 }} ||
exit 1
done
- name: update gh-pages
uses: ./.github/actions/update-gh-pages
with:
commit-message: ${{ needs.update-download-data.outputs.commit-message }}