diff --git a/.travis.yml b/.travis.yml index 10b1eff10..e652fa0d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,9 @@ jobs: - make goget-tools script: skip before_deploy: + - make cross - make prepare-release + - make packages - ./scripts/generate-bintray-json.sh deploy: - provider: bintray diff --git a/Makefile b/Makefile index 15b12e293..a4f977226 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,9 @@ cross: generate-cli-docs: go run scripts/generate-cli-documentation.go +# create gzipped binaries in ./dist/release/ +# for uploading to GitHub release page +# run make cross before this! .PHONY: prepare-release prepare-release: cross ./scripts/prepare-release.sh @@ -58,3 +61,9 @@ prepare-release: cross .PHONY: test test: go test -race $(PKGS) + +# create deb and rpm packages using fpm in ./dist/pkgs/ +# run make cross before this! +.PHONY: packages +packages: + ./scripts/create-packages.sh diff --git a/scripts/create-packages.sh b/scripts/create-packages.sh new file mode 100755 index 000000000..31fa397c1 --- /dev/null +++ b/scripts/create-packages.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# fpm is required installed (https://github.com/jordansissel/fpm) + +BIN_DIR="./dist/bin/" +PKG_DIR="./dist/pkgs/" + +mkdir -p $PKG_DIR + +# package version, use current date by default (if build from master) +PKG_VERSION=$(date "+%Y%m%d%H%M%S") + +# if this is run on travis make sure that binary was build with corrent version +if [[ -n $TRAVIS_TAG ]]; then + echo "Checking if ocdev version was set to the same version as current tag" + # use sed to get only semver part + bin_version=$(${BIN_DIR}/linux-amd64/ocdev version | sed 's/ .*//g') + if [ "$TRAVIS_TAG" == "v${bin_version}" ]; then + echo "OK: ocdev version output is matching current tag" + else + echo "ERR: TRAVIS_TAG ($TRAVIS_TAG) is not matching 'ocdev version' (v${bin_version})" + exit 1 + fi + # this is build from tag, that means it is proper relase, use version for PKG_VERSION + PKG_VERSION="${bin_version}" +fi + +# create packages using fpm +fpm -h >/dev/null 2>&1 || { + echo "ERROR: fpm (https://github.com/jordansissel/fpm) is not installed. Can't create linux packages" + exit 1 +} + +TMP_DIR=$(mktemp -d) +mkdir -p $TMP_DIR/usr/local/bin/ +cp $BIN_DIR/linux-amd64/ocdev $TMP_DIR/usr/local/bin/ + +echo "creating DEB package" +fpm \ + --input-type dir --output-type deb \ + --chdir $TMP_DIR \ + --name ocdev --version $PKG_VERSION \ + --architecture amd64 \ + --maintainer "Tomas Kral " \ + --package $PKG_DIR + +echo "creating RPM package" +fpm \ + --input-type dir --output-type rpm \ + --chdir $TMP_DIR \ + --name ocdev --version $PKG_VERSION \ + --architecture x86_64 --rpm-os linux \ + --maintainer "Tomas Kral " \ + --package $PKG_DIR \ No newline at end of file diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh index 6f405fa5a..0e0be8c28 100755 --- a/scripts/prepare-release.sh +++ b/scripts/prepare-release.sh @@ -1,5 +1,7 @@ #!/bin/bash +# this script assumes that runs on linux + BIN_DIR="./dist/bin/" RELEASE_DIR="./dist/release/" @@ -18,10 +20,15 @@ if [[ -n $TRAVIS_TAG ]]; then fi fi +# gziped binaries for arch in `ls -1 $BIN_DIR/`;do suffix="" if [[ $arch == windows-* ]]; then suffix=".exe" fi - gzip --keep --to-stdout $BIN_DIR/$arch/ocdev$suffix > $RELEASE_DIR/ocdev-$arch$suffix.gz + source_file=$BIN_DIR/$arch/ocdev$suffix + target_file=$RELEASE_DIR/ocdev-$arch$suffix.gz + + echo "gzipping binary $source_file as $target_file" + gzip --keep --to-stdout $source_file > $target_file done