From 7276c7d0cbf08465f8bf617032182f3e2b1bab51 Mon Sep 17 00:00:00 2001 From: John Dyer Date: Sun, 24 Nov 2019 12:29:48 -0500 Subject: [PATCH] switch release scripts to Bonsai, and switch checksum to sha512 --- .gitignore | 1 + .goreleaser.yml | 1 + .travis.yml | 3 +- travis/generate-sha512sum.sh | 22 ---------- travis/github-release-upload.sh | 76 --------------------------------- 5 files changed, 3 insertions(+), 100 deletions(-) delete mode 100755 travis/generate-sha512sum.sh delete mode 100755 travis/github-release-upload.sh diff --git a/.gitignore b/.gitignore index 0fef63c..334c54b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vendor/ +bonsai/ coverage.txt coverage.out dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml index b4ed7d2..bf8806e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -31,6 +31,7 @@ checksum: # You can change the name of the checksums file. # Default is `{{ .ProjectName }}_{{ .Version }}_checksums.txt`. name_template: "{{ .ProjectName }}_{{ .Version }}_sha512-checksums.txt" + algorithm: sha512 archives: - id: default diff --git a/.travis.yml b/.travis.yml index 0c45ee5..17099b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,5 +23,4 @@ after_deploy: - rm -f coverage.txt - git clone https://github.com/sensu/sensu-go-bonsai-asset.git bonsai - bonsai/generate-sha512sum.sh -- bonsai/github-release-upload.sh github_api_token=$GITHUB_TOKEN repo_slug="$TRAVIS_REPO_SLUG" - tag="${TRAVIS_TAG}" filename="dist/$(cat dist/sha512_file)" +- bonsai/github-release-upload.sh github_api_token=$GITHUB_TOKEN repo_slug="$TRAVIS_REPO_SLUG" tag="${TRAVIS_TAG}" filename="dist/$(cat dist/sha512_file)" diff --git a/travis/generate-sha512sum.sh b/travis/generate-sha512sum.sh deleted file mode 100755 index b4dd73a..0000000 --- a/travis/generate-sha512sum.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - - -if [ -d dist ]; then - files=( dist/*sha256-checksums.txt ) - file=$(basename "${files[0]}") - IFS=_ read -r package prefix leftover <<< "$file" - unset leftover - if [ -n "$prefix" ]; then - echo "Generating sha512sum for ${package}_${prefix}" - cd dist || exit - sha512_file="${package}_${prefix}_sha512-checksums.txt" - echo "${sha512_file}" > sha512_file - echo "sha512_file: $(cat sha512_file)" - sha512sum ./*.tar.gz > "${sha512_file}" - echo "" - cat "${sha512_file}" - fi -else - echo "error" -fi - diff --git a/travis/github-release-upload.sh b/travis/github-release-upload.sh deleted file mode 100755 index b97d6d7..0000000 --- a/travis/github-release-upload.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env bash -# -# Author: Stefan Buck -# License: MIT -# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447 -# -# -# This script accepts the following parameters: -# -# * owner -# * repo -# * tag -# * filename -# * github_api_token -# -# Script to upload a release asset using the GitHub API v3. -# -# Example: -# -# github-release-upload.sh github_api_token=TOKEN repo_slug=hey/now tag=v0.1.0 filename=./build.zip -# - -# Check dependencies. -set -e - -# Set Envvars Defaults: -filename="text.txt" -github_api_token="aaa" -repo_slug="test/test" -tag="0.0.0" -id="0" - -# Validate settings. -[ "$TRACE" ] && set -x - -CONFIG=( "$@" ) - -# Update Envvars using cmdline args -for line in "${CONFIG[@]}"; do - eval "$line" -done - -# Define variables. -GH_API="https://api.github.com" -GH_REPO="$GH_API/repos/$repo_slug" -GH_TAGS="$GH_REPO/releases/tags/$tag" -AUTH="Authorization: token $github_api_token" - -if [[ "$tag" == 'LATEST' ]]; then - GH_TAGS="$GH_REPO/releases/latest" -fi - -# Validate token. -curl -o /dev/null -sH "$AUTH" "$GH_REPO" || { echo "Error: Invalid repo, token or network issue!"; exit 1; } - -# Read asset tags. -echo "curl -sH ${AUTH} ${GH_TAGS}" -response=$(curl -sH "${AUTH}" "${GH_TAGS}") - -# Get ID of the asset based on given filename. -unset id -eval "$(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')" -echo "$id" -[ "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; } - -# Upload asset -echo "Uploading asset... " - -# Construct url -GH_ASSET="https://uploads.github.com/repos/$repo_slug/releases/$id/assets?name=$(basename "$filename")" -echo "$GH_ASSET" -echo "curl $GITHUB_OAUTH_BASIC --data-binary @$filename -H \"Authorization: token $github_api_token\" -H \"Content-Type: application/octet-stream\" $GH_ASSET" -curl "${GITHUB_OAUTH_BASIC}" --data-binary @"${filename}" -H "Authorization: token ${github_api_token}" -H "Content-Type: application/octet-stream" "${GH_ASSET}" - - -