From 47b9d0735df69adc6422dfa07b30346386edd233 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Tue, 5 Sep 2023 22:48:55 -0400 Subject: [PATCH 1/3] common/scripts/xbps-cycles.py: improve caching by storing the hash of the template in the cache, the cache can be invalidated when the template is changed. --- common/scripts/xbps-cycles.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/common/scripts/xbps-cycles.py b/common/scripts/xbps-cycles.py index 7710381eb2925..1ae8f4199a133 100755 --- a/common/scripts/xbps-cycles.py +++ b/common/scripts/xbps-cycles.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import os -import sys import glob +import hashlib import subprocess import multiprocessing @@ -11,6 +11,17 @@ import networkx as nx +def hash_template(pkg, xbpsdir): + ''' + Hashes a template with md5 for cache keying + ''' + try: + with open(os.path.join(xbpsdir, 'srcpkgs', pkg, 'template'), "rb") as tmpl: + return hashlib.file_digest(tmpl, hashlib.md5).hexdigest() + except FileNotFoundError: + return '0' + + def enum_depends(pkg, xbpsdir, cachedir): ''' Return a pair (pkg, [dependencies]), where [dependencies] is the list @@ -21,15 +32,21 @@ def enum_depends(pkg, xbpsdir, cachedir): /xbps-src show-build-deps unless /deps- file exist, in that case it is read. + To ensure the cache for a package is invalidated when its template changes, + the template is hashed and that hash is stored on the first line of the + package's cache file. If the return code of this call nonzero, a message will be printed but the package will treated as if it has no dependencies. ''' if cachedir: cachepath = os.path.join(cachedir, 'deps-' + pkg) + newhash = hash_template(pkg, xbpsdir) try: with open(cachepath) as f: - return pkg, [l.strip() for l in f] + oldhash = f.readline().strip() + if oldhash == newhash: + return pkg, [l.strip() for l in f] except FileNotFoundError: pass @@ -44,6 +61,7 @@ def enum_depends(pkg, xbpsdir, cachedir): deps = [d for d in deps.decode('utf-8').split('\n') if d] if cachedir: with open(cachepath, 'w') as f: + print(newhash, file=f) for d in deps: print(d, file=f) From e14f9abd092478223c58f2c633c758386e496b19 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Tue, 5 Sep 2023 20:10:58 -0400 Subject: [PATCH 2/3] .github/workflows/cycles.yaml: run on PRs, don't run on forks - running on forks is kinda useless and just gives people useless error messages if they sync their master branch at the wrong time - run cycle check on PRs to catch cycles before they happen. this makes the cron cycle check more of a backup/just-in-case for things that slip past the CI - speed things up by caching dependencies in github's cache functionality. this is only written by the scheduled job, not PRs. --- .github/workflows/cycles.yml | 41 +++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cycles.yml b/.github/workflows/cycles.yml index 8eaecdc70287b..7091d26abbf2d 100644 --- a/.github/workflows/cycles.yml +++ b/.github/workflows/cycles.yml @@ -3,11 +3,18 @@ name: 'Cycle Check' on: schedule: - cron: '0 18 * * *' + pull_request: + paths: + - 'srcpkgs/**' jobs: cycles: runs-on: ubuntu-latest + # run only if on the main repo or on pull requests + if: ${{ github.event_name == 'pull_request' || github.repository_owner == 'void-linux' }} permissions: + # this will only apply to scheduled runs + # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token issues: write container: image: 'ghcr.io/void-linux/void-buildroot-musl:20230904R2' @@ -24,7 +31,7 @@ jobs: # Upgrade again (in case there was a xbps update) xbps-install -yu # Install script dependencies - xbps-install -y python3-networkx github-cli + xbps-install -y python3-networkx - name: Clone and checkout uses: classabbyamp/treeless-checkout-action@v1 @@ -34,9 +41,26 @@ jobs: ln -s "$(pwd)" /hostrepo && common/travis/set_mirror.sh && common/travis/prepare.sh - - name: Find cycles and open issues + - name: Load cached dependencies + id: cache-restore + uses: actions/cache/restore@v3 + with: + key: xbps-cycles + path: /xbps-cycles + - name: Find cycles run: | - common/scripts/xbps-cycles.py | tee cycles + mkdir -p /xbps-cycles + common/scripts/xbps-cycles.py -c /xbps-cycles | tee cycles + - name: Save cached dependencies + if: ${{ github.event_name == 'schedule' }} + uses: actions/cache/save@v3 + with: + key: ${{ steps.cache-restore.outputs.cache-primary-key }} + path: /xbps-cycles + - name: Open issues + if: ${{ github.event_name == 'schedule' }} + run: | + xbps-install -y github-cli grep 'Cycle:' cycles | while read -r line; do if gh issue list -R "$GITHUB_REPOSITORY" -S "$line" | grep .; then printf "Issue on '%s' already exists.\n" "$line" @@ -46,3 +70,14 @@ jobs: done env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }} + - name: Summary + run: | + if grep -q '^Cycle:' cycles; then + echo "Build cycles found:" + rv=1 + else + echo "No cycles found:" + rv=0 + fi + cat cycles + exit $rv From c9b07bd55214c27fd0660ed2221282faa92fb9e3 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Tue, 5 Sep 2023 21:04:08 -0400 Subject: [PATCH 3/3] chezmoi: --- srcpkgs/chezmoi/template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srcpkgs/chezmoi/template b/srcpkgs/chezmoi/template index f046f669df41c..7ecf6f84aef19 100644 --- a/srcpkgs/chezmoi/template +++ b/srcpkgs/chezmoi/template @@ -1,7 +1,7 @@ # Template file for 'chezmoi' pkgname=chezmoi version=2.38.0 -revision=1 +revision=2 build_style=go go_import_path="github.com/twpayne/chezmoi/v2" go_build_tags="noembeddocs noupgrade"