feat: added script to automatically update with github actions

Co-authored-by: omarcresp <crespomerchano@gmail.com>
This commit is contained in:
Luis Quiñones
2024-10-11 22:11:08 -06:00
parent d1345f6c86
commit 1fac4fb086
4 changed files with 79 additions and 8 deletions

10
.github/new-version.sh vendored Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
upstream=$(curl -s https://api.github.com/repos/zen-browser/desktop/releases/latest | jq -r '.tag_name')
local=$(grep -oP 'version = "\K[^"]+' flake.nix)
if [ "$upstream" != "$local" ]; then
echo "new_version=true" >>"$GITHUB_OUTPUT"
fi
echo "$upstream"

23
.github/update-zen-browser.bash vendored Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
script_dir="$(dirname -- "$0")"
upstream=$("$script_dir/new-version.sh" | cat -)
echo "Updating to $upstream"
base_url="https://github.com/zen-browser/desktop/releases/download/$upstream"
# Modify with sed the nix file
sed -i "s/version = \".*\"/version = \"$upstream\"/" ./flake.nix
# Update the hash specific.sha256
specific=$(nix-prefetch-url --type sha256 --unpack "$base_url/zen.linux-specific.tar.bz2")
sed -i "s/specific.sha256 = \".*\"/specific.sha256 = \"$specific\"/" ./flake.nix
# Update the hash generic.sha256
generic=$(nix-prefetch-url --type sha256 --unpack "$base_url/zen.linux-generic.tar.bz2")
sed -i "s/generic.sha256 = \".*\"/generic.sha256 = \"$generic\"/" ./flake.nix
nix flake update
nix build

41
.github/workflows/zen-update.yml vendored Normal file
View File

@@ -0,0 +1,41 @@
name: Update Zen Browser
on:
workflow_dispatch:
schedule:
- cron: "0 * * * *"
jobs:
update-zen-browser:
name: Update Zen Browser
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check new version
id: new-version
run: |
.github/new-version.sh
- name: Install Nix
if: steps.new-version.outputs.new_version == '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'
uses: DeterminateSystems/magic-nix-cache-action@main
- name: Update hashes and test build
if: steps.new-version.outputs.new_version == 'true'
run: |
.github/update-zen-browser.bash
- name: Commit changes
if: steps.new-version.outputs.new_version == 'true'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "GitHub Action automated Zen update"
file_pattern: "*"

View File

@@ -12,14 +12,11 @@
system = "x86_64-linux";
version = "1.0.1-a.8";
downloadUrl = {
"specific" = {
url = "https://github.com/zen-browser/desktop/releases/download/${version}/zen.linux-specific.tar.bz2";
sha256 = "sha256:0pxwfxvvf3rp5cnil47578dgpyb0a42nnjpb7v3ylddfdlvr2msm";
};
"generic" = {
url = "https://github.com/zen-browser/desktop/releases/download/${version}/zen.linux-generic.tar.bz2";
sha256 = "sha256:0g3pkdyq06651v2rxjssqwn79j3phghf0fxpq9r0vhhsqdw2r62a";
};
specific.url = "https://github.com/zen-browser/desktop/releases/download/${version}/zen.linux-specific.tar.bz2";
specific.sha256 = "sha256:0pxwfxvvf3rp5cnil47578dgpyb0a42nnjpb7v3ylddfdlvr2msm";
generic.url = "https://github.com/zen-browser/desktop/releases/download/${version}/zen.linux-generic.tar.bz2";
generic.sha256 = "0g3pkdyq06651v2rxjssqwn79j3phghf0fxpq9r0vhhsqdw2r62a";
};
pkgs = import nixpkgs {