diff --git a/.travis.yml b/.travis.yml index 74646ee5..2fad16f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ addons: env: global: - - secure: cDfB188ECmloGfScZQezqwiFef7l+gXgn2RiTOxINriy9wYS6RmZxuZBHGuR36u7QV3QEJtMdihyQ+XBN2eQPf5jULQXV15t7gArXEVPzzF8i+f8MTgVHugU3TqmPLQkY94wBBbpzvRD9xCAC/uNiQcLLwuD2SjPfTXkqgqqtd0= - PGVERSION="9.3" - JANSSON_VERSION="2.9" - CK_DEFAULT_TIMEOUT=20 @@ -36,20 +35,3 @@ script: - ienv - ils - ./scripts/travis_script.sh - -after_success: - - make dist - - export DIST_FILE=$(ls baton-*.tar.gz) - - export SHA256_FILE=$DIST_FILE.sha256 - - shasum -a 256 $DIST_FILE > $SHA256_FILE - -deploy: - provider: releases - api-key: $GH_OAUTH - file: - - $DIST_FILE - - $SHA256_FILE - skip_cleanup: true - on: - tags: true - all_branches: true diff --git a/Makefile.am b/Makefile.am index ec52ef6e..bfb10084 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,8 @@ ACLOCAL_AMFLAGS= -I m4 +AM_DISTCHECK_CONFIGURE_FLAGS = --with-irods + if HAVE_SPHINX MAYBE_DOC = doc endif @@ -16,6 +18,12 @@ pkgconfig_DATA = baton.pc etcdir = $(sysconfdir) +github-release: + $(top_builddir)/scripts/github_release.sh \ +-a $(GITHUB_API_TOKEN) -b "Release $(PACKAGE_VERSION)" \ +-c master -d -n $(PACKAGE_VERSION) -r $(GITHUB_REPO) \ +-t $(PACKAGE_VERSION) -u $(GITHUB_USER) baton-$(PACKAGE_VERSION).tar.gz + if COVERAGE_ENABLED .PHONY: coverage coverage-report clean-coverage-report check-coverage diff --git a/configure.ac b/configure.ac index fafc87f0..2f9aae13 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,33 @@ AS_IF( AM_CONDITIONAL(HAVE_SPHINX, [test "x${SPHINXBUILD}" != "xno"]) dnl End Sphinx +dnl Begin GitHub release upload +AC_ARG_VAR([GITHUB_API_TOKEN], [GitHub API token file]) +AC_ARG_VAR([GITHUB_USER], [GitHub release user name (default: $USER)]) +AC_ARG_VAR([GITHUB_REPO], [GitHub release repository (default: baton)]) + +if test -z "$GITHUB_USER"; then + GITHUB_USER=${USER} +fi + +if test -z "$GITHUB_REPO"; then + GITHUB_REPO=baton +fi + +AC_ARG_ENABLE([github-release], + [AS_HELP_STRING([--enable-github-release], + [Enable GitHub release (default is no)])], + [release_enabled=${enableval}], [release_enabled=no]) + +AS_IF( + [test "x${release_enabled}" = "xyes"], + AS_IF([test "x${GITHUB_API_TOKEN}" = "x"], + [AC_MSG_ERROR(No GitHub API token file set. GitHub releases will not be made)], + [AC_MSG_NOTICE([GitHub release enabled for repo $GITHUB_REPO]) + AC_MSG_NOTICE([GitHub release user $GITHUB_USER]) + AC_MSG_NOTICE([GitHub release API token $GITHUB_API_TOKEN])])) +dnl End GitHub + dnl Begin Lcov code coverage analysis dnl Be aware on OS X that gcc may not really be gcc, but a symlink to diff --git a/scripts/github_release.sh b/scripts/github_release.sh new file mode 100755 index 00000000..ba30b5e7 --- /dev/null +++ b/scripts/github_release.sh @@ -0,0 +1,232 @@ +#!/bin/bash +# +# Copyright (C) 2017 Genome Research Limited. All Rights Reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the Perl Artistic License or the GNU General +# Public License as published by the Free Software Foundation, either +# version 3 of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Author: Keith James + +# Needs error handling to report better messages when HTTP responses +# indicate a failure on the server + +set -e -o pipefail + +# trap cleanup EXIT INT TERM + +# cleanup() { +# rm -r ${TMP} +# } + +usage() { + cat 1>&2 << EOF + +This script creates a release on GitHub, creates a sha256 checksum of +each release artifact and uploads the artifacts and checksum files to +the release. + +A GitHub API token is required to be stored locally in a file +accessible to the script. The token is sent to GitHub using SSL. + +Version: $VERSION +Author: Keith James + +Usage: $0 -a \\ + -b "" \\ + -c [-d] -n [-p] \\ + -r -t \\ + -u [-v] + +Options: + -b Release description body. Required. + -c Target commitish e.g. 'master'. Required. + -d Draft release flag + -n Release name. Required. + -p Pre-release flag + -r Github repository name. Required. + -t Tag name e.g. '1.0.0'. Required. + -u GitHub user name. Required. + -v Print verbose messages +EOF +} + +# Read the API token from a file +read_api_token() { + while read token || [[ -n $token ]] ; do + TOKEN=${TOKEN:-$token} + done < $GITHUB_API_TOKEN +} + +# URL encode an input +urlencode() { + echo $(python -c "import urllib ; print(urllib.quote(\"$1\"))") +} + +# Create the release and extract the upload URL from the response +create_github_release() { + pushd ${TMP} + + cat > release.json < response.json + + GITHUB_UPLOAD_URL=$($PYTHON -c 'import json ; print(json.load(open("response.json"))["upload_url"])' | sed -e 's/{?name,label}//') + + popd +} + +# Checksum and upload the artifacts to the upload URL obtained from +# the release response +upload_release_artifacts() { + for artifact in "${RELEASE_ARTIFACTS[@]}"; do + if [ ! -e "$artifact" ] ; then + echo "Release artifact $artifact file does not exist" + exit 5 + fi + + shasum -a 256 "$artifact" > "$artifact.sha256" + + encoded=$(urlencode "$artifact") + + $CURL -u $TOKEN:x-oauth-basic -X POST \ + -H "Content-Type: application/octet-stream" \ + -sSL $GITHUB_UPLOAD_URL?name="$encoded" \ + --data-binary @"$artifact" + + $CURL -u $TOKEN:x-oauth-basic -X POST \ + -H "Content-Type: application/octet-stream" \ + -sSL $GITHUB_UPLOAD_URL?name="$encoded.sha256" \ + --data-binary @"$artifact.sha256" + done +} + +CURL=/usr/bin/curl +PYTHON=python + +TMPDIR=$PWD/ +TMP=$(mktemp -d ${TMPDIR:-/tmp/}$(basename -- "$0").XXXXXXXXXX) + +GITHUB_API_URL=https://api.github.com +GITHUB_API_TOKEN= +GITHUB_UPLOAD_URL= + +RELEASE_BODY= +TARGET_COMMITISH= +DRAFT=false +RELEASE_NAME= +PRERELEASE=false +REPOSITORY_NAME= +TAG_NAME= +USER_NAME= + +while getopts "a:b:c:dn:pr:t:u:v" option; do + case "$option" in + a) + GITHUB_API_TOKEN="${OPTARG}" + ;; + b) + RELEASE_BODY="${OPTARG}" + ;; + c) + TARGET_COMMITISH="${OPTARG}" + ;; + d) + DRAFT="true" + ;; + n) + RELEASE_NAME="${OPTARG}" + ;; + p) + PRERELEASE="true" + ;; + r) + REPOSITORY_NAME="${OPTARG}" + ;; + t) + TAG_NAME="${OPTARG}" + ;; + u) + USER_NAME="${OPTARG}" + ;; + v) + set -x + ;; + *) + usage + echo "Invalid argument!" + exit 4 + ;; + esac +done + +shift "$((OPTIND-1))" + +RELEASE_ARTIFACTS=("$@") + +if [ -z "$GITHUB_API_TOKEN" ] ; then + usage + echo -e "\nERROR:\n A -a argument is required" + exit 4 +fi + +if [ -z "$RELEASE_BODY" ] ; then + usage + echo -e "\nERROR:\n A -b argument is required" + exit 4 +fi + +if [ -z "$TARGET_COMMITISH" ] ; then + usage + echo -e "\nERROR:\n A -c argument is required" + exit 4 +fi + +if [ -z "$RELEASE_NAME" ] ; then + usage + echo -e "\nERROR:\n A -n argument is required" + exit 4 +fi + +if [ -z "$REPOSITORY_NAME" ] ; then + usage + echo -e "\nERROR:\n A -r argument is required" + exit 4 +fi + +if [ -z "$TAG_NAME" ] ; then + usage + echo -e "\nERROR:\n A -t argument is required" + exit 4 +fi + +if [ -z "$USER_NAME" ] ; then + usage + echo -e "\nERROR:\n A -u argument is required" + exit 4 +fi + +if [ -z "$RELEASE_ARTIFACTS" ] ; then + usage + echo -e "\nERROR:\n No release artifacts were supplied" + exit 4 +fi + +read_api_token +create_github_release +upload_release_artifacts