Upload script and some script refactoring

This commit is contained in:
Julian K. Arni 2015-06-05 14:14:26 +02:00
parent 664691e1ba
commit aec39b546e
7 changed files with 92 additions and 44 deletions

10
.gitignore vendored
View file

@ -1,8 +1,8 @@
dist /dist
bin /bin
lib /lib
share /share
packages /packages
*-packages.conf.d *-packages.conf.d
cabal-dev cabal-dev
add-source-timestamps add-source-timestamps

View file

@ -16,33 +16,16 @@
set -o nounset set -o nounset
set -o errexit set -o errexit
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) . lib/common.sh
DRY_RUN=false
POSITION="none"
SOURCES_TXT="$( dirname $DIR)/sources.txt"
declare -a SOURCES
readarray -t SOURCES < "$SOURCES_TXT"
usage () { usage () {
echo " bump-versions <POSITION> [-d|--dry-run]" echo " bump-versions.sh <POSITION> [-d|--dry-run]"
echo " | [-h|--help]" echo " | [-h|--help]"
echo " Bumps the specified positional version of all servant packages." echo " Bumps the specified positional version of all servant packages."
echo " POSITION is a number between 0 and 3, inclusive." echo " POSITION is a number between 0 and 3, inclusive."
exit 0 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 if [ $# -eq 0 ] ; then
echo "expecting one or more arguments. Got 0" echo "expecting one or more arguments. Got 0"
usage usage

31
scripts/lib/common.sh Normal file
View file

@ -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
}

View file

@ -13,12 +13,7 @@
set -o nounset set -o nounset
set -o errexit set -o errexit
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) . lib/common.sh
SOURCES_TXT="$( dirname $DIR)/sources.txt"
CABAL=${CABAL:-cabal}
declare -a SOURCES
readarray -t SOURCES < "$SOURCES_TXT"
prepare_sandbox () { prepare_sandbox () {
$CABAL sandbox init $CABAL sandbox init

View file

@ -14,14 +14,7 @@
set -o nounset set -o nounset
set -o errexit set -o errexit
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) . lib/common.sh
GHC_FLAGS="-Werror"
SOURCES_TXT="$( dirname $DIR)/sources.txt"
CABAL=${CABAL:-cabal}
declare -a SOURCES
readarray -t SOURCES < "$SOURCES_TXT"
prepare_sandbox () { prepare_sandbox () {
$CABAL sandbox init $CABAL sandbox init

View file

@ -11,12 +11,7 @@
set -o nounset set -o nounset
set -o errexit set -o errexit
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) . lib/common.sh
BASE_DIR="$( dirname $DIR)"
SOURCES_TXT="$BASE_DIR/sources.txt"
declare -a SOURCES
readarray -t SOURCES < "$SOURCES_TXT"
for s in ${SOURCES[@]} ; do for s in ${SOURCES[@]} ; do
echo $s echo $s

51
scripts/upload.sh Executable file
View file

@ -0,0 +1,51 @@
#!/bin/bash -
#===============================================================================
#
# FILE: upload.sh
#
# USAGE: ./upload.sh <USER> <PASSWORD>
#
# 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 <USER> <PASSWORD>"
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