From 51eea10d80fffd5e3ac1997789128efedc407012 Mon Sep 17 00:00:00 2001 From: Michael Aldridge Date: Thu, 18 Mar 2021 02:30:55 -0700 Subject: [PATCH] Add release workflow --- .github/workflows/release.yml | 27 +++++++++++++++ .goreleaser.yml | 24 +++++++++++++ scripts/prepare.sh | 3 ++ scripts/vendor-licenses | 64 +++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100755 scripts/prepare.sh create mode 100755 scripts/vendor-licenses diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..16f3416 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,27 @@ +--- +name: goreleaser + +on: + push: + tags: + - '*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Unshallow + run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.15.x + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v1 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..650b647 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,24 @@ +before: + hooks: + - go mod vendor + - scripts/prepare.sh +builds: + - goos: + - linux +archives: +- replacements: + linux: Linux + 386: i386 + amd64: x86_64 + files: + - LICENSE + - NOTICE + - README.md +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +release: + github: + owner: netauth + name: nsscache diff --git a/scripts/prepare.sh b/scripts/prepare.sh new file mode 100755 index 0000000..a40b20f --- /dev/null +++ b/scripts/prepare.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +./scripts/vendor-licenses > NOTICE diff --git a/scripts/vendor-licenses b/scripts/vendor-licenses new file mode 100755 index 0000000..e09f235 --- /dev/null +++ b/scripts/vendor-licenses @@ -0,0 +1,64 @@ +#!/bin/bash + +list_vendor_files() { + find vendor -type f -a \( -iname 'COPYING*' -o -iname 'LICENSE*' \) | sort +} + +list_files() { + goroot="$(go env GOROOT)" + goid='Go programming language' + if [ -r "$goroot/LICENSE" ]; then + echo "${goid}::$goroot/LICENSE" + elif [ -r /usr/share/licenses/go/LICENSE ]; then + echo "${goid}::/usr/share/licenses/go/LICENSE" + else # last restort: HTTP + echo "${goid}::https://golang.org/LICENSE?m=text" + fi + list_vendor_files +} + +generate_notice() { + last= + $0 -all | while IFS=$'\n' read -r license; do + pkg="${license%%::*}" + if [ "$pkg" != "$license" ]; then + license="${license#${pkg}::}" + else + pkg="${pkg#vendor/}" + pkg="${pkg%/*}" + fi + + printf "%s" "${last:+'\n\n\n'}" + last=x + + echo "$pkg" | sed 'p;s/./-/g' + fetch "${license}" + done +} + +fetch() { + case "$1" in + *://*) wget -q -O- "${1#*::}";; + *) cat "${1#*::}";; + esac +} + +case "${1--gen}" in + -gen) + if [ -t 1 ]; then + generate_notice | ${PAGER:-more} + else + generate_notice + fi + ;; + -src) list_vendor_files;; + -all) list_files;; + -h) + echo 'Usage: vendor-licenses [-h|-gen|-src|-all]' >&2 + exit 2 + ;; + *) + echo "Unrecognized argument: '$1'" >&2 + exit 1 + ;; +esac