Skip to content

Commit

Permalink
Merge pull request #8 from jspaleta/asset-automation
Browse files Browse the repository at this point in the history
Asset automation
  • Loading branch information
Nikki Attea authored Dec 4, 2018
2 parents f25674d + 3a59ab2 commit 0922b55
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ builds:
- goos: linux
goarch: mips64le

checksum:
# You can change the name of the checksums file.
# Default is `{{ .ProjectName }}_{{ .Version }}_checksums.txt`.
name_template: "{{ .ProjectName }}_{{ .Version }}_sha256-checksums.txt"

archive:
format: tar.gz
files:
Expand Down
23 changes: 18 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: go
go:
- 1.10.x


install:
- go get gopkg.in/alecthomas/gometalinter.v1
- go get github.com/gordonklaus/ineffassign
Expand All @@ -12,14 +14,25 @@ install:
script:
- gometalinter.v1 --vendor --disable-all --enable=vet --enable=golint --enable=ineffassign
--enable=goconst --tests ./...

before_script:
- echo "REPO $TRAVIS_REPO_SLUG TAG ${TRAVIS_TAG}"

before_deploy:
- go get github.com/goreleaser/goreleaser
deploy:
skip_cleanup: true
provider: script
script: goreleaser
on:
tags: true
- #goreleaser
provider: script
script: goreleaser
skip_cleanup: true
on:
tags: true

after_deploy:
- travis/generate-sha512sum.sh
- cat "dist/sha512_file"
- travis/github-release-upload.sh github_api_token=$GITHUB_TOKEN repo_slug="$TRAVIS_REPO_SLUG" tag="${TRAVIS_TAG}" filename="dist/$(cat dist/sha512_file)"

env:
global:
secure: AAAAB3NzaC1yc2EAAAADAQABAAACAQDd8VD1c3Mno+WzqOC/4a59ersotUdAqOsQCdql8eVDlv49PWkFEUh/cKVmhnooGO68O+Qt3dcP7uqEo2DZtgxfTshd0JpT/IV6KLGqJbg8VWIbikY4AIlNZEov4PDjvGsyRogYfxbx5F71pr5TiYbvkyN4qYDZKJMmqfD1VcA5FYXrLg18SR3fuly+thfIQtD8yv9rHTMfk9KfcwoNbyLgmU28U6ZUHm0tz6x+UN9LT39oCSZAp3MvyLZvEmFZhyzSnfylhTzICi05F1gpPzD0CAvLHbtPGse7igXu1fupNEuM9f01g+uY/gsHNuxcgL026RcMd5EYvbr0F8chVrrZRTc7Emgd2QSqVGWZb0jVnIAF09FsIzHgt2nSQRkkEhNP80skOiDi3VthQ8b4XWO4hJ4bTm1C6DQGUN80Y8xtlNFYpHBA7GNV+zwIoTOGSb0vKP/786cVHx2E+hYZkP+03QXdv0zyeXevCS6s4TSKGyHv9apRg+6JZ1nGm6f1MPHB5OLEf582xi5RAkKtFGpKxDHyTv1KhcySzgOvbQTW488O2jPMUuTHAevp6HQvyOFe2OMYIyhu1xMK5rTBKzRMwMG8WH8Yf+9WqBJf2mmgqPuAX16KyXao9x/iyaFD9VnVyINqxxCO+LiTFGPvOU6uUNGm3Tm+HznOo7s13ueVEQ==
22 changes: 22 additions & 0 deletions travis/generate-sha512sum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/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

76 changes: 76 additions & 0 deletions travis/github-release-upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/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}"



0 comments on commit 0922b55

Please sign in to comment.