Skip to content

Commit

Permalink
Merge pull request #194 from wtsi-npg/devel
Browse files Browse the repository at this point in the history
release 1.0.1 prep
  • Loading branch information
dozy authored Nov 24, 2017
2 parents b295a86 + 1677d1e commit e4ce083
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 29 deletions.
18 changes: 0 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ addons:

env:
global:
- secure: cDfB188ECmloGfScZQezqwiFef7l+gXgn2RiTOxINriy9wYS6RmZxuZBHGuR36u7QV3QEJtMdihyQ+XBN2eQPf5jULQXV15t7gArXEVPzzF8i+f8MTgVHugU3TqmPLQkY94wBBbpzvRD9xCAC/uNiQcLLwuD2SjPfTXkqgqqtd0=
- PGVERSION="9.3"
- JANSSON_VERSION="2.9"
- CK_DEFAULT_TIMEOUT=20
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

ACLOCAL_AMFLAGS= -I m4

AM_DISTCHECK_CONFIGURE_FLAGS = --with-irods

if HAVE_SPHINX
MAYBE_DOC = doc
endif
Expand All @@ -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

Expand Down
27 changes: 27 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
232 changes: 232 additions & 0 deletions scripts/github_release.sh
Original file line number Diff line number Diff line change
@@ -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 <kdj@sanger.ac.uk>
Usage: $0 -a <GitHub API token file> \\
-b "<release description body>" \\
-c <target commitish> [-d] -n <release name> [-p] \\
-r <GitHub repository name> -t <release tag name> \\
-u <GitHub user name> [-v] <release artifact files>
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 <<EOF
{"tag_name": "$TAG_NAME",
"target_commitish": "$TARGET_COMMITISH",
"name": "$RELEASE_NAME",
"body": "$RELEASE_BODY",
"draft": $DRAFT,
"prerelease": $PRERELEASE}
EOF

$CURL -u $TOKEN:x-oauth-basic -X POST \
-sSL https://api.github.com/repos/$USER_NAME/$REPOSITORY_NAME/releases \
-d @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 <API token file> argument is required"
exit 4
fi

if [ -z "$RELEASE_BODY" ] ; then
usage
echo -e "\nERROR:\n A -b <release body> argument is required"
exit 4
fi

if [ -z "$TARGET_COMMITISH" ] ; then
usage
echo -e "\nERROR:\n A -c <target commitish> argument is required"
exit 4
fi

if [ -z "$RELEASE_NAME" ] ; then
usage
echo -e "\nERROR:\n A -n <release name> argument is required"
exit 4
fi

if [ -z "$REPOSITORY_NAME" ] ; then
usage
echo -e "\nERROR:\n A -r <repository name> argument is required"
exit 4
fi

if [ -z "$TAG_NAME" ] ; then
usage
echo -e "\nERROR:\n A -t <tag name> argument is required"
exit 4
fi

if [ -z "$USER_NAME" ] ; then
usage
echo -e "\nERROR:\n A -u <user name> 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
17 changes: 8 additions & 9 deletions src/baton-get.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ int main(int argc, char *argv[]) {
}
}

if (acl_flag) flags = flags | PRINT_ACL;
if (avu_flag) flags = flags | PRINT_AVU;
if (raw_flag) flags = flags | PRINT_RAW;
if (size_flag) flags = flags | PRINT_SIZE;
if (timestamp_flag) flags = flags | PRINT_TIMESTAMP;
if (unsafe_flag) flags = flags | UNSAFE_RESOLVE;
if (acl_flag) flags = flags | PRINT_ACL;
if (avu_flag) flags = flags | PRINT_AVU;
if (raw_flag) flags = flags | PRINT_RAW;
if (save_flag) flags = flags | SAVE_FILES;
if (size_flag) flags = flags | PRINT_SIZE;
if (timestamp_flag) flags = flags | PRINT_TIMESTAMP;
if (unbuffered_flag) flags = flags | FLUSH;
if (unsafe_flag) flags = flags | UNSAFE_RESOLVE;

const char *help =
"Name\n"
Expand Down Expand Up @@ -147,9 +149,6 @@ int main(int argc, char *argv[]) {
exit(0);
}

if (unsafe_flag) flags = flags | UNSAFE_RESOLVE;
if (unbuffered_flag) flags = flags | FLUSH;

if (debug_flag) set_log_threshold(DEBUG);
if (verbose_flag) set_log_threshold(NOTICE);
if (silent_flag) set_log_threshold(FATAL);
Expand Down
5 changes: 3 additions & 2 deletions src/log.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2013, 2014 Genome Research Ltd. All rights reserved.
* Copyright (C) 2013, 2014, 2017 Genome Research Ltd. All rights
* reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,7 +39,7 @@ typedef enum {
} log_level;

#define logmsg(level, ...) \
log_impl(__LINE__, __FILE__, __FUNCTION__, level, __VA_ARGS__);
log_impl(__LINE__, __FILE__, __func__, level, __VA_ARGS__);

void log_impl(int line, const char *file, char const *function,
log_level level, ...);
Expand Down

0 comments on commit e4ce083

Please sign in to comment.