Skip to content

Commit 4fe7873

Browse files
authored
ci: old way to do things but with new twilight release name (#265)
Closes #263.
1 parent e646c6a commit 4fe7873

3 files changed

Lines changed: 143 additions & 39 deletions

File tree

.github/update.sh

Lines changed: 138 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,63 @@ get_beta_tag_short_meta() {
4141
echo "$remote_tags" | jq -r '(map(select(.name | test("[0-9]+\\.[0-9]+b$")))) | first'
4242
}
4343

44-
get_twilight_tag_short_meta() {
45-
# tags like twilight-1, twilight-2, etc... or you'll make me angry
46-
echo "$remote_tags" | jq -r '(map(select(.name | test("^twilight-[0-9]+$")))) | sort_by(.name | split("-")[1] | tonumber) | reverse | first'
44+
get_twilight_tag_full_meta() {
45+
# Remove control characters
46+
with_retry gh api repos/zen-browser/desktop/releases/tags/twilight-1
4747
}
4848

49+
twilight_tag=$(get_twilight_tag_full_meta)
4950
beta_tag=$(get_beta_tag_short_meta)
50-
twilight_tag=$(get_twilight_tag_short_meta)
51+
52+
get_twilight_release_artifact_meta_from_zen_repo() {
53+
arch=$1
54+
os=$2
55+
56+
if [ "$os" = "darwin" ]; then
57+
echo "$twilight_tag" | tr -d '\000-\031' | jq -r \
58+
'.assets[] | select(.name | contains("zen.macos-universal.dmg")) | "\(.id) \(.name)"'
59+
else
60+
echo "$twilight_tag" | tr -d '\000-\031' | jq -r --arg arch "$arch" \
61+
'.assets[] | select(.name | contains("zen.linux") and contains($arch)) | "\(.id) \(.name)"'
62+
fi
63+
}
64+
65+
download_artifact_from_zen_repo() {
66+
artifact_id="$1"
67+
# relative or absolute path
68+
file_path="$2"
69+
70+
curl -L \
71+
-H "Accept: application/octet-stream" \
72+
-H "X-GitHub-Api-Version: 2022-11-28" \
73+
"https://api.github.com/repos/zen-browser/desktop/releases/assets/$artifact_id" >"$file_path"
74+
}
75+
76+
get_updated_at_of_twilight_artifact_from_zen_repo() {
77+
with_retry gh api repos/zen-browser/desktop/releases/tags/twilight-1 | jq -r '.assets | (map(select(.name | test("zen.linux-(x86_64|aarch64).tar.xz")))) | first | .updated_at'
78+
}
79+
80+
get_twilight_version_name() {
81+
echo "$twilight_tag" | tr -d '\000-\031' | jq -r '.name' | grep -oE '([0-9\.])+(t|-t.[0-9]+)'
82+
}
83+
84+
resolve_full_sha1_from_zen_repo() {
85+
short_sha1="$1"
86+
87+
with_retry curl -sL \
88+
-H "Accept: application/vnd.github+json" \
89+
-H "X-GitHub-Api-Version: 2022-11-28" \
90+
"https://api.github.com/repos/zen-browser/desktop/commits/$short_sha1" |
91+
jq -r '.sha'
92+
}
5193

5294
resolve_version_remote_sha1() {
5395
# twilight or beta
5496
version="$1"
5597

5698
if [ "$version" = "twilight" ]; then
57-
echo "$twilight_tag" | jq -r '.commit.sha'
99+
short_sha1=$(echo "$twilight_tag" | tr -d '\000-\031' | jq -r '.body' | grep -oE '^[-•] [0-9a-f]{7,}' | head -n 1 | awk '{print $2}')
100+
resolve_full_sha1_from_zen_repo "$short_sha1"
58101
return
59102
fi
60103

@@ -67,11 +110,18 @@ resolve_version_remote_sha1() {
67110
exit 1
68111
}
69112

113+
twilight_version_name=$(get_twilight_version_name)
114+
if [ "$twilight_version_name" = "" ]; then
115+
echo "No twilight version name could be extracted... (clue: $twilight_tag))" 1>&2
116+
exit 1
117+
fi
118+
70119
resolve_semver() {
120+
# twilight or beta
71121
version="$1"
72122

73123
if [ "$version" = "twilight" ]; then
74-
echo "$twilight_tag" | jq -r '.name'
124+
echo "$twilight_version_name"
75125
return
76126
fi
77127

@@ -103,8 +153,15 @@ update_version() {
103153
local_sha1=$(echo "$meta" | jq -r '.sha1')
104154
remote_sha1=$(resolve_version_remote_sha1 "$version_name")
105155

106-
local="$local_sha1"
107-
remote="$remote_sha1"
156+
local=""
157+
remote=""
158+
if [ "$version_name" = "twilight" ]; then
159+
local=$(jq -r '.metadata_for.twilight.last_updated_at' sources.json)
160+
remote=$(get_updated_at_of_twilight_artifact_from_zen_repo)
161+
else
162+
local="$local_sha1"
163+
remote="$remote_sha1"
164+
fi
108165

109166
echo "Checking $version_name version @ $arch... local=$local remote=$remote"
110167

@@ -113,15 +170,20 @@ update_version() {
113170
return
114171
fi
115172

116-
echo "Local $version_name version mismatch with remote so we assume it's outdated"
173+
echo "Local $version_name version mismatch with remote so we* assume it's outdated"
117174

118175
if $only_check; then
119176
echo "should_update=true" >>"$GITHUB_OUTPUT"
120177
exit 0
121178
fi
122179

123180
semver=$(resolve_semver "$version_name")
181+
updated_at="$remote"
182+
124183
target_release_name="$semver"
184+
if [ "$version_name" = "twilight" ]; then
185+
target_release_name="twilight-1"
186+
fi
125187

126188
if [ "$os" = "darwin" ]; then
127189
download_url="https://github.com/zen-browser/desktop/releases/download/$target_release_name/zen.macos-universal.dmg"
@@ -139,13 +201,59 @@ update_version() {
139201
entry_name="$version_name"
140202

141203
if [ "$version_name" = "twilight" ]; then
142-
jq ".variants[\"twilight\"][\"$arch-$os\"] = {\"version\":\"$semver\",\"sha1\":\"$remote_sha1\",\"url\":\"$download_url\",\"sha256\":\"$sha256\"} | .variants[\"twilight-official\"][\"$arch-$os\"] = {\"version\":\"$semver\",\"sha1\":\"$remote_sha1\",\"url\":\"$download_url\",\"sha256\":\"$sha256\"}" <sources.json >sources.json.tmp
143-
mv sources.json.tmp sources.json
144-
else
145-
jq ".variants[\"$entry_name\"][\"$arch-$os\"] = {\"version\":\"$semver\",\"sha1\":\"$remote_sha1\",\"url\":\"$download_url\",\"sha256\":\"$sha256\"}" <sources.json >sources.json.tmp
146-
mv sources.json.tmp sources.json
204+
entry_name="twilight-official"
205+
semver="$twilight_version_name"
206+
207+
updated_at_epoch="$(date -d "$updated_at" +%s)"
208+
209+
release_name="$semver-$updated_at_epoch"
210+
release_title="$semver#$updated_at_epoch"
211+
212+
flake_repo_location="0xc000022070/zen-browser-flake"
213+
214+
if ! gh release list | grep "$release_title" >/dev/null; then
215+
echo "Creating $release_name release..."
216+
217+
# Users with push access to the repository can create a release.
218+
gh release --repo="$flake_repo_location" \
219+
create "$release_name" --title="$release_title" \
220+
--notes "Artifacts from https://github.com/zen-browser/desktop/releases/tag/twilight [;"
221+
else
222+
echo "Release $release_name already exists, skipping creation..."
223+
fi
224+
225+
get_twilight_release_artifact_meta_from_zen_repo "$arch" "$os" |
226+
while read -r line; do
227+
artifact_id=$(echo "$line" | cut -d' ' -f1)
228+
artifact_name=$(echo "$line" | cut -d' ' -f2)
229+
230+
if [ "$os" = "darwin" ]; then
231+
self_download_url="https://github.com/0xc000022070/zen-browser-flake/releases/download/$release_name/zen.macos-universal.dmg"
232+
else
233+
self_download_url="https://github.com/0xc000022070/zen-browser-flake/releases/download/$release_name/zen.linux-$arch.tar.xz"
234+
fi
235+
236+
if ! gh release --repo="$flake_repo_location" view "$release_name" | grep "$artifact_name" >/dev/null; then
237+
echo "[downloading] An artifact $artifact_name doesn't exists in $release_name"
238+
239+
download_artifact_from_zen_repo "$artifact_id" "/tmp/$artifact_name"
240+
241+
gh release --repo="$flake_repo_location" \
242+
upload "$release_name" "/tmp/$artifact_name"
243+
244+
echo "[uploaded] The artifact is available @ following link: $self_download_url"
245+
else
246+
echo "[skipping] An artifact $artifact_name already exists in $release_name @ following link: $self_download_url"
247+
fi
248+
249+
jq ".variants[\"twilight\"][\"$arch-$os\"] = {\"version\":\"$semver\",\"sha1\":\"$remote_sha1\",\"url\":\"$self_download_url\",\"sha256\":\"$sha256\"}" <sources.json >sources.json.tmp
250+
mv sources.json.tmp sources.json
251+
done
147252
fi
148253

254+
jq ".variants[\"$entry_name\"][\"$arch-$os\"] = {\"version\":\"$semver\",\"sha1\":\"$remote_sha1\",\"url\":\"$download_url\",\"sha256\":\"$sha256\"}" <sources.json >sources.json.tmp
255+
mv sources.json.tmp sources.json
256+
149257
echo "$version_name was updated to $semver"
150258

151259
if ! $ci; then
@@ -164,8 +272,11 @@ update_version() {
164272

165273
if [ "$version_name" = "twilight" ]; then
166274
if [ "$commit_twilight_targets" = "" ]; then
275+
updated_at="$remote"
276+
updated_at_epoch="$(date -d "$updated_at" +%s)"
277+
167278
commit_twilight_targets="$arch"
168-
commit_twilight_version="$semver"
279+
commit_twilight_version="$twilight_version_name#$updated_at_epoch"
169280
elif ! echo "$commit_twilight_targets" | grep -q "$arch"; then
170281
commit_twilight_targets="$commit_twilight_targets && $arch"
171282
fi
@@ -178,19 +289,24 @@ main() {
178289
update_version "beta" "x86_64" "linux"
179290
update_version "beta" "aarch64" "linux"
180291
update_version "beta" "aarch64" "darwin"
181-
182-
if [ "$twilight_tag" != "null" ] && [ -n "$twilight_tag" ]; then
183-
update_version "twilight" "x86_64" "linux"
184-
update_version "twilight" "aarch64" "linux"
185-
update_version "twilight" "aarch64" "darwin"
186-
fi
292+
update_version "twilight" "x86_64" "linux"
293+
update_version "twilight" "aarch64" "linux"
294+
update_version "twilight" "aarch64" "darwin"
187295

188296
if $only_check && $ci; then
189297
echo "should_update=false" >>"$GITHUB_OUTPUT"
190298
fi
191299

192-
# touch output.txt && GITHUB_OUTPUT=output.txt .github/update.sh --ci
300+
# Check if there are changes
193301
if ! git diff --exit-code >/dev/null; then
302+
# Update twilight metadata
303+
if [ "$commit_twilight_targets" != "" ]; then
304+
updated_at=$(get_updated_at_of_twilight_artifact_from_zen_repo)
305+
jq ".metadata_for.twilight.last_updated_at = \"$updated_at\"" sources.json >sources.json.tmp
306+
mv sources.json.tmp sources.json
307+
fi
308+
309+
# Prepare commit message
194310
init_message="chore(update):"
195311
message="$init_message"
196312

hm-module/default.nix

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,10 @@ in {
104104
"zen.window-sync.sync-only-pinned-tabs" = true;
105105
''
106106
else null;
107-
108-
twilightOfficialMigrationWarning =
109-
if name == "twilight-official"
110-
then ''
111-
[Zen Browser] The twilight-official variant is deprecated. Both twilight and twilight-official
112-
now use assets directly from the upstream repository (zen-browser/desktop).
113-
114-
Please migrate to the "twilight" home module:
115-
116-
homeManagerModules.zen-browser-flake.homeModules.twilight
117-
118-
instead of:
119-
120-
homeManagerModules.zen-browser-flake.homeModules.twilight-official
121-
''
122-
else null;
123107
in
124108
lib.filter (w: w != null) [
125109
migrationWarning
126110
essentialPinsWarning
127-
twilightOfficialMigrationWarning
128111
];
129112

130113
assertions =

sources.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,10 @@
7272
"hash": "sha256-JvXNVd0HJ2OtVQuZ3bsOOvJW5VD5TIuZD8zxP1V2Y4Q="
7373
}
7474
}
75+
},
76+
"metadata_for": {
77+
"twilight": {
78+
"last_updated_at": "2026-02-20T04:32:35Z"
79+
}
7580
}
7681
}

0 commit comments

Comments
 (0)