home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

univ.sh (1627B)


      1 #!/usr/bin/env bash
      2 # univ: update niv (and generate a nice commit)
      3 
      4 set -euo pipefail
      5 
      6 SOURCES=nix/sources.json
      7 
      8 error() {
      9     echo "::error::$*"
     10     exit 1
     11 }
     12 
     13 update() {
     14     local dep=$1
     15     echo "checking for update: $dep" >&2
     16     owner=$(jq -r ".\"$dep\".owner" < ${SOURCES})
     17     repo=$(jq -r ".\"$dep\".repo" < ${SOURCES})
     18     old_rev=$(jq -r ".\"$dep\".rev" < ${SOURCES})
     19     dep_url=$(jq -r ".\"$dep\".url // empty" < "${SOURCES}" | { grep github.com || true; })
     20     [[ -n $dep_url ]] && is_github="yes" || is_github=""
     21     niv update $dep 1>&2
     22     new_rev=$(jq -r ".\"$dep\".rev" < ${SOURCES})
     23     if [[ $old_rev == $new_rev ]]; then
     24         echo "… no updates" >&2
     25         return
     26     fi
     27     echo "$dep: ${old_rev} to ${new_rev}"
     28     if [[ -z $is_github ]]; then
     29         echo "$dep not using github.com, no changelog"
     30     else
     31         merges_filter=""
     32         hub api "/repos/$owner/$repo/compare/${old_rev}...${new_rev}" \
     33             | jq -r '.commits[] '"$merges_filter"' | "* [`\(.sha[0:8])`](\(.html_url)) \(.commit.message | split("\n") | first)"' \
     34             | sed "s~\(#[0-9]\+\)~$owner/$repo\1~g"
     35     fi
     36 }
     37 
     38 main() {
     39     message=$(mktemp)
     40     commit_msg=$(mktemp)
     41     for dep in $(jq -r 'keys[]' < ${SOURCES}); do
     42         update $dep >> $message
     43         echo "" >> $message
     44     done
     45     echo $message $commit_msg
     46     content=$(cat $message | tr -d '\n')
     47     if [[ -z "$content" ]]; then
     48         echo "No updates, do nothing"
     49         exit 0
     50     fi
     51     echo "nix: niv update(s)" > $commit_msg
     52     echo "" >> $commit_msg
     53     cat $message >> $commit_msg
     54     git add nix
     55     git commit -F $commit_msg
     56 }
     57 
     58 main $@