-
Notifications
You must be signed in to change notification settings - Fork 38
281 lines (232 loc) · 11.2 KB
/
Copy pathupdate-discord.yaml
File metadata and controls
281 lines (232 loc) · 11.2 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: Update Discord
on:
schedule:
- cron: "0 */8 * * *" # Every 8 hours
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
update-discord:
name: Update Discord
runs-on: ubuntu-latest
timeout-minutes: 4
permissions:
contents: write
steps:
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 1
- uses: DeterminateSystems/nix-installer-action@v16
- name: Validate workspace
run: |
set -euo pipefail
if [[ ! -f "pkgs/discord.nix" ]]; then
echo "::error::pkgs/discord.nix not found"
exit 1
fi
echo "::notice::Workspace validation passed"
- name: Get old versions
id: old-versions
shell: bash
run: |
set -euo pipefail
echo "::group::Extracting current versions"
if ! perl_output=$(perl -ne '
BEGIN { our $platform = ""; }
if (/^\s*linux\s*=\s*\{/) { $platform="linux"; }
if (/^\s*darwin\s*=\s*\{/) { $platform="darwin"; }
if ($platform && /^\s*(stable|ptb|canary|development)\s*=\s*"([^"]+)";/) {
print "OUTPUT_VAR:${platform}_$1=$2\n";
}
' pkgs/discord.nix 2>&1); then
echo "::error::Failed to parse discord.nix for version extraction"
echo "::error::Perl output: $perl_output"
exit 1
fi
if [[ -z "$perl_output" ]]; then
echo "::error::No version information extracted from discord.nix"
exit 1
fi
echo "::debug::Perl output: $perl_output"
while IFS= read -r line; do
line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [[ -z "$line" ]]; then continue; fi
if [[ "$line" == "OUTPUT_VAR:"* ]]; then
key_value="${line#OUTPUT_VAR:}"
echo "$key_value" >> "$GITHUB_OUTPUT"
echo "::debug::Extracted: $key_value"
else
echo "::warning::Unexpected Perl output line: [$line]"
fi
done < <(echo "$perl_output" | tr -d '\r')
echo "::endgroup::"
- name: Update Discord
id: update
env:
NIXPKGS_ALLOW_UNFREE: 1
run: |
set -euo pipefail
echo "::group::Building update script"
if ! nix build --impure --expr 'let pkgs = import <nixpkgs> { config.allowUnfree = true; }; in (pkgs.callPackage ./pkgs/discord.nix {}).passthru.updateScript' 2>&1; then
echo "::error::Failed to build the update script"
exit 1
fi
echo "::endgroup::"
echo "::group::Running update script"
if ! timeout 600 ./result/bin/discord-update 2>&1; then
echo "::error::Update script failed or timed out"
exit 1
fi
echo "::notice::Discord update script completed successfully"
echo "::endgroup::"
rm -f ./result
- name: Get new versions
id: new-versions
shell: bash
run: |
set -euo pipefail
echo "::group::Extracting updated versions"
if [[ ! -f ./pkgs/discord.nix ]]; then
echo "::error::pkgs/discord.nix not found after update script ran"
exit 1
fi
if ! perl_output=$(perl -ne '
BEGIN { our $platform = ""; }
if (/^\s*linux\s*=\s*\{/) { $platform="linux"; }
if (/^\s*darwin\s*=\s*\{/) { $platform="darwin"; }
if ($platform && /^\s*(stable|ptb|canary|development)\s*=\s*"([^"]+)";/) {
print "OUTPUT_VAR:${platform}_$1=$2\n";
}
' pkgs/discord.nix 2>&1); then
echo "::error::Failed to parse updated discord.nix"
echo "::error::Perl output: $perl_output"
exit 1
fi
if [[ -z "$perl_output" ]]; then
echo "::error::No version information extracted from updated discord.nix"
exit 1
fi
echo "::debug::Updated Perl output: $perl_output"
while IFS= read -r line; do
line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [[ -z "$line" ]]; then continue; fi
if [[ "$line" == "OUTPUT_VAR:"* ]]; then
key_value="${line#OUTPUT_VAR:}"
echo "$key_value" >> "$GITHUB_OUTPUT"
echo "::debug::Updated: $key_value"
else
echo "::warning::Unexpected Perl output line: [$line]"
fi
done < <(echo "$perl_output" | tr -d '\r')
echo "::endgroup::"
- name: Test Build
env:
NIXPKGS_ALLOW_UNFREE: 1
run: |
set -euo pipefail
echo "::group::Testing builds"
failed_branches=()
for branch in stable ptb canary development; do
echo "::notice::Testing build for $branch"
if ! timeout 300 nix-build --arg config '{ allowUnfree = true; }' -E "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./pkgs/discord.nix { branch = \"$branch\"; }" 2>&1; then
echo "::error::Failed to build $branch"
failed_branches+=("$branch")
continue
fi
echo "::notice::Successfully built $branch"
rm -f result
done
if [[ ${#failed_branches[@]} -gt 0 ]]; then
echo "::error::Failed to build branches: ${failed_branches[*]}"
exit 1
fi
echo "::notice::All Linux builds tested successfully"
echo "::endgroup::"
- name: Commit changes
if: |
success() && (
steps.old-versions.outputs.linux_stable != steps.new-versions.outputs.linux_stable ||
steps.old-versions.outputs.linux_ptb != steps.new-versions.outputs.linux_ptb ||
steps.old-versions.outputs.linux_canary != steps.new-versions.outputs.linux_canary ||
steps.old-versions.outputs.linux_development != steps.new-versions.outputs.linux_development ||
steps.old-versions.outputs.darwin_stable != steps.new-versions.outputs.darwin_stable ||
steps.old-versions.outputs.darwin_ptb != steps.new-versions.outputs.darwin_ptb ||
steps.old-versions.outputs.darwin_canary != steps.new-versions.outputs.darwin_canary ||
steps.old-versions.outputs.darwin_development != steps.new-versions.outputs.darwin_development
)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OLD_linux_stable: ${{ steps.old-versions.outputs.linux_stable }}
OLD_linux_ptb: ${{ steps.old-versions.outputs.linux_ptb }}
OLD_linux_canary: ${{ steps.old-versions.outputs.linux_canary }}
OLD_linux_development: ${{ steps.old-versions.outputs.linux_development }}
OLD_darwin_stable: ${{ steps.old-versions.outputs.darwin_stable }}
OLD_darwin_ptb: ${{ steps.old-versions.outputs.darwin_ptb }}
OLD_darwin_canary: ${{ steps.old-versions.outputs.darwin_canary }}
OLD_darwin_development: ${{ steps.old-versions.outputs.darwin_development }}
NEW_linux_stable: ${{ steps.new-versions.outputs.linux_stable }}
NEW_linux_ptb: ${{ steps.new-versions.outputs.linux_ptb }}
NEW_linux_canary: ${{ steps.new-versions.outputs.linux_canary }}
NEW_linux_development: ${{ steps.new-versions.outputs.linux_development }}
NEW_darwin_stable: ${{ steps.new-versions.outputs.darwin_stable }}
NEW_darwin_ptb: ${{ steps.new-versions.outputs.darwin_ptb }}
NEW_darwin_canary: ${{ steps.new-versions.outputs.darwin_canary }}
NEW_darwin_development: ${{ steps.new-versions.outputs.darwin_development }}
run: |
set -euo pipefail
echo "::group::Preparing commit"
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
commit_body=""
linux_changes=()
darwin_changes=()
# Check for Linux changes
[[ "$OLD_linux_stable" != "$NEW_linux_stable" ]] && linux_changes+=("stable: $OLD_linux_stable -> $NEW_linux_stable")
[[ "$OLD_linux_ptb" != "$NEW_linux_ptb" ]] && linux_changes+=("ptb: $OLD_linux_ptb -> $NEW_linux_ptb")
[[ "$OLD_linux_canary" != "$NEW_linux_canary" ]] && linux_changes+=("canary: $OLD_linux_canary -> $NEW_linux_canary")
[[ "$OLD_linux_development" != "$NEW_linux_development" ]] && linux_changes+=("development: $OLD_linux_development -> $NEW_linux_development")
# Check for Darwin changes
[[ "$OLD_darwin_stable" != "$NEW_darwin_stable" ]] && darwin_changes+=("stable: $OLD_darwin_stable -> $NEW_darwin_stable")
[[ "$OLD_darwin_ptb" != "$NEW_darwin_ptb" ]] && darwin_changes+=("ptb: $OLD_darwin_ptb -> $NEW_darwin_ptb")
[[ "$OLD_darwin_canary" != "$NEW_darwin_canary" ]] && darwin_changes+=("canary: $OLD_darwin_canary -> $NEW_darwin_canary")
[[ "$OLD_darwin_development" != "$NEW_darwin_development" ]] && darwin_changes+=("development: $OLD_darwin_development -> $NEW_darwin_development")
# Build commit message
if [[ ${#linux_changes[@]} -gt 0 ]]; then
commit_body+="- linux: $(IFS=, ; echo "${linux_changes[*]}")\n"
fi
if [[ ${#darwin_changes[@]} -gt 0 ]]; then
commit_body+="- darwin: $(IFS=, ; echo "${darwin_changes[*]}")\n"
fi
if [[ -z "$commit_body" ]]; then
echo "::notice::No version changes detected, skipping commit"
exit 0
fi
# Remove trailing newline
commit_body=$(echo -e "$commit_body" | sed '/^$/d' | sed '$ s/\\n$//')
COMMIT_MSG="github: update discord versions\n\n$commit_body"
echo "::endgroup::"
if [[ -n "$(git status --porcelain pkgs/discord.nix)" ]]; then
echo "::group::Committing and pushing changes"
git add pkgs/discord.nix
printf "%b" "$COMMIT_MSG" | git commit -F -
echo "::notice::Pushing changes with retry logic..."
for attempt in {1..5}; do
echo "::debug::Push attempt $attempt/5"
if git fetch origin 2>&1 && \
git pull --rebase origin ${{ github.ref_name }} 2>&1 && \
git push origin HEAD:${{ github.ref_name }} 2>&1; then
echo "::notice::Successfully pushed changes on attempt $attempt"
break
fi
if [[ $attempt == 5 ]]; then
echo "::error::Failed to push after 5 attempts"
exit 1
fi
echo "::warning::Push attempt $attempt failed, retrying in $((attempt * 2)) seconds..."
sleep $((attempt * 2))
done
echo "::endgroup::"
else
echo "::notice::No changes to commit (git status shows no modifications)"
fi