diff options
author | Evils <evils.devils@protonmail.com> | 2023-09-23 20:43:36 +0200 |
---|---|---|
committer | Evils <evils.devils@protonmail.com> | 2024-01-08 07:57:24 +0100 |
commit | 3aaab6bc2a3df2e8b36fe3bdfe281638f8ba4587 (patch) | |
tree | 4554862bf043738400e2a366d14242ef6408d97e /pkgs/applications/science/electronics | |
parent | e0fe5cf69ff110439a98270a7330aee4fc536f17 (diff) |
kicad.passthru.updateScript: fix integration
accept UPDATE_NIX_PNAME output JSON handle the -small packages not sure why i thought i couldn't call it for each pname... and some cleanup
Diffstat (limited to 'pkgs/applications/science/electronics')
-rw-r--r-- | pkgs/applications/science/electronics/kicad/default.nix | 10 | ||||
-rwxr-xr-x | pkgs/applications/science/electronics/kicad/update.sh | 88 |
2 files changed, 67 insertions, 31 deletions
diff --git a/pkgs/applications/science/electronics/kicad/default.nix b/pkgs/applications/science/electronics/kicad/default.nix index b761ea82f2fb4..0eae018dc7833 100644 --- a/pkgs/applications/science/electronics/kicad/default.nix +++ b/pkgs/applications/science/electronics/kicad/default.nix @@ -267,12 +267,10 @@ stdenv.mkDerivation rec { ln -s ${base}/share/metainfo $out/share/metainfo ''; - # can't run this for each pname - # stable and unstable are in the same versions.nix - # and kicad-small reuses stable - # with "all" it updates both, run it manually if you don't want that - # and can't git commit if this could be running in parallel with other scripts - passthru.updateScript = [ ./update.sh "all" ]; + passthru.updateScript = { + command = [ ./update.sh "${pname}" ]; + supportedFeatures = [ "commit" ]; + }; meta = rec { description = (if (stable) diff --git a/pkgs/applications/science/electronics/kicad/update.sh b/pkgs/applications/science/electronics/kicad/update.sh index 69659e256ea44..a2804a5983888 100755 --- a/pkgs/applications/science/electronics/kicad/update.sh +++ b/pkgs/applications/science/electronics/kicad/update.sh @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash -p coreutils git nix curl +#!nix-shell -i bash -p coreutils git nix curl jq # shellcheck shell=bash enable=all set -e @@ -27,6 +27,15 @@ export TMPDIR=/tmp # remove items left in /nix/store? # reuse hashes of already checked revs (to avoid redownloading testing's packages3d) +# nixpkgs' update.nix passes in UPDATE_NIX_PNAME to indicate which package is being updated +# assigning a default value to that as shellcheck doesn't like the use of unassigned variables +: "${UPDATE_NIX_PNAME:=""}" +# update.nix can also parse JSON output of this script to formulate a commit +# this requires we collect the version string in the old versions.nix for the updated package +old_version="" +new_version="" + + # get the latest tag that isn't an RC or *.99 latest_tags="$(git ls-remote --tags --sort -version:refname https://gitlab.com/kicad/code/kicad.git)" # using a scratch variable to ensure command failures get caught (SC2312) @@ -49,16 +58,16 @@ prefetch="nix-prefetch-url --unpack --quiet" clean="" check_stable="" -check_unstable=1 check_testing=1 +check_unstable=1 commit="" -for arg in "$@"; do +for arg in "$@" "${UPDATE_NIX_PNAME}"; do case "${arg}" in help|-h|--help) echo "Read me!" >&2; exit 1; ;; - kicad|release|tag|stable|*small|5*|6*|7*|8*) check_stable=1; check_testing=""; check_unstable="" ;; - testing) check_testing=1; check_unstable="" ;; - master|*unstable) check_unstable=1; check_testing="" ;; + kicad|kicad-small|release|tag|stable|5*|6*|7*|8*) check_stable=1; check_testing=""; check_unstable="" ;; + *testing|kicad-testing-small) check_testing=1; check_unstable="" ;; + *unstable|*unstable-small|master|main) check_unstable=1; check_testing="" ;; latest|now|today) check_unstable=1; check_testing=1 ;; all|both|full) check_stable=1; check_testing=1; check_unstable=1 ;; clean|fix|*fuck) check_stable=1; check_testing=1; check_unstable=1; clean=1 ;; @@ -86,9 +95,10 @@ src_pre="https://gitlab.com/api/v4/projects/kicad%2Fcode%2Fkicad/repository/arch lib_pre="https://gitlab.com/api/v4/projects/kicad%2Flibraries%2Fkicad-" lib_mid="/repository/archive.tar.gz?sha=" +# number of items updated count=0 -printf "Latest tag is\t%s\n" "${latest_tag}" >&2 +printf "Latest tag is %s\n" "${latest_tag}" >&2 if [[ ! -f ${file} ]]; then echo "No existing file, generating from scratch" >&2 @@ -105,17 +115,6 @@ printf "{\n" for version in "${all_versions[@]}"; do - if [[ ${version} == "master" ]]; then - pname="kicad-unstable" - today="${now}" - elif [[ ${version} == "testing" ]]; then - pname="kicad-testing" - today="${testing_branch}-${now}" - else - pname="kicad" - today="${version}" - fi - src_version=${version}; lib_version=${version}; # testing is the stable branch on the main repo @@ -126,16 +125,35 @@ for version in "${all_versions[@]}"; do lib_version=${latest_tag}; fi + if [[ ${version} == "master" ]]; then + pname="kicad-unstable" + elif [[ ${version} == "testing" ]]; then + pname="kicad-testing" + else + pname="kicad" + fi + # skip a version if we don't want to check it - if [[ (${version} != "master" && ${version} != "testing" && -n ${check_stable}) \ - || (${version} == "testing" && -n ${check_testing}) \ - || (${version} == "master" && -n ${check_unstable}) ]]; then + if [[ (-n ${check_stable} && ${version} != "master" && ${version} != "testing") \ + || (-n ${check_testing} && ${version} == "testing") \ + || (-n ${check_unstable} && ${version} == "master" ) ]]; then + + if [[ ${version} == "master" ]]; then + pname="kicad-unstable" + new_version="${now}" + elif [[ ${version} == "testing" ]]; then + pname="kicad-testing" + new_version="${testing_branch}-${now}" + else + pname="kicad" + new_version="${version}" + fi printf "\nChecking %s\n" "${pname}" >&2 printf "%2s\"%s\" = {\n" "" "${pname}" printf "%4skicadVersion = {\n" "" - printf "%6sversion =\t\t\t\"%s\";\n" "" "${today}" + printf "%6sversion =\t\t\t\"%s\";\n" "" "${new_version}" printf "%6ssrc = {\n" "" echo "Checking src" >&2 @@ -143,9 +161,10 @@ for version in "${all_versions[@]}"; do src_rev="$(cut -f1 <<< "${scratch}")" has_rev="$(grep -sm 1 "\"${pname}\"" -A 4 "${file}" | grep -sm 1 "${src_rev}" || true)" has_hash="$(grep -sm 1 "\"${pname}\"" -A 5 "${file}" | grep -sm 1 "sha256" || true)" + old_version="$(grep -sm 1 "\"${pname}\"" -A 3 "${file}" | grep -sm 1 "version" | awk -F "\"" '{print $2}' || true)" if [[ -n ${has_rev} && -n ${has_hash} && -z ${clean} ]]; then - echo "Reusing old ${pname}.src.sha256, already latest .rev" >&2 + echo "Reusing old ${pname}.src.sha256, already latest .rev at ${old_version}" >&2 scratch=$(grep -sm 1 "\"${pname}\"" -A 5 "${file}") grep -sm 1 "rev" -A 1 <<< "${scratch}" else @@ -158,7 +177,7 @@ for version in "${all_versions[@]}"; do printf "%4s};\n" "" printf "%4slibVersion = {\n" "" - printf "%6sversion =\t\t\t\"%s\";\n" "" "${today}" + printf "%6sversion =\t\t\t\"%s\";\n" "" "${new_version}" printf "%6slibSources = {\n" "" for lib in "${libs[@]}"; do @@ -170,7 +189,7 @@ for version in "${all_versions[@]}"; do has_rev="$(grep -sm 1 "\"${pname}\"" -A 19 "${file}" | grep -sm 1 "${lib_rev}" || true)" has_hash="$(grep -sm 1 "\"${pname}\"" -A 20 "${file}" | grep -sm 1 "${lib}.sha256" || true)" if [[ -n ${has_rev} && -n ${has_hash} && -z ${clean} ]]; then - echo "Reusing old kicad-${lib}-${today}.src.sha256, already latest .rev" >&2 + echo "Reusing old kicad-${lib}-${new_version}.src.sha256, already latest .rev" >&2 scratch="$(grep -sm 1 "\"${pname}\"" -A 20 "${file}")" grep -sm 1 "${lib}" -A 1 <<< "${scratch}" else @@ -214,3 +233,22 @@ if [[ ${count} -gt 0 ]]; then else echo "No changes, those checked are up to date" >&2 fi + +# using UPDATE_NIX_ATTR_PATH to detect if this is being called from update.nix +# and output JSON to describe the changes +if [[ -n ${UPDATE_NIX_ATTR_PATH} ]]; then + + if [[ ${count} -eq 0 ]]; then echo "[{}]"; exit 0; fi + + jq -n \ + --arg attrpath "${UPDATE_NIX_PNAME}" \ + --arg oldversion "${old_version}" \ + --arg newversion "${new_version}" \ + --arg file "${file}" \ +'[{ + "attrPath": $attrpath, + "oldVersion": $oldversion, + "newVersion": $newversion, + "files": [ $file ] +}]' +fi |