From 09041e2ec8106390004fd2aefbbdaafe6d6aa850 Mon Sep 17 00:00:00 2001 From: LavaDesu Date: Mon, 17 Mar 2025 23:16:12 +1100 Subject: [PATCH] workflow: update, and add update script --- .github/workflows/autoupdate.yml | 48 ++++++++++++++++++++++++++++++++ .github/workflows/cachix.yml | 19 +++++-------- update.sh | 32 +++++++++++++++++++++ 3 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/autoupdate.yml create mode 100755 update.sh diff --git a/.github/workflows/autoupdate.yml b/.github/workflows/autoupdate.yml new file mode 100644 index 0000000..67158bd --- /dev/null +++ b/.github/workflows/autoupdate.yml @@ -0,0 +1,48 @@ +name: Auto update +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * *" + +jobs: + update: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check for updates + id: check + run: | + local=$(cat flake.lock | jq ".nodes.nixpkgs.locked.rev") + remote=$(curl "https://api.github.com/repos/NixOS/nixpkgs/branches/nixos-unstable/commits?per_page=1" | jq ".commit.sha") + if [[ $local == $remote ]]; then + echo "skip=1" >> "$GITHUB_OUTPUT" + else + echo "skip=0" >> "$GITHUB_OUTPUT" + branch=$(TZ='Australia/Melbourne' date '+staging_auto/%Y%m%d') + echo "branch_name=${branch}" >> "$GITHUB_OUTPUT" + fi + + - name: Install nix + if: steps.check.outputs.skip == 0 + uses: cachix/install-nix-action@v31 + + - name: Configure git + if: steps.check.outputs.skip == 0 + run: | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + - name: Update + if: steps.check.outputs.skip == 0 + run: ./update.sh + + - name: Push + if: steps.check.outputs.skip == 0 + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ steps.check.outputs.branch_name }} diff --git a/.github/workflows/cachix.yml b/.github/workflows/cachix.yml index ed8dee2..bdc63ba 100644 --- a/.github/workflows/cachix.yml +++ b/.github/workflows/cachix.yml @@ -1,6 +1,7 @@ name: CI on: + push: workflow_dispatch: jobs: @@ -8,14 +9,11 @@ jobs: name: Check flake runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: cachix/install-nix-action@v17 - with: - install_url: https://github.com/numtide/nix-unstable-installer/releases/download/nix-2.12.0pre20220930_89ca75c/install - extra_nix_config: experimental-features = nix-command flakes - - uses: cachix/cachix-action@v10 + - uses: cachix/install-nix-action@v31 + - uses: cachix/cachix-action@v14 with: name: lava authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' @@ -25,14 +23,11 @@ jobs: name: Build linux-lava for x86_64-linux runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: cachix/install-nix-action@v17 - with: - install_url: https://github.com/numtide/nix-unstable-installer/releases/download/nix-2.12.0pre20220930_89ca75c/install - extra_nix_config: experimental-features = nix-command flakes - - uses: cachix/cachix-action@v10 + - uses: cachix/install-nix-action@v31 + - uses: cachix/cachix-action@v14 with: name: lava authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..c9ce776 --- /dev/null +++ b/update.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env -S nix shell 'nixpkgs#git' 'nixpkgs#curl' -c sh + +update_kernel() { + previous_ver=$(cat packages/linux-lava/sources.nix | grep "version =" | sed --expression='s/[^0-9.]//g') + kernel_ver=$(curl -s https://www.kernel.org/finger_banner | grep -m1 stable | awk '{print $NF}') + + if [ "$previous_ver" = "$kernel_ver" ]; then + return + fi + + kernel_major=$(cut -d '.' -f 1 <<< "$kernel_ver") + kernel_mmver=$(cut -d '.' -f 1,2 <<< "$kernel_ver") + + hash_mm=$(nix-prefetch-url "https://cdn.kernel.org/pub/linux/kernel/v${kernel_major}.x/linux-${kernel_mmver}.tar.xz") + hash_patch=$(nix-prefetch-url "https://cdn.kernel.org/pub/linux/kernel/v${kernel_major}.x/patch-${kernel_ver}.xz") + + sed -i "/version =/c\ version = \"${kernel_ver}\";" packages/linux-lava/sources.nix + sed -i "/kernelHash =/c\ kernelHash = \"${hash_mm}\";" packages/linux-lava/sources.nix + sed -i "/kernelPatchHash =/c\ kernelPatchHash = \"${hash_patch}\";" packages/linux-lava/sources.nix + + git add packages/linux-lava/sources.nix + git commit -m "packages/linux-lava: bump to ${kernel_ver}" +} + +bump_inputs() { + nix flake update + git add flake.lock + git commit -m "flake: bump inputs" +} + +bump_inputs +update_kernel