This is an automated email from the ASF dual-hosted git repository. francischuang pushed a commit to tag v3.3.0-rc0 in repository https://gitbox.apache.org/repos/asf/calcite-avatica-go.git
commit 2b8042c92dcc02238e213f01af9a76f808584f0e Author: Francis Chuang <[email protected]> AuthorDate: Fri Apr 26 15:43:22 2019 +1000 Improve release script --- Dockerfile | 23 --- docker-compose.yml | 60 +++++++- docker.sh | 370 +++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 24 --- make-release-artifacts.sh | 187 ----------------------- site/develop/avatica-go.md | 8 +- 6 files changed, 428 insertions(+), 244 deletions(-) diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index d1645d7..0000000 --- a/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to you under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FROM golang:1.12-alpine as base - -ENV DEV "" - -RUN apk --no-cache --no-progress add build-base git -RUN go get github.com/unchartedsoftware/witch -WORKDIR /source -ENTRYPOINT ["sh", "./entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index bb3889b..69c6c37 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,17 +15,61 @@ version: '3' services: - calcite-avatica-go: - build: . + phoenix: + image: boostport/hbase-phoenix-all-in-one:2.0-5.0 + + hsqldb: + image: apache/calcite-avatica-hypersql:1.13.0 + command: -u jdbc:hsqldb:mem:public + + test: + image: golang:1.12-alpine + command: sh -c "apk --no-cache --no-progress add build-base git; export AVATICA_FLAVOR=HSQLDB && go test -v ./...; export AVATICA_FLAVOR=PHOENIX && go test -v ./..." + working_dir: /source environment: PHOENIX_HOST: http://phoenix:8765 HSQLDB_HOST: http://hsqldb:8765 - DEV: ${DEV} volumes: - .:/source - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache - phoenix: - image: boostport/hbase-phoenix-all-in-one:2.0-5.0 - hsqldb: - image: apache/calcite-avatica-hypersql:1.13.0 - command: -u jdbc:hsqldb:mem:public \ No newline at end of file + depends_on: + - phoenix + - hsqldb + + dev: + image: golang:1.12-alpine + command: sh -c "apk --no-cache --no-progress add build-base git; go get github.com/unchartedsoftware/witch; cd /source; witch --cmd=\"export AVATICA_FLAVOR=HSQLDB && go test -v ./...; export AVATICA_FLAVOR=PHOENIX && go test -v ./...\" --watch=\"*.mod,**/*.go\"" + environment: + PHOENIX_HOST: http://phoenix:8765 + HSQLDB_HOST: http://hsqldb:8765 + volumes: + - .:/source + - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache + depends_on: + - phoenix + - hsqldb + + dry-run: + image: alpine + working_dir: /source + command: sh -c "apk --no-cache --no-progress add bash; ./docker.sh dry-run" + volumes: + - .:/source + - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache + + release: + image: alpine + + clean: + image: alpine + working_dir: /source + command: sh -c "apk --no-cache --no-progress add bash; ./docker.sh clean" + volumes: + - .:/source + - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache + + publish-release-for-voting: + image: alpine + + promote-release: + image: alpine \ No newline at end of file diff --git a/docker.sh b/docker.sh new file mode 100755 index 0000000..cef7f61 --- /dev/null +++ b/docker.sh @@ -0,0 +1,370 @@ +#!/bin/bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +GITBOX_URL=https://gitbox.apache.org/repos/asf/calcite-avatica-go.git + +init_release(){ + apk --no-cache add git gnupg tar +} + +KEYS=() + +GPG_COMMAND="gpg" + +get_gpg_keys (){ + GPG_KEYS=$($GPG_COMMAND --list-keys --with-colons --keyid-format LONG) + + KEY_NUM=1 + + KEY_DETAILS="" + + while read -r line; do + + IFS=':' read -ra PART <<< "$line" + + if [ ${PART[0]} == "pub" ]; then + + if [ -n "$KEY_DETAILS" ]; then + KEYS[$KEY_NUM]=$KEY_DETAILS + KEY_DETAILS="" + ((KEY_NUM++)) + + fi + + KEY_DETAILS=${PART[4]} + fi + + if [ ${PART[0]} == "uid" ]; then + KEY_DETAILS="$KEY_DETAILS - ${PART[9]}" + fi + + done <<< "$GPG_KEYS" + + if [ -n "$KEY_DETAILS" ]; then + KEYS[$KEY_NUM]=$KEY_DETAILS + fi +} + +mount_gpg_keys(){ + mkdir -p /.gnupg + + if [[ -z "$(ls -A /.gnupg)" ]]; then + echo "Please mount the contents of your .gnupg folder into /.gnupg. Exiting..." + exit 1 + fi + + mkdir -p /root/.gnupg + + cp -r /.gnupg/ /root/ + + chmod -R 700 /root/.gnupg/ + + rm -rf /root/.gnupg/*.lock +} + +SELECTED_GPG_KEY="" + +select_gpg_key(){ + + get_gpg_keys + + export GPG_TTY=/dev/console + + touch /root/.gnupg/gpg-agent.conf + echo 'default-cache-ttl 10000' >> /root/.gnupg/gpg-agent.conf + echo 'max-cache-ttl 10000' >> /root/.gnupg/gpg-agent.conf + + echo "Starting GPG agent..." + gpg-agent --daemon + + while $INVALID_KEY_SELECTED; do + + if [[ "${#KEYS[@]}" -le 0 ]]; then + echo "You do not have any GPG keys available. Exiting..." + exit 1 + fi + + echo "You have the following GPG keys:" + + for i in "${!KEYS[@]}"; do + echo "$i) ${KEYS[$i]}" + done + + read -p "Select your GPG key for signing: " KEY_INDEX + + SELECTED_GPG_KEY=$(sed 's/ -.*//' <<< ${KEYS[$KEY_INDEX]}) + + if [[ -z $SELECTED_GPG_KEY ]]; then + echo "Selected key is invalid, please try again." + continue + fi + + echo "Authenticating your GPG key..." + + echo "test" | $GPG_COMMAND --local-user $SELECTED_GPG_KEY --output /dev/null --sign - + + if [[ $? != 0 ]]; then + echo "Invalid GPG passphrase or GPG error. Please try again." + continue + fi + + echo "You have selected the following GPG key to sign the release:" + echo "${KEYS[$KEY_INDEX]}" + + INVALID_CONFIRMATION=true + + while $INVALID_CONFIRMATION; do + read -p "Is this correct? (y/n) " CONFIRM + + if [[ ($CONFIRM == "Y") || ($CONFIRM == "y") ]]; then + INVALID_KEY_SELECTED=false + INVALID_CONFIRMATION=false + elif [[ ($CONFIRM == "N") || ($CONFIRM == "n") ]]; then + INVALID_CONFIRMATION=false + fi + done + done +} + +check_release_guidelines(){ + + # Exclude files without the Apache license header + for i in $(git ls-files); do + case "$i" in + # The following are excluded from the license header check + + # License files + (LICENSE|NOTICE);; + + # Generated files + (message/common.pb.go|message/requests.pb.go|message/responses.pb.go|Gopkg.lock|Gopkg.toml|go.mod|go.sum);; + + # Binaries + (test-fixtures/calcite.png);; + + (*) grep -q "Licensed to the Apache Software Foundation" $i || echo "$i has no header";; + esac + done + + # Check copyright year in NOTICE + if ! grep -Fq "Copyright 2012-$(date +%Y)" NOTICE; then + echo "Ending copyright year in NOTICE is not $(date +%Y)" + exit 1 + fi + + # Check that Avatica versions in both gen-protobuf.bat and gen-protobuf.sh match + EXPECTED_AVATICA_VERSION=$(grep -o '^export AVATICA_VER="\K[^"]+' gen-protobuf.sh) + + if ! grep -Fq "SET AVATICA_VER=$EXPECTED_AVATICA_VERSION" gen-protobuf.bat; then + echo "AVATICA_VER in gen-protobuf.sh and gen-protobuf.bat does not match. Expected: $EXPECTED_AVATICA_VERSION" + exit 1 + fi +} + +check_if_tag_exists(){ + # Get new tags from remote + git fetch --tags $GITBOX_URL + + for tag in "$@" + do + # Check to see if a tag with a v in front of it has been released + if git show-ref --tags | egrep -q "refs/tags/v$tag$"; then + echo "A release with version $1 was already released. Check that the version number entered is correct." + exit 1 + fi + + # Check to see if a tag without a v in front of it has been released (3.0.0 and below) + if git show-ref --tags | egrep -q "refs/tags/$tag$"; then + echo "A release with version $1 was already released. Check that the version number entered is correct." + exit 1 + fi + done +} + +check_import_paths(){ + TAG_MAJOR_VERSION=$(echo $1 | sed -e 's/\..*//') + + # Check that go.mod's module path contains the right version + if ! grep -Fq "module github.com/apache/calcite-avatica-go/$TAG_MAJOR_VERSION" go.mod; then + echo "Module declaration in go.mod does not contain the correct version. Expected: $TAG_MAJOR_VERSION" + exit 1 + fi + + # Make sure import paths contain the correct version + badImportPaths=false + + for i in $(git ls-files); do + + if [[ "$i" == "docker.sh" || "$i" =~ \.md$ ]]; then + continue + fi + + lines=$(grep -F '"github.com/apache/calcite-avatica-go' $i) + + if ! [[ -z "$lines" ]]; then + while read -r line; do + if ! grep -q "github.com/apache/calcite-avatica-go/$TAG_MAJOR_VERSION" <<< "$line" ; then + badImportPaths=true + echo "Import for github.com/apache/calcite-avatica-go in $i does not have the correct version ($TAG_MAJOR_VERSION) in its path" + fi + done <<< "$lines" + fi + done + + if "$badImportPaths" == true; then + exit 1 + fi +} + +RELEASE_VERSION="" +RC_NUMBER="" +ASF_USERNAME="" +ASF_PASSWORD="" + +set_git_credentials(){ + read -s -p "Enter your ASF password: " ASF_PASSWORD + + printf "\n" + + echo https://$ASF_USERNAME:[email protected] >> /root/.git-credentials + git config --global credential.helper 'store --file=/root/.git-credentials' +} + +clean_release_directory(){ + rm -rf dist + mkdir -p dist +} + +make_release_artifacts(){ + + CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2) + + if [ $CURRENT_BRANCH != "master" ]; then + echo "You are currently on the $CURRENT_BRANCH branch. A release must be made from the master branch. Exiting..." + exit 1 + fi + + check_release_guidelines + + while $NOT_CONFIRMED; do + read -p "Enter the version number to be released (example: 4.0.0, do not include the rc number): " RELEASE_VERSION + read -p "Enter the release candidate number (example: if you are releasing rc0, enter 0): " RC_NUMBER + read -p "Enter your ASF username: " ASF_USERNAME + echo "Build configured as follows:" + echo "Release: $RELEASE_VERSION-rc$RC_NUMBER" + echo "ASF Username: $ASF_USERNAME" + + INVALID_CONFIRMATION=true + + while $INVALID_CONFIRMATION; do + read -p "Is this correct? (y/n) " CONFIRM + + if [[ ($CONFIRM == "Y") || ($CONFIRM == "y") ]]; then + NOT_CONFIRMED=false + INVALID_CONFIRMATION=false + elif [[ ($CONFIRM == "N") || ($CONFIRM == "n") ]]; then + INVALID_CONFIRMATION=false + fi + done + done + + select_gpg_key + + check_if_tag_exists $RELEASE_VERSION $RELEASE_VERSION-rc$RC_NUMBER + + TAG="v$RELEASE_VERSION-rc$RC_NUMBER" + + check_import_paths $TAG + + clean_release_directory + + PRODUCT=apache-calcite-avatica-go + TAR_FILE=$PRODUCT-$RELEASE_VERSION-src.tar.gz + RELEASE_DIR=dist/$PRODUCT-$RELEASE_VERSION-rc$RC_NUMBER + + #Make release dir + mkdir -p $RELEASE_DIR + + # Make tar + tar -zcf $RELEASE_DIR/$TAR_FILE --transform "s/^/$PRODUCT-$RELEASE_VERSION-src\//g" $(git ls-files) + + cd $RELEASE_DIR + + # Calculate SHA512 + gpg --print-md SHA512 $TAR_FILE > $TAR_FILE.sha512 + + # Sign + gpg -u $SELECTED_GPG_KEY --armor --output $TAR_FILE.asc --detach-sig $TAR_FILE + + echo "Release artifacts created!" +} + +make_release_artifacts_and_push_tag(){ + make_release_artifacts + + # Create the tag + git tag $TAG + + # Push the tag + set_git_credentials + + git push $GITBOX_URL $TAG + + echo "Release $RELEASE_VERSION-rc$RC_NUMBER has been tagged and pushed!" +} + +publish_artifacts_for_voting(){ +echo "empty" +} + +promote_release(){ +echo "empty" +} + +case $1 in + dry-run) + init_release + mount_gpg_keys + make_release_artifacts + ;; + + release) + init_release + mount_gpg_keys + make_release_artifacts_and_push_tag + ;; + + clean) + clean_release_directory + echo "Release directory ./dist removed" + ;; + + upload-artifacts-for-voting) + echo "empty" + ;; + + promote-release) + echo "empety" + ;; + + *) + echo $"Usage: $0 {dry-run|release|clean|upload-artifacts-for-voting|promote-release}" + ;; + +esac + +# End \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 0d061fd..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to you under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -TEST_COMMAND="export AVATICA_FLAVOR=HSQLDB && go test -v ./...; export AVATICA_FLAVOR=PHOENIX && go test -v ./..." - -if [[ -z "${DEV}" ]]; then - sh -c "$TEST_COMMAND" -else - witch --cmd="$TEST_COMMAND" --watch="*.mod,**/*.go" -fi \ No newline at end of file diff --git a/make-release-artifacts.sh b/make-release-artifacts.sh deleted file mode 100755 index 6051880..0000000 --- a/make-release-artifacts.sh +++ /dev/null @@ -1,187 +0,0 @@ -#!/bin/bash - -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to you under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Clean dist directory -rm -rf dist -mkdir -p dist - -# Get new tags from remote -git fetch --tags - -# Prompt for tag to release (defaults to latest tag) -echo -n "Enter tag to release (default: latest tag): " -read tag - -if [[ -z $tag ]]; then - tag=$(git describe --tags `git rev-list --tags --max-count=1`) - echo "No tag provided. Using the latest tag: $tag" -fi - -# Exclude files without the Apache license header -for i in $(git ls-files); do - case "$i" in - # The following are excluded from the license header check - - # License files - (LICENSE|NOTICE);; - - # Generated files - (message/common.pb.go|message/requests.pb.go|message/responses.pb.go|Gopkg.lock|Gopkg.toml|go.mod|go.sum);; - - # Binaries - (test-fixtures/calcite.png);; - - (*) grep -q "Licensed to the Apache Software Foundation" $i || echo "$i has no header";; - esac -done - -# Check copyright year in NOTICE -if ! grep -Fq "Copyright 2012-$(date +%Y)" NOTICE; then - echo "Ending copyright year in NOTICE is not $(date +%Y)" - exit 1 -fi - -tagMajorVersion=$(echo $tag | sed -e 's/\..*//') - -# Check that go.mod's module path contains the right version -if ! grep -Fq "module github.com/apache/calcite-avatica-go/$tagMajorVersion" go.mod; then - echo "module declaration in go.mod does not contain the correct version. Expected: $tagMajorVersion" - exit 1 -fi - -# Make sure import paths contain the correct version -badImportPaths=false - -for i in $(git ls-files); do - - if [[ "$i" == "make-release-artifacts.sh" || "$i" =~ \.md$ ]]; then - continue - fi - - lines=$(grep -F '"github.com/apache/calcite-avatica-go' $i) - - if ! [[ -z "$lines" ]]; then - while read -r line; do - if ! grep -q "github.com/apache/calcite-avatica-go/$tagMajorVersion" <<< "$line" ; then - badImportPaths=true - echo "import for github.com/apache/calcite-avatica-go in $i does not have the correct version ($tagMajorVersion) in its path" - fi - done <<< "$lines" - fi -done - -if "$badImportPaths" == true; then - exit 1 -fi - -# Check that Avatica versions in both gen-protobuf.bat and gen-protobuf.sh match -EXPECTED_AVATICA_VERSION=$(grep -oP '^export AVATICA_VER="\K[^"]+' gen-protobuf.sh) - -if ! grep -Fq "SET AVATICA_VER=$EXPECTED_AVATICA_VERSION" gen-protobuf.bat; then - echo "AVATICA_VER in gen-protobuf.sh and gen-protobuf.bat does not match. Expected: $EXPECTED_AVATICA_VERSION" - exit 1 -fi - -tagWithoutV=$(echo $tag | sed -e 's/v//') -tagWithoutRC=$(echo $tagWithoutV | sed -e 's/-rc[0-9][0-9]*//') -product=apache-calcite-avatica-go -tarFile=$product-$tagWithoutRC-src.tar.gz -releaseDir=dist/$product-$tagWithoutV - -#Make release dir -mkdir -p $releaseDir - -# Checkout tag -if ! git checkout $tag; then - echo "Could not check out tag $tag. Does it exist?" - exit 1 -fi - -# Make tar -tar -zcf $releaseDir/$tarFile --transform "s/^/$product-$tagWithoutRC-src\//g" $(git ls-files) - -cd $releaseDir - -# Calculate SHA512 -gpg --print-md SHA512 $tarFile > $tarFile.sha512 - -# Select GPG key for signing -KEYS=() - -GPG_COMMAND="gpg2" - -get_gpg_keys (){ - GPG_KEYS=$($GPG_COMMAND --list-keys --with-colons --keyid-format LONG) - - KEY_NUM=1 - - KEY_DETAILS="" - - while read -r line; do - - IFS=':' read -ra PART <<< "$line" - - if [ ${PART[0]} == "pub" ]; then - - if [ -n "$KEY_DETAILS" ]; then - KEYS[$KEY_NUM]=$KEY_DETAILS - KEY_DETAILS="" - ((KEY_NUM++)) - - fi - - KEY_DETAILS=${PART[4]} - fi - - if [ ${PART[0]} == "uid" ]; then - KEY_DETAILS="$KEY_DETAILS - ${PART[9]}" - fi - - done <<< "$GPG_KEYS" - - if [ -n "$KEY_DETAILS" ]; then - KEYS[$KEY_NUM]=$KEY_DETAILS - fi -} - -get_gpg_keys - -if [ "${#KEYS[@]}" -le 0 ]; then - echo "You do not have any GPG keys available. Exiting..." - exit 1 -fi - -echo "You have the following GPG keys:" - -for i in "${!KEYS[@]}"; do - echo "$i) ${KEYS[$i]}" -done - -read -p "Select your GPG key for signing: " KEY_INDEX - -GPG_KEY=$(sed 's/ -.*//' <<< ${KEYS[$KEY_INDEX]}) - -if [ -z $GPG_KEY ]; then - echo "Selected key is invalid. Exiting..." - exit 1 -fi - -# Sign -gpg -u $GPG_KEY --armor --output $tarFile.asc --detach-sig $tarFile - -echo "Release created!" -# End \ No newline at end of file diff --git a/site/develop/avatica-go.md b/site/develop/avatica-go.md index fd6faca..5fe11ec 100644 --- a/site/develop/avatica-go.md +++ b/site/develop/avatica-go.md @@ -45,7 +45,9 @@ during development allows us to not have to manually execute the test suite on s ### Set up 1. Install [docker](https://docs.docker.com/install/) and [docker-compose](https://docs.docker.com/compose/install/). -2. From the root of the repository, run `DEV=true docker-compose up --build`. +2. From the root of the repository, run `docker-compose run --rm dev`. + +3. After terminating the container, stop the database containers and remove them using: `docker-compose down` ## Testing @@ -54,7 +56,9 @@ The test suite takes around 4 minutes to run if you run both the Avatica HSQLDB ### Easy way 1. Install [docker](https://docs.docker.com/install/) and [docker-compose](https://docs.docker.com/compose/install/). -2. From the root of the repository, run `docker-compose up --build --abort-on-container-exit`. +2. From the root of the repository, run `docker-compose run --rm test`. + +3. After the tests complete, stop the database containers and remove them using: `docker-compose down` ### Manual set up 1. Install [Go](https://golang.org/doc/install).
