Skip to content

Commit

Permalink
Add a local releasing test thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridai Govinda Pombo committed Jul 30, 2020
1 parent 02b46f5 commit f220754
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 42 deletions.
20 changes: 20 additions & 0 deletions .yourbase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ build_targets:
- pip install awscli
- bash release.sh

- name: local_test_release
build_after:
- default
host_only: true
environment:
- TEST_RELEASE=test_me
- AWS_ACCESS_KEY_ID=only_smeagle_knows
- AWS_SECRET_ACCESS_KEY=only_smeagle_knows
- RELEASE_KEY=not known
- RELEASE_TOKEN=also unknown
- YB_GIT_BRANCH=refs/tags/v0.0.0-rc0
commands:
- pip install awscli
- bash release.sh
- rm -f yb
- tar xf release/yb-linux-amd64-v0.0.0-rc0.tgz
- mv yb-linux-amd64 yb
- ls -lh yb
- ./yb version

- name: linux
build_after:
- default
Expand Down
87 changes: 45 additions & 42 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,37 @@ else
CHANNEL="stable"
fi

local_test_release="${2:-}"

if [ -z "${local_test_release}" ]; then
# YourBase S3 artifacts Release
# TODO migrate to CATS
aws_disabled=true
[ -n "${AWS_ACCESS_KEY_ID}" -a -n "${AWS_SECRET_ACCESS_KEY}" ] && aws_disabled=false
if $aws_disabled; then
echo "No AWS credentials, probably in Staging/Preview, giving up"
# Non fatal, we won't get GH status errors when trying to release on Staging/Preview
exit 0
fi
local_test_release="${TEST_RELEASE:-}"

# YourBase S3 artifacts Release
# TODO migrate to CATS
AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID:-}"
AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY:-}"
aws_disabled=true
[ -n "${AWS_ACCESS_KEY_ID}" -a -n "${AWS_SECRET_ACCESS_KEY}" ] && aws_disabled=false
if $aws_disabled; then
echo "No AWS credentials, probably in Staging/Preview, giving up"
# Non fatal, we won't get GH status errors when trying to release on Staging/Preview
exit 0
fi

# Commit info
COMMIT="-"
if [ -z "${local_test_release}" ]; then
COMMIT="${YB_GIT_COMMIT}"
else
COMMIT="${YB_GIT_COMMIT:-}"
if [ -z "${COMMIT}" ]; then
# If git is installed
if hash git; then
COMMIT="$(git rev-list -n1 HEAD)"
fi
fi

BUILD_COMMIT_INFO=""
if [ "${COMMIT}" != "-" ]; then
if [ -n "${COMMIT}" ]; then
BUILD_COMMIT_INFO=" -X 'main.commitSHA=$COMMIT'"
fi

umask 077

echo "Releasing ${CHANNEL} yb version ${VERSION}..."
echo "Releasing ${CHANNEL} yb version ${VERSION} [${COMMIT}]..."

set -x

Expand All @@ -67,7 +65,7 @@ for os in "${OSLIST[@]}"
do
for arch in "${ARCHLIST[@]}"
do
GOOS=${os} GOARCH=${arch} go build -ldflags "-X 'main.version=$VERSION' -X 'main.date=$(date)' -X 'main.channel=$CHANNEL'${BUILD_COMMIT_INFO}" -o release/yb-${os}-${arch}
GOOS=${os} GOARCH=${arch} go build -ldflags "-X 'main.version=$VERSION' -X 'main.date=$(date -u '+%F-%T')' -X 'main.channel=$CHANNEL'${BUILD_COMMIT_INFO}" -o release/yb-${os}-${arch}
done
done

Expand All @@ -80,18 +78,22 @@ done
rm $i
done

if [ -z "${local_test_release}" ]; then
for i in *.tgz
do
aws s3 ls s3://yourbase-artifacts/yb/${VERSION}/$i
if [[ $? -eq 0 ]]; then
echo "A version for ${VERSION} already exists! Not releasing this version."
exit 1
if [ -z "${local_test_release}" ]; then
aws s3 ls s3://yourbase-artifacts/yb/${VERSION}/$i
if [[ $? -eq 0 ]]; then
echo "A version for ${VERSION} already exists! Not releasing this version."
exit 1
fi

aws s3 cp $i s3://yourbase-artifacts/yb/${VERSION}/
else
echo "Local test, would run:"
echo aws s3 ls s3://yourbase-artifacts/yb/${VERSION}/$i
echo aws s3 cp $i s3://yourbase-artifacts/yb/${VERSION}/
fi

aws s3 cp $i s3://yourbase-artifacts/yb/${VERSION}/
done
fi
)

# Equinox install procedure
Expand All @@ -106,6 +108,7 @@ cleanup() {
set -x
rv=$?
rm -rf "$tmpkeyfile"
rm -rf equinox release-tool-stable-linux-amd64.tgz
exit $rv
}

Expand All @@ -116,9 +119,21 @@ KEY_FILE="${tmpkeyfile}"

equinox_disabled=true

[ -n "${RELEASE_KEY}" -a -n "${TOKEN}" ] && equinox_disabled=false
if $equinox_disabled; then
echo "No Equinox credentials, probably in Staging/Preview, giving up"
# Non fatal, we won't get GH status errors when trying to release on Staging/Preview
exit 0
fi

echo "${RELEASE_KEY}" > "${KEY_FILE}"

wget https://bin.equinox.io/c/mBWdkfai63v/release-tool-stable-linux-amd64.tgz
tar zxvf release-tool-stable-linux-amd64.tgz

if [ -n "${local_test_release}" ]; then
set +x
echo -e "Would run:
echo -e "Local test, would run:
./equinox release
--version=$VERSION
--platforms='darwin_amd64 linux_amd64'
Expand All @@ -127,24 +142,12 @@ if [ -n "${local_test_release}" ]; then
--token='${TOKEN}'
--channel='${CHANNEL}'
--
-ldflags '-X main.version=$VERSION -X 'main.date=$(date)' -X 'main.channel=$CHANNEL'${BUILD_COMMIT_INFO}'
-ldflags '-X main.version=$VERSION -X 'main.date=$(date -u '+%F-%T')' -X 'main.channel=$CHANNEL'${BUILD_COMMIT_INFO}'
'github.com/yourbase/${PROJECT}'"

exit 0
fi

[ -n "${RELEASE_KEY}" -a -n "${TOKEN}" ] && equinox_disabled=false
if $equinox_disabled; then
echo "No Equinox credentials, probably in Staging/Preview, giving up"
# Non fatal, we won't get GH status errors when trying to release on Staging/Preview
exit 0
fi

echo "${RELEASE_KEY}" > "${KEY_FILE}"

wget https://bin.equinox.io/c/mBWdkfai63v/release-tool-stable-linux-amd64.tgz
tar zxvf release-tool-stable-linux-amd64.tgz

./equinox release \
--version=$VERSION \
--platforms="darwin_amd64 linux_amd64" \
Expand All @@ -153,6 +156,6 @@ tar zxvf release-tool-stable-linux-amd64.tgz
--token="${TOKEN}" \
--channel="${CHANNEL}" \
-- \
-ldflags "-X main.version=$VERSION -X 'main.date=$(date)' -X 'main.channel=$CHANNEL'${BUILD_COMMIT_INFO}" \
-ldflags "-X main.version=$VERSION -X 'main.date=$(date -u '+%F-%T')' -X 'main.channel=$CHANNEL'${BUILD_COMMIT_INFO}" \
"github.com/yourbase/${PROJECT}"

0 comments on commit f220754

Please sign in to comment.