From 5ca7b0ed795814a7748cfd197de18619c57d8470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Qui=C3=B1ones?= Date: Tue, 31 Dec 2024 13:43:46 -0500 Subject: [PATCH 1/7] feat: using using json file to store package metadata --- flake.nix | 30 ++++++++---------------------- sources.json | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 sources.json diff --git a/flake.nix b/flake.nix index 8097afd..ed7d10f 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,7 @@ { description = "Zen Browser"; - inputs = {nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";}; + inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; outputs = { self, @@ -9,24 +9,10 @@ }: let system = "x86_64-linux"; - prepareUrl = version: arch: "https://github.com/zen-browser/desktop/releases/download/${version}/zen.linux-${arch}.tar.bz2"; - - beta_version = "1.0.2-b.5"; - beta_hash = "1xp0z86l7z661cwckgr623gwwjsy3h66900xqjq6dvgx5a3njbxi"; - - beta = { - name = "beta"; - url = prepareUrl beta_version "x86_64"; - sha256 = beta_hash; - version = beta_version; - }; - - twilight = { - name = "twilight"; - url = prepareUrl "twilight" "x86_64"; - sha256 = "0yhlkyj87fylmjr8zfqv73ljx99wry8j07r19bl88078pll4ifn2"; - version = "twilight"; - }; + getSource = let + sources = builtins.fromJSON (builtins.readFile ./sources.json); + in + name: sources.${name}.${system}; pkgs = import nixpkgs {inherit system;}; @@ -155,9 +141,9 @@ }; in { packages."${system}" = { - default = mkZen beta; - beta = mkZen beta; - twilight = mkZen twilight; + default = mkZen (getSource "beta"); + beta = mkZen (getSource "beta"); + twilight = mkZen (getSource "twilight"); }; }; } diff --git a/sources.json b/sources.json new file mode 100644 index 0000000..ece96c3 --- /dev/null +++ b/sources.json @@ -0,0 +1,18 @@ +{ + "beta": { + "x86_64-linux": { + "name": "beta", + "version": "1.0.2-b.5", + "url": "https://github.com/zen-browser/desktop/releases/download/1.0.2-b.5/zen.linux-x86_64.tar.bz2", + "sha256": "1xp0z86l7z661cwckgr623gwwjsy3h66900xqjq6dvgx5a3njbxi" + } + }, + "twilight": { + "x86_64-linux": { + "name": "twilight", + "version": "twilight", + "url": "https://github.com/zen-browser/desktop/releases/download/twilight/zen.linux-x86_64.tar.bz2", + "sha256": "0yhlkyj87fylmjr8zfqv73ljx99wry8j07r19bl88078pll4ifn2" + } + } +} From 974934b72233695d95fc5708cff728f20d851dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Qui=C3=B1ones?= Date: Tue, 31 Dec 2024 14:57:20 -0500 Subject: [PATCH 2/7] feat: new script to automatically update beta and twilight versions --- new.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 new.sh diff --git a/new.sh b/new.sh new file mode 100644 index 0000000..5853627 --- /dev/null +++ b/new.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +repo_tags=$(curl 'https://api.github.com/repos/zen-browser/desktop/tags' -s) + +twilight_tag=$(echo "$repo_tags" | jq -r '.[]|select(.name|test("twilight"))') +beta_tag=$(echo "$repo_tags" | jq -r '(map(select(.name | test("-b.")))) | first') + +try_to_update() { + name=$1 + arch=$2 + target_tag_meta=$3 + + meta=$(jq ".[\"$name\"][\"$arch-linux\"]" sources.json.tmp + mv sources.json.tmp sources.json + + echo "$name was updated to $version" + fi +} + +set -e + +try_to_update "beta" "x86_64" "$beta_tag" +try_to_update "beta" "aarch64" "$beta_tag" +try_to_update "twilight" "x86_64" "$twilight_tag" +try_to_update "twilight" "aarch64" "$twilight_tag" From f7f3e0aa62c465828447a84c2ade59590fd45264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Qui=C3=B1ones?= Date: Tue, 31 Dec 2024 14:58:12 -0500 Subject: [PATCH 3/7] feat: support for aarch64 architecture --- sources.json | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/sources.json b/sources.json index ece96c3..de26173 100644 --- a/sources.json +++ b/sources.json @@ -1,18 +1,34 @@ { - "beta": { - "x86_64-linux": { - "name": "beta", - "version": "1.0.2-b.5", - "url": "https://github.com/zen-browser/desktop/releases/download/1.0.2-b.5/zen.linux-x86_64.tar.bz2", - "sha256": "1xp0z86l7z661cwckgr623gwwjsy3h66900xqjq6dvgx5a3njbxi" - } - }, - "twilight": { - "x86_64-linux": { - "name": "twilight", - "version": "twilight", - "url": "https://github.com/zen-browser/desktop/releases/download/twilight/zen.linux-x86_64.tar.bz2", - "sha256": "0yhlkyj87fylmjr8zfqv73ljx99wry8j07r19bl88078pll4ifn2" - } - } + "beta": { + "x86_64-linux": { + "name": "beta", + "version": "1.0.2-b.5", + "sha1": "20c16af6d399fc325572e9beb404c160a1130aa8", + "url": "https://github.com/zen-browser/desktop/releases/download/1.0.2-b.5/zen.linux-x86_64.tar.bz2", + "sha256": "1xp0z86l7z661cwckgr623gwwjsy3h66900xqjq6dvgx5a3njbxi" + }, + "aarch64-linux": { + "name": "beta", + "version": "1.0.2-b.5", + "sha1": "20c16af6d399fc325572e9beb404c160a1130aa8", + "url": "https://github.com/zen-browser/desktop/releases/download/1.0.2-b.5/zen.linux-aarch64.tar.bz2", + "sha256": "sha256-NwIYylGal2QoWhWKtMhMkAAJQ6iNHfQOBZaxTXgvxAk=" + } + }, + "twilight": { + "x86_64-linux": { + "name": "twilight", + "version": "twilight", + "sha1": "c88dbd3f02016b568e4de61b7c20ade45b2a16d1", + "url": "https://github.com/zen-browser/desktop/releases/download/twilight/zen.linux-x86_64.tar.bz2", + "sha256": "0yhlkyj87fylmjr8zfqv73ljx99wry8j07r19bl88078pll4ifn2" + }, + "aarch64-linux": { + "name": "twilight", + "version": "twilight", + "sha1": "c88dbd3f02016b568e4de61b7c20ade45b2a16d1", + "url": "https://github.com/zen-browser/desktop/releases/download/twilight/zen.linux-aarch64.tar.bz2", + "sha256": "sha256-3u6nxVsHXNvDywHAwJWlOEAWxHV/FzWp6kPTmS5HlsQ=" + } + } } From 49b0ac38c4484122a304d6003b7046102a93ace4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Qui=C3=B1ones?= Date: Tue, 31 Dec 2024 15:00:19 -0500 Subject: [PATCH 4/7] fix(flake): function to mkZen package accepts extra arguments --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index ed7d10f..ceb19df 100644 --- a/flake.nix +++ b/flake.nix @@ -21,6 +21,7 @@ url, sha256, version, + ... }: let runtimeLibs = with pkgs; [ From 07a074f2f791475e7fbdfceb4152e1fba3ed33df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Qui=C3=B1ones?= Date: Tue, 31 Dec 2024 15:09:28 -0500 Subject: [PATCH 5/7] ci: partial integration with new script to fetch new versions --- .github/check-update.sh | 33 ++++++++++++++++++++++++ .github/new-version.sh | 18 ------------- .github/update-zen-browser.bash | 43 -------------------------------- new.sh => .github/update.sh | 2 +- .github/workflows/zen-update.yml | 18 ++++++------- 5 files changed, 43 insertions(+), 71 deletions(-) create mode 100755 .github/check-update.sh delete mode 100755 .github/new-version.sh delete mode 100755 .github/update-zen-browser.bash rename new.sh => .github/update.sh (95%) mode change 100644 => 100755 diff --git a/.github/check-update.sh b/.github/check-update.sh new file mode 100755 index 0000000..065edb4 --- /dev/null +++ b/.github/check-update.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +repo_tags=$(curl 'https://api.github.com/repos/zen-browser/desktop/tags' -s) + +twilight_tag=$(echo "$repo_tags" | jq -r '.[]|select(.name|test("twilight"))') +beta_tag=$(echo "$repo_tags" | jq -r '(map(select(.name | test("-b.")))) | first') + +check_update() { + name=$1 + arch=$2 + target_tag_meta=$3 + + meta=$(jq ".[\"$name\"][\"$arch-linux\"]" >"$GITHUB_OUTPUT" + return + fi +} + +set -e + +check_update "beta" "x86_64" "$beta_tag" +check_update "beta" "aarch64" "$beta_tag" +check_update "twilight" "x86_64" "$twilight_tag" +check_update "twilight" "aarch64" "$twilight_tag" diff --git a/.github/new-version.sh b/.github/new-version.sh deleted file mode 100755 index 73edc65..0000000 --- a/.github/new-version.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -echo "Fetching upstream version from GitHub API..." >&2 -upstream_data=$(curl -s https://api.github.com/repos/zen-browser/desktop/releases/latest) -echo "Upstream data: $upstream_data" >&2 - -upstream=$(echo "$upstream_data" | tr -d '\000-\037\177' | jq -r '.tag_name') -echo "Upstream version is: $upstream" >&2 - -local=$(grep -oP 'beta_version = "\K[^"]+' flake.nix) -echo "Current version (local) is: $local" >&2 # first! - -if [ "$upstream" != "$local" ]; then - echo "new_version=true" >>"$GITHUB_OUTPUT" - echo "upstream=$upstream" >>"$GITHUB_OUTPUT" -fi - -echo "$upstream" diff --git a/.github/update-zen-browser.bash b/.github/update-zen-browser.bash deleted file mode 100755 index 80d85ca..0000000 --- a/.github/update-zen-browser.bash +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash - -script_dir="$(dirname -- "$0")" - -upstream="null" - -max_attempts=10 -attempts=1 - -while [ "$upstream" == "null" ]; do - upstream=$("$script_dir/new-version.sh") - - if [ "$upstream" != "null" ]; then - break - elif [ $attempts -ge $max_attempts ]; then - echo "Unable to determine new upstream version" - exit 1 - fi - - echo "[attempt #${attempts}] Unable to determine new upstream version, retrying in 5 seconds..." - attempts=$((attempts + 1)) - sleep 5 -done - -upstream=$("$script_dir/new-version.sh" | cat -) -if [ "$upstream" == "null" ]; then - echo "Unable to determine new upstream version" - return 1 -fi - -echo "Updating to $upstream" - -base_url="https://github.com/zen-browser/desktop/releases/download/$upstream" - -# Modify with sed the nix file -sed -i "s/beta_version = \".*\"/beta_version = \"$upstream\"/" ./flake.nix - -# Update the hash sha256 -hash=$(nix-prefetch-url --type sha256 --unpack "$base_url/zen.linux-x86_64.tar.bz2") -sed -i "s/beta_hash = \".*\"/beta_hash = \"$hash\"/" ./flake.nix - -nix flake update -nix build .#beta diff --git a/new.sh b/.github/update.sh old mode 100644 new mode 100755 similarity index 95% rename from new.sh rename to .github/update.sh index 5853627..c2dd0e1 --- a/new.sh +++ b/.github/update.sh @@ -31,7 +31,7 @@ try_to_update() { jq ".[\"$name\"][\"$arch-linux\"] = {\"name\":\"$name\",\"version\":\"$version\",\"sha1\":\"$remote_sha1\",\"url\":\"$download_url\",\"sha256\":\"$sha256\"}" sources.json.tmp mv sources.json.tmp sources.json - echo "$name was updated to $version" + echo "$name was updated to $version" # missing nix build! fi } diff --git a/.github/workflows/zen-update.yml b/.github/workflows/zen-update.yml index 9e0aac7..c7985e1 100644 --- a/.github/workflows/zen-update.yml +++ b/.github/workflows/zen-update.yml @@ -13,28 +13,28 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Check new version - id: new-version + - name: Check if update is needed + id: check run: | - .github/new-version.sh + .github/check-update.sh - name: Install Nix - if: steps.new-version.outputs.new_version == 'true' + if: steps.check.outputs.should_update == 'true' uses: cachix/install-nix-action@v27 with: nix_path: nixpkgs=channel:nixpkgs-unstable - name: Setup Nix Magic Cache - if: steps.new-version.outputs.new_version == 'true' + if: steps.check.outputs.should_update == 'true' uses: DeterminateSystems/magic-nix-cache-action@main - - name: Update hashes and test build - if: steps.new-version.outputs.new_version == 'true' + - name: Update versions + if: steps.check.outputs.should_update == 'true' run: | - .github/update-zen-browser.bash + .github/update.sh - name: Commit changes - if: steps.new-version.outputs.new_version == 'true' + if: steps.check.outputs.should_update == 'true' uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: "Update Zen Browser to v${{ steps.new-version.outputs.upstream }}" From 3d26db3a166d5607220b46aeb2c7deadd0b17e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Qui=C3=B1ones?= Date: Tue, 31 Dec 2024 15:44:22 -0500 Subject: [PATCH 6/7] ci: script to update everything can produce good commit messages --- .github/check-update.sh | 33 ---------------- .github/update.sh | 68 ++++++++++++++++++++++++++++++++ .github/workflows/zen-update.yml | 7 ++-- 3 files changed, 72 insertions(+), 36 deletions(-) delete mode 100755 .github/check-update.sh diff --git a/.github/check-update.sh b/.github/check-update.sh deleted file mode 100755 index 065edb4..0000000 --- a/.github/check-update.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -repo_tags=$(curl 'https://api.github.com/repos/zen-browser/desktop/tags' -s) - -twilight_tag=$(echo "$repo_tags" | jq -r '.[]|select(.name|test("twilight"))') -beta_tag=$(echo "$repo_tags" | jq -r '(map(select(.name | test("-b.")))) | first') - -check_update() { - name=$1 - arch=$2 - target_tag_meta=$3 - - meta=$(jq ".[\"$name\"][\"$arch-linux\"]" >"$GITHUB_OUTPUT" - return - fi -} - -set -e - -check_update "beta" "x86_64" "$beta_tag" -check_update "beta" "aarch64" "$beta_tag" -check_update "twilight" "x86_64" "$twilight_tag" -check_update "twilight" "aarch64" "$twilight_tag" diff --git a/.github/update.sh b/.github/update.sh index c2dd0e1..03316a3 100755 --- a/.github/update.sh +++ b/.github/update.sh @@ -1,10 +1,25 @@ #!/bin/sh +ci=false +if echo "$@" | grep -qoE '(--ci)'; then + ci=true +fi + +only_check=false +if echo "$@" | grep -qoE '(--only-check)'; then + only_check=true +fi + repo_tags=$(curl 'https://api.github.com/repos/zen-browser/desktop/tags' -s) twilight_tag=$(echo "$repo_tags" | jq -r '.[]|select(.name|test("twilight"))') beta_tag=$(echo "$repo_tags" | jq -r '(map(select(.name | test("-b.")))) | first') +commit_beta_targets="" +commit_beta_version="" +commit_twilight_targets="" +commit_twilight_version="" + try_to_update() { name=$1 arch=$2 @@ -22,6 +37,11 @@ try_to_update() { else echo "Local $name version is outdated" + if $only_check; then + echo "should_update=true" >>"$GITHUB_OUTPUT" + exit 0 + fi + version=$(echo "$target_tag_meta" | jq -r '.name') download_url="https://github.com/zen-browser/desktop/releases/download/$version/zen.linux-$arch.tar.bz2" @@ -32,6 +52,30 @@ try_to_update() { mv sources.json.tmp sources.json echo "$name was updated to $version" # missing nix build! + + if ! $ci; then + return + fi + + if [ "$name" = "beta" ]; then + if [ "$commit_beta_targets" = "" ]; then + commit_beta_targets="$arch" + commit_beta_version="$version" + else + commit_beta_targets="$commit_beta_targets && $arch" + fi + fi + + if [ "$name" = "twilight" ]; then + if [ "$commit_twilight_targets" = "" ]; then + commit_twilight_targets="$arch" + commit_twilight_version="latest" + else + commit_twilight_targets="$commit_twilight_targets && $arch" + fi + + fi + fi } @@ -41,3 +85,27 @@ try_to_update "beta" "x86_64" "$beta_tag" try_to_update "beta" "aarch64" "$beta_tag" try_to_update "twilight" "x86_64" "$twilight_tag" try_to_update "twilight" "aarch64" "$twilight_tag" + +if $only_check && $ci; then + echo "should_update=false" >>"$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" + 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 diff --git a/.github/workflows/zen-update.yml b/.github/workflows/zen-update.yml index c7985e1..475d7fb 100644 --- a/.github/workflows/zen-update.yml +++ b/.github/workflows/zen-update.yml @@ -16,7 +16,7 @@ jobs: - name: Check if update is needed id: check run: | - .github/check-update.sh + .github/update.sh --ci --only-check - name: Install Nix if: steps.check.outputs.should_update == 'true' @@ -29,13 +29,14 @@ jobs: uses: DeterminateSystems/magic-nix-cache-action@main - name: Update versions + id: update if: steps.check.outputs.should_update == 'true' run: | - .github/update.sh + .github/update.sh --ci - name: Commit changes if: steps.check.outputs.should_update == 'true' uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "Update Zen Browser to v${{ steps.new-version.outputs.upstream }}" + commit_message: "${{ steps.update.outputs.commit_message }}" file_pattern: "*" From 1894eec539ca6ff03ed878552747894328303be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Qui=C3=B1ones?= Date: Tue, 31 Dec 2024 15:51:25 -0500 Subject: [PATCH 7/7] feat(flake): support for aarch64-linux --- flake.nix | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/flake.nix b/flake.nix index ceb19df..98af0f1 100644 --- a/flake.nix +++ b/flake.nix @@ -7,22 +7,10 @@ self, nixpkgs, }: let - system = "x86_64-linux"; + mkZen = name: system: let + pkgs = import nixpkgs {inherit system;}; + variant = (builtins.fromJSON (builtins.readFile ./sources.json)).${name}.${system}; - getSource = let - sources = builtins.fromJSON (builtins.readFile ./sources.json); - in - name: sources.${name}.${system}; - - pkgs = import nixpkgs {inherit system;}; - - mkZen = { - name, - url, - sha256, - version, - ... - }: let runtimeLibs = with pkgs; [ libGL @@ -82,10 +70,10 @@ }); in pkgs.stdenv.mkDerivation { - inherit version; + inherit (variant) version; pname = "zen-browser"; - src = builtins.fetchTarball {inherit url sha256;}; + src = builtins.fetchTarball {inherit (variant) url sha256;}; desktopSrc = ./.; phases = ["installPhase" "fixupPhase"]; @@ -93,12 +81,12 @@ nativeBuildInputs = [pkgs.makeWrapper pkgs.copyDesktopItems pkgs.wrapGAppsHook]; installPhase = '' - mkdir -p $out/{bin,opt/zen,lib/zen-${version}/distribution} && cp -r $src/* $out/opt/zen + mkdir -p $out/{bin,opt/zen,lib/zen-${variant.version}/distribution} && cp -r $src/* $out/opt/zen ln -s $out/opt/zen/zen $out/bin/zen - ln -s ${policiesJson} "$out/lib/zen-${version}/distribution/policies.json" - ln -s $out/bin/zen $out/bin/zen-${name} + ln -s ${policiesJson} "$out/lib/zen-${variant.version}/distribution/policies.json" + ln -s $out/bin/zen $out/bin/zen-${variant.name} - install -D $desktopSrc/zen-${name}.desktop $out/share/applications/zen.desktop + install -D $desktopSrc/zen-${variant.name}.desktop $out/share/applications/zen.desktop install -D $src/browser/chrome/icons/default/default16.png $out/share/icons/hicolor/16x16/apps/zen.png install -D $src/browser/chrome/icons/default/default32.png $out/share/icons/hicolor/32x32/apps/zen.png @@ -140,11 +128,18 @@ meta.mainProgram = "zen"; }; + + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + ]; + + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; in { - packages."${system}" = { - default = mkZen (getSource "beta"); - beta = mkZen (getSource "beta"); - twilight = mkZen (getSource "twilight"); - }; + packages = forAllSystems (system: { + default = mkZen "beta" system; + beta = mkZen "beta" system; + twilight = mkZen "twilight" system; + }); }; }