Auto-Update #1124
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: 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@v4 | |
- 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@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install Bashbrew | |
run: | | |
mkdir -p "$RUNNER_TEMP/bin" | |
wget -O "$RUNNER_TEMP/bin/bashbrew" 'https://github.com/docker-library/bashbrew/releases/download/v0.1.8/bashbrew-amd64' | |
chmod +x "$RUNNER_TEMP/bin/bashbrew" | |
"$RUNNER_TEMP/bin/bashbrew" --version | |
echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH" | |
- 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 -f .github/workflows/version-components.jq "$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@v4 | |
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 |