From 0c52b23168f2f9e42fca55234f0a8ffde342b4e3 Mon Sep 17 00:00:00 2001 From: "Julian K. Arni" Date: Fri, 5 Jun 2015 14:14:26 +0200 Subject: [PATCH] Upload script and some script refactoring --- .gitignore | 10 +++---- scripts/bump-versions.sh | 21 ++------------ scripts/lib/common.sh | 31 +++++++++++++++++++++ scripts/start-sandbox.sh | 7 +---- scripts/test-all.sh | 9 +----- scripts/update-defaults-nix.sh | 7 +---- scripts/upload.sh | 51 ++++++++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 scripts/lib/common.sh create mode 100755 scripts/upload.sh diff --git a/.gitignore b/.gitignore index 3007a0c1..de16e47a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ -dist -bin -lib -share -packages +/dist +/bin +/lib +/share +/packages *-packages.conf.d cabal-dev add-source-timestamps diff --git a/scripts/bump-versions.sh b/scripts/bump-versions.sh index 43391d35..f75a3d5e 100755 --- a/scripts/bump-versions.sh +++ b/scripts/bump-versions.sh @@ -16,33 +16,16 @@ set -o nounset set -o errexit -DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -DRY_RUN=false -POSITION="none" -SOURCES_TXT="$( dirname $DIR)/sources.txt" - -declare -a SOURCES -readarray -t SOURCES < "$SOURCES_TXT" +. lib/common.sh usage () { - echo " bump-versions [-d|--dry-run]" + echo " bump-versions.sh [-d|--dry-run]" echo " | [-h|--help]" echo " Bumps the specified positional version of all servant packages." echo " POSITION is a number between 0 and 3, inclusive." exit 0 } -join () { local IFS="$1"; shift; echo "$*"; } - -versions_equal () { - local NUM=$(find . -name 'servant*.cabal' | xargs grep "^version:" | awk '{ print $2 }' | uniq -c | wc -l) - if [ 1 -eq $NUM ] ; then - return 0 - else - echo "versions of packages are not all the same!" && exit 1 - fi -} - if [ $# -eq 0 ] ; then echo "expecting one or more arguments. Got 0" usage diff --git a/scripts/lib/common.sh b/scripts/lib/common.sh new file mode 100644 index 00000000..d41a8988 --- /dev/null +++ b/scripts/lib/common.sh @@ -0,0 +1,31 @@ +#!/bin/bash - +#=============================================================================== +# +# FILE: lib/common.sh +# +# DESCRIPTION: Common functions for servant's shell scripts +# Meant to be sourced rather than run. +# +# REQUIREMENTS: bash >= 4 +#=============================================================================== + + +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +DRY_RUN=false +POSITION="none" +SOURCES_TXT="$( dirname $DIR)/sources.txt" +CABAL=${CABAL:-cabal} + +declare -a SOURCES +readarray -t SOURCES < "$SOURCES_TXT" + +join () { local IFS="$1"; shift; echo "$*"; } + +versions_equal () { + local NUM=$(find . -name 'servant*.cabal' | xargs grep "^version:" | awk '{ print $2 }' | uniq -c | wc -l) + if [ 1 -eq $NUM ] ; then + return 0 + else + echo "versions of packages are not all the same!" && exit 1 + fi +} diff --git a/scripts/start-sandbox.sh b/scripts/start-sandbox.sh index 7d042bd2..1c1cab5a 100755 --- a/scripts/start-sandbox.sh +++ b/scripts/start-sandbox.sh @@ -13,12 +13,7 @@ set -o nounset set -o errexit -DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -SOURCES_TXT="$( dirname $DIR)/sources.txt" -CABAL=${CABAL:-cabal} - -declare -a SOURCES -readarray -t SOURCES < "$SOURCES_TXT" +. lib/common.sh prepare_sandbox () { $CABAL sandbox init diff --git a/scripts/test-all.sh b/scripts/test-all.sh index 3e7d0465..111e4e9d 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -14,14 +14,7 @@ set -o nounset set -o errexit -DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -GHC_FLAGS="-Werror" -SOURCES_TXT="$( dirname $DIR)/sources.txt" -CABAL=${CABAL:-cabal} - -declare -a SOURCES -readarray -t SOURCES < "$SOURCES_TXT" - +. lib/common.sh prepare_sandbox () { $CABAL sandbox init diff --git a/scripts/update-defaults-nix.sh b/scripts/update-defaults-nix.sh index 7e85c98a..4ad7a291 100755 --- a/scripts/update-defaults-nix.sh +++ b/scripts/update-defaults-nix.sh @@ -11,12 +11,7 @@ set -o nounset set -o errexit -DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -BASE_DIR="$( dirname $DIR)" -SOURCES_TXT="$BASE_DIR/sources.txt" - -declare -a SOURCES -readarray -t SOURCES < "$SOURCES_TXT" +. lib/common.sh for s in ${SOURCES[@]} ; do echo $s diff --git a/scripts/upload.sh b/scripts/upload.sh new file mode 100755 index 00000000..fc0219f7 --- /dev/null +++ b/scripts/upload.sh @@ -0,0 +1,51 @@ +#!/bin/bash - +#=============================================================================== +# +# FILE: upload.sh +# +# USAGE: ./upload.sh +# +# DESCRIPTION: Uploads all servant packages to Hackage +# +# REQUIREMENTS: cabal, bash >= 4 +# AUTHOR: Julian K. Arni +# CREATED: 05.06.2015 13:05 +#=============================================================================== + +set -o nounset +set -o errexit + +. lib/common.sh + +usage () { + echo " upload.sh " + echo " Uploads all servant packages to Hackage" + exit 0 +} + + +upload_package () { + local package="$0" + local cabalFile="$0.cabal" + pushd "$package" + local version=$(grep -i '^version:' $cabalFile | awk '{ print $2 }') + local sdist="${package}-${version}.tar.gz" + cabal sdist + cabal upload --user="$USER" --password="$PASS" "$sdist" + popd +} + + +if [ $# -ne 2 ] ; then + echo "expecting two arguments." + usage +else + USER="$0" + PASS="$1" +fi + +versions_equal + +for s in ${SOURCES[@]} ; do + upload_package "$s" +done