-
Notifications
You must be signed in to change notification settings - Fork 38
191 lines (161 loc) · 6.83 KB
/
Copy pathupdate-discord.yaml
File metadata and controls
191 lines (161 loc) · 6.83 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
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 (${{ matrix.branch }})
runs-on: ubuntu-latest
strategy:
matrix:
branch: [stable, ptb, canary, development]
max-parallel: 1
timeout-minutes: 15
permissions:
contents: write
steps:
- uses: actions/checkout@v6.0.1
with:
fetch-depth: 1
- uses: DeterminateSystems/nix-installer-action@v21
with:
extra-conf: |
extra-nix-path = nixpkgs=flake:github:NixOS/nixpkgs/nixos-25.11
- name: Validate workspace
run: |
set -euo pipefail
if [[ ! -f "pkgs/discord/data/sources.json" ]]; then
echo "::error::pkgs/discord/data/sources.json not found"
exit 1
fi
echo "::notice::Workspace validation passed"
- name: Get old versions
id: old-versions
shell: bash
run: |
set -euo pipefail
BRANCH="${{ matrix.branch }}"
linux_version=$(jq -r --arg k "linux-$BRANCH" '.[$k].version // ""' pkgs/discord/data/sources.json)
darwin_version=$(jq -r --arg k "osx-$BRANCH" '.[$k].version // ""' pkgs/discord/data/sources.json)
{
echo "linux_$BRANCH=$linux_version"
echo "darwin_$BRANCH=$darwin_version"
} >> "$GITHUB_OUTPUT"
echo "::notice::Old: linux=$linux_version, darwin=$darwin_version"
- name: Update Discord
id: update
env:
NIXPKGS_ALLOW_UNFREE: 1
DISCORD_BRANCHES: ${{ matrix.branch }}
run: |
set -euo pipefail
nixpkgs_config='{ allowUnfree = true; }'
echo "::group::Building update script"
if ! nix build --impure --expr "let pkgs = import <nixpkgs> { config = $nixpkgs_config; }; in (pkgs.callPackage ./pkgs/discord {}).passthru.updateScript" 2>&1; then
echo "::error::Failed to build the update script"
exit 1
fi
echo "::endgroup::"
echo "::group::Running update script"
if ! ./result/bin/discord-update 2>&1; then
echo "::error::Update script failed"
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
if [[ ! -f ./pkgs/discord/data/sources.json ]]; then
echo "::error::pkgs/discord/data/sources.json not found after update script ran"
exit 1
fi
BRANCH="${{ matrix.branch }}"
linux_version=$(jq -r --arg k "linux-$BRANCH" '.[$k].version // ""' pkgs/discord/data/sources.json)
darwin_version=$(jq -r --arg k "osx-$BRANCH" '.[$k].version // ""' pkgs/discord/data/sources.json)
{
echo "linux_$BRANCH=$linux_version"
echo "darwin_$BRANCH=$darwin_version"
} >> "$GITHUB_OUTPUT"
echo "::notice::New: linux=$linux_version, darwin=$darwin_version"
- name: Test Build
env:
NIXPKGS_ALLOW_UNFREE: 1
run: |
set -euo pipefail
echo "::group::Testing builds"
branch="${{ matrix.branch }}"
nixpkgs_config='{ allowUnfree = true; }'
echo "::notice::Testing build for $branch"
if ! nix-build -E "let pkgs = import <nixpkgs> { config = $nixpkgs_config; }; in pkgs.callPackage ./pkgs/discord { branch = \"$branch\"; }" 2>&1; then
echo "::error::Failed to build $branch"
exit 1
fi
rm -f result || true
echo "::notice::Linux build for $branch tested successfully"
echo "::endgroup::"
- name: Commit changes
if: |
success() && (
steps.old-versions.outputs[format('linux_{0}', matrix.branch)] != steps.new-versions.outputs[format('linux_{0}', matrix.branch)] ||
steps.old-versions.outputs[format('darwin_{0}', matrix.branch)] != steps.new-versions.outputs[format('darwin_{0}', matrix.branch)]
)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: ${{ matrix.branch }}
OLD_LINUX: ${{ steps.old-versions.outputs[format('linux_{0}', matrix.branch)] }}
OLD_DARWIN: ${{ steps.old-versions.outputs[format('darwin_{0}', matrix.branch)] }}
NEW_LINUX: ${{ steps.new-versions.outputs[format('linux_{0}', matrix.branch)] }}
NEW_DARWIN: ${{ steps.new-versions.outputs[format('darwin_{0}', matrix.branch)] }}
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=""
if [[ "$OLD_LINUX" != "$NEW_LINUX" ]]; then
commit_body+="linux:"$'\n'" $BRANCH: $OLD_LINUX -> $NEW_LINUX"$'\n'
fi
if [[ "$OLD_DARWIN" != "$NEW_DARWIN" ]]; then
[[ -n "$commit_body" ]] && commit_body+=$'\n'
commit_body+="darwin:"$'\n'" $BRANCH: $OLD_DARWIN -> $NEW_DARWIN"$'\n'
fi
if [[ -z "$commit_body" ]]; then
echo "::notice::No version changes detected, skipping commit"
exit 0
fi
commit_body=$(echo -n "$commit_body" | sed '/^$/d')
COMMIT_MSG="chore(discord): update $BRANCH"$'\n\n'"$commit_body"
echo "::endgroup::"
if [[ -n "$(git status --porcelain pkgs/discord/data/sources.json)" ]]; then
echo "::group::Committing and pushing changes"
git add pkgs/discord/data/sources.json
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"
git rebase --abort 2>/dev/null || true
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