-
Notifications
You must be signed in to change notification settings - Fork 227
145 lines (138 loc) · 4.34 KB
/
update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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