Skip to content

Auto-Update

Auto-Update #668

Workflow file for this run

name: Auto-Update
on:
schedule:
# roughly 4:23pm PDT (3:23pm PST)
- cron: 20 23 * * *
workflow_dispatch:
defaults:
run:
shell: 'bash -Eeuo pipefail -x {0}'
concurrency:
group: update
cancel-in-progress: true
jobs:
generate-jobs:
name: Generate Jobs
runs-on: ubuntu-latest
outputs:
strategy: ${{ steps.generate-jobs.outputs.strategy }}
steps:
- uses: actions/checkout@v3
- id: generate-jobs
name: Generate Jobs
run: |
strategy="$(
find -name versions.json -exec dirname --zero '{}' + \
| jq -rcsR '
split("\u0000")
| map(ltrimstr("./"))
- [
# directories to skip creating branches/PRs for
"docker-desktop", # no "versions.sh" (yet?)
"docker-master",
empty # trailing comma
]
| sort
| {
matrix: { dir: . },
"fail-fast": false,
}
'
)"
echo "strategy=$strategy" >> "$GITHUB_OUTPUT"
jq . <<<"$strategy" # sanity check / debugging aid
update:
needs: generate-jobs
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }}
name: ${{ matrix.dir }}
runs-on: ubuntu-latest
env:
dir: ${{ matrix.dir }}
branch: update/${{ matrix.dir }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Config
run: |
git config user.name 'Tianon (automated)'
git config user.email '[email protected]'
- name: Rebase
run: |
if git fetch origin "$branch"; then
cur="$(git rev-parse HEAD)"
if git checkout FETCH_HEAD && git rebase "$cur"; then
echo 'yay!'
else
git reset --hard "$cur"
fi
fi
- name: Update
run: |
version_components() {
jq -c '
[
.version // empty,
(
to_entries[]
| select(.value | type == "object" and has("version"))
| .key + " " + .value.version
)
]
' "$dir/versions.json"
}
before="$(version_components)"
./update.sh "$dir"
after="$(version_components)"
git diff || :
message="$(jq -rn "$after - $before"' | "Update " + env.dir + if length > 0 then " to " + join(", ") else "" end')"
before="$(git rev-parse HEAD)"
git commit -m "$message" "$dir" || :
after="$(git rev-parse HEAD)"
if [ "$before" != "$after" ]; then
git push -f origin HEAD:"$branch"
else
head="$(git rev-parse origin/master)"
if [ "$after" = "$head" ]; then
git push origin --delete "$branch" || :
fi
fi
single-branch:
needs: update
if: always()
name: 'Create Single Branch'
runs-on: ubuntu-latest
env:
branch: 'update-versions'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Config
run: |
git config user.name 'Tianon (automated)'
git config user.email '[email protected]'
- name: Rebase
run: |
if git fetch origin "$branch"; then
cur="$(git rev-parse HEAD)"
if git checkout FETCH_HEAD && git rebase "$cur"; then
echo 'yay!'
else
git reset --hard "$cur"
fi
fi
- name: Create Branch
run: |
updateBranches="$(git branch --remotes --list 'origin/update/*')"
for updateBranch in $updateBranches; do
commits="$(git log --format='format:%H' "HEAD..$updateBranch")"
for commit in $commits; do
git cherry-pick "$commit"
done
done
head="$(git rev-parse origin/master)"
cur="$(git rev-parse HEAD)"
if [ "$cur" != "$head" ]; then
git push -f origin HEAD:"$branch"
else
git push origin --delete "$branch" || :
fi