From 9a6a8b54fdac8bf1a761624b50ed66d9982403c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Qui=C3=B1ones?= Date: Sat, 15 Mar 2025 01:01:56 -0500 Subject: [PATCH] ci(update): using artifact timestamp to detect if there is any update in twilight release artifacts This commit might resolve: https://github.com/0xc000022070/zen-browser-flake/issues/26 I should say thanks to Silenc3IsGold3n because the idea of using the updated_at field belongs to him/her. --- .github/update.sh | 88 ++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/.github/update.sh b/.github/update.sh index eb4795a..a5196ac 100755 --- a/.github/update.sh +++ b/.github/update.sh @@ -23,7 +23,7 @@ get_twilight_tag_full_meta() { twilight_tag=$(get_twilight_tag_full_meta) beta_tag=$(get_beta_tag_short_meta) -get_twilight_release_from_zen_repo() { +get_twilight_release_artifact_meta_from_zen_repo() { arch=$1 echo "$twilight_tag" | jq -r --arg arch "$arch" \ @@ -41,6 +41,10 @@ download_artifact_from_zen_repo() { "https://api.github.com/repos/zen-browser/desktop/releases/assets/$artifact_id" >"$file_path" } +get_updated_at_of_twilight_artifact_from_zen_repo() { + gh api repos/zen-browser/desktop/releases/tags/twilight | jq -r '.assets | (map(select(.name | test("zen.linux-(x86_64|aarch64).tar.xz")))) | first | .updated_at' +} + get_twilight_version_name() { echo "$twilight_tag" | jq -r '.name' | grep -oE '([0-9\.])+(t|-t.[0-9]+)' } @@ -103,7 +107,7 @@ commit_beta_version="" commit_twilight_targets="" commit_twilight_version="" -try_to_update() { +update_version() { # twilight or beta version_name=$1 # "x86_64" or "aarch64" @@ -112,12 +116,21 @@ try_to_update() { meta=$(jq ".[\"$version_name\"][\"$arch-linux\"]" >"$GITHUB_OUTPUT" -fi - -# Check if there are changes -if ! git diff --exit-code >/dev/null; then - init_message="Update Zen Browser" - message="$init_message" - - if [ "$commit_beta_targets" != "" ]; then - message="$message beta @ $commit_beta_targets to $commit_beta_version" + if $only_check && $ci; then + echo "should_update=false" >>"$GITHUB_OUTPUT" fi - if [ "$commit_twilight_targets" != "" ]; then - if [ "$message" != "$init_message" ]; then - message="$message and" + # Check if there are changes + if ! git diff --exit-code >/dev/null; then + # Update twilight metadata + if [ "$commit_twilight_targets" != "" ]; then + updated_at=$(get_updated_at_of_twilight_artifact_from_zen_repo) + jq ".[\"twilight_metadata\"][\"updated_at\"] = \"$updated_at"\" sources.json >sources.json.tmp + mv sources.json.tmp sources.json fi - message="$message twilight @ $commit_twilight_targets to $commit_twilight_version" - fi + # Prepare commit message + init_message="Update Zen Browser" + message="$init_message" - echo "commit_message=$message" >>"$GITHUB_OUTPUT" -fi + if [ "$commit_beta_targets" != "" ]; then + message="$message beta @ $commit_beta_targets to $commit_beta_version" + fi + + if [ "$commit_twilight_targets" != "" ]; then + if [ "$message" != "$init_message" ]; then + message="$message and" + fi + + message="$message twilight @ $commit_twilight_targets to $commit_twilight_version" + fi + + echo "commit_message=$message" >>"$GITHUB_OUTPUT" + fi +} + +main