github.com/rigado/snapd@v2.42.5-go-mod+incompatible/mkauthors.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  # debugging if anything fails is tricky as dh-golang eats up all output
     5  # uncomment the lines below to get a useful trace if you have to touch
     6  # this again (my advice is: DON'T)
     7  #set -x
     8  #logfile=/tmp/mkauthors.log
     9  #exec >> $logfile 2>&1
    10  #echo "env: $(set)"
    11  #echo "mkauthors.sh run from: $0"
    12  #echo "pwd: $(pwd)"
    13  
    14  # GO_GENERATE_BUILDDIR may be the toplevel pkg dir, but during
    15  # "dpkg-buildpackage" it will become a different _build/ dir that
    16  # dh-golang creates and that only contains a subset of the files of
    17  # the toplevel buildir.
    18  GO_GENERATE_BUILDDIR="$(pwd)"
    19  
    20  # run from "go generate" adjust path
    21  if [ "$GOPACKAGE" = "cmd" ]; then
    22      GO_GENERATE_BUILDDIR="$(pwd)/.."
    23  fi
    24  
    25  # Let's try to derive authors from git
    26  if ! command -v git >/dev/null; then
    27      exit
    28  fi
    29  
    30  # see if we are in a git branch, if not, do nothing
    31  if [ ! -d .git ]; then
    32      exit
    33  fi
    34  
    35  raw_authors="$(git shortlog -s|sort -n|tail -n14|cut -f2)"
    36  authors=""
    37  while read -r author; do
    38      authors="$authors \"$author\","
    39  done <<< "$raw_authors"
    40  
    41  
    42  cat <<EOF > "$GO_GENERATE_BUILDDIR/cmd/snap/cmd_blame_generated.go"
    43  package main
    44  
    45  // generated by mkauthors.sh; do not edit
    46  
    47  func init() {
    48  	authors = []string{"Mark Shuttleworth", "Gustavo Niemeyer", $authors}
    49  }
    50  EOF
    51  
    52  go fmt "$GO_GENERATE_BUILDDIR/cmd/snap/cmd_blame_generated.go" >/dev/null