From a38331404079fe68dae977647a176f5632fb386f Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Wed, 23 Apr 2025 11:55:47 +0200 Subject: [PATCH] Add up-to-date check to not recompile things that have not changed --- .gitea/workflows/up-to-date.sh | 47 ++++++++++++++++++++++++++++++++++ .gitea/workflows/workflow.yml | 31 +++++++++++++++++++++- PKGBUILD | 3 ++- 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100755 .gitea/workflows/up-to-date.sh diff --git a/.gitea/workflows/up-to-date.sh b/.gitea/workflows/up-to-date.sh new file mode 100755 index 0000000..e972df0 --- /dev/null +++ b/.gitea/workflows/up-to-date.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Exit on any error +set -e + +# Source the PKGBUILD in a subshell to avoid polluting the global environment +( + source ./PKGBUILD + + # Convert pkgname to array in case it's a single string + pkgnames=("${pkgname[@]}") + + for pkg in "${pkgnames[@]}"; do + echo "Checking package: $pkg" + + if pacman -Si "$pkg" &>/dev/null; then + echo "Package '$pkg' exists in a repository." + + # Get the package build date + pkg_build_date=$(date -d "$(pacman -Si "$pkg" | grep 'Build Date' | cut -d: -f2-)" +%s) + + all_deps=("${depends[@]}" "${makedepends[@]}" "${optdepends[@]}") + + # Check each dependency + for dep in "${all_deps[@]}"; do + dep_name=$(echo "$dep" | sed 's/[<>=].*//') # Remove version constraints + echo "Querying dependency: $dep_name" + + if pacman -Si "$dep_name" &>/dev/null; then + dep_build_date=$(date -d "$(pacman -Si "$dep_name" | grep 'Build Date' | cut -d: -f2-)" +%s) + if (( dep_build_date >= pkg_build_date )); then + echo "Dependency '$dep_name' has newer or equal build date than '$pkg'." + exit 1 + fi + else + echo "Dependency '$dep_name' not found in repositories. Skipping." + fi + done + + echo "All dependencies are older than package '$pkg'." + exit 0 + else + echo "Package '$pkg' does NOT exist in any repository." + exit 1 + fi + done +) diff --git a/.gitea/workflows/workflow.yml b/.gitea/workflows/workflow.yml index ab4254c..55a5c67 100644 --- a/.gitea/workflows/workflow.yml +++ b/.gitea/workflows/workflow.yml @@ -37,12 +37,37 @@ jobs: run: | curl https://idlesleep.wolproxy.seeseepuff.be/status + check: + name: Check if rebuild is necessary + runs-on: ubuntu-amd64 + needs: wake + outputs: + up-to-date: ${{ steps.up-to-date.outputs.up-to-date }} + container: + image: gitea.seeseepuff.be/archlinux/archlinux:latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Ensure image is up-to-date + run: | + sudo pacman -Sy --noconfirm + + - name: Check if rebuild is necessary + id: up-to-date + run: | + set +e + .gitea/workflows/up-to-date.sh + echo "exit_code=$?" >> "$GITHUB_OUTPUT" + set -e + build: name: Build and Push runs-on: ubuntu-amd64 - needs: wake + needs: check container: image: gitea.seeseepuff.be/archlinux/archlinux:latest + if: needs.check.outputs.up-to-date == '1' steps: - name: Checkout code uses: actions/checkout@v2 @@ -50,6 +75,10 @@ jobs: - name: Ensure image is up-to-date run: | sudo pacman -Syu --noconfirm + + - name: Check if rebuild is necessary + run: | + .gitea/workflows/up-to-date.sh - name: Build package run: | diff --git a/PKGBUILD b/PKGBUILD index 492e52c..d251215 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -15,7 +15,8 @@ optdepends=( 'sudo: privilege elevation' 'doas: privilege elevation' ) -makedepends=('go>=1.21') +makedepends=('go>=1.21' + 'helloworld') source=("${pkgname}-${pkgver}.tar.gz::https://github.com/Jguer/yay/archive/v${pkgver}.tar.gz") sha256sums=('f3f4af5d84f75abc3ea726f192568bdf570e2632b4b3c214effa4bba406ad293')