Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal build on pull request, closes #11 #27

Merged
merged 2 commits into from
Sep 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 51 additions & 43 deletions ci-script.sh
Original file line number Diff line number Diff line change
@@ -1,68 +1,76 @@
#!/bin/bash

if [ -z $REG_USER ]; then echo "REG_USER not set"; exit 1; fi
if [ -z $REG_PASS ]; then echo "REG_PASS not set"; exit 1; fi
if [ -z $GITHUB_USER ]; then echo "GITHUB_USER not set"; exit 1; fi
if [ -z $GITHUB_PASS ]; then echo "GITHUB_PASS not set"; exit 1; fi
if [ -z $BINTRAY_USER ]; then echo "BINTRAY_USER not set"; exit 1; fi
if [ -z $BINTRAY_KEY ]; then echo "BINTRAY_KEY not set"; exit 1; fi
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
# only require these variables if building off the main repo
if [ -z $REG_USER ]; then echo "REG_USER not set"; exit 1; fi
if [ -z $REG_PASS ]; then echo "REG_PASS not set"; exit 1; fi
if [ -z $GITHUB_USER ]; then echo "GITHUB_USER not set"; exit 1; fi
if [ -z $GITHUB_PASS ]; then echo "GITHUB_PASS not set"; exit 1; fi
if [ -z $BINTRAY_USER ]; then echo "BINTRAY_USER not set"; exit 1; fi
if [ -z $BINTRAY_KEY ]; then echo "BINTRAY_KEY not set"; exit 1; fi
fi

DOCKER_PUSH_ENABLED=1
BINTRAY_UPLOAD_ENABLED=1
GITHUB_RELEASE_ENABLED=1

set -e
if [ $DOCKER_PUSH_ENABLED = 1 ]; then
if [ "$TRAVIS_PULL_REQUEST" = "false" -a $DOCKER_PUSH_ENABLED = 1 ]; then
echo "$REG_PASS" | docker login -u $REG_USER --password-stdin
fi

set -x
app_ver=$(mvn -B help:evaluate -Dexpression=project.version -q -DforceStdout)
echo Kafdrop version $app_ver
mvn -B clean integration-test package assembly:single docker:build
if [ $DOCKER_PUSH_ENABLED = 1 ]; then
docker push docker.io/obsidiandynamics/kafdrop:$app_ver
fi

repo_url=https://api.github.com/repos/obsidiandynamics/kafdrop
if [[ ! $app_ver =~ "-SNAPSHOT" ]]; then
echo "Release version"
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
if [ $DOCKER_PUSH_ENABLED = 1 ]; then
docker push docker.io/obsidiandynamics/kafdrop:latest
docker push docker.io/obsidiandynamics/kafdrop:$app_ver
fi

if [ $GITHUB_RELEASE_ENABLED = 1 ]; then
set +x
get_release_status=$(curl -u $GITHUB_USER:$GITHUB_PASS -s -o /dev/null -w "%{http_code}" $repo_url/releases/tags/$app_ver)
set -x
echo "Release tag query status code: $get_release_status"
if [ $get_release_status == "404" ]; then
echo "Publishing release"
release_json="{ \
\"tag_name\": \"$app_ver\", \
\"target_commitish\": \"master\", \
\"name\": \"$app_ver\", \
\"body\": \"Download from [Bintray](https://bintray.com/obsidiandynamics/kafdrop/download_file?file_path=com%2Fobsidiandynamics%2Fkafdrop%2Fkafdrop%2F${app_ver}%2Fkafdrop-${app_ver}.jar)\", \
\"draft\": false, \
\"prerelease\": false \
}"
repo_url=https://api.github.com/repos/obsidiandynamics/kafdrop
if [[ ! $app_ver =~ "-SNAPSHOT" ]]; then
echo "Release version"
if [ $DOCKER_PUSH_ENABLED = 1 ]; then
docker push docker.io/obsidiandynamics/kafdrop:latest
fi

if [ $GITHUB_RELEASE_ENABLED = 1 ]; then
set +x
curl -u $GITHUB_USER:$GITHUB_PASS -X POST $repo_url/releases -d "$release_json"
elif [ $get_release_status == "200" ]; then
echo "Release already exists; skipping"
else
echo "Unexpected error checking release status: $get_release_status"
exit 1
get_release_status=$(curl -u $GITHUB_USER:$GITHUB_PASS -s -o /dev/null -w "%{http_code}" $repo_url/releases/tags/$app_ver)
set -x
echo "Release tag query status code: $get_release_status"
if [ $get_release_status == "404" ]; then
echo "Publishing release"
release_json="{ \
\"tag_name\": \"$app_ver\", \
\"target_commitish\": \"master\", \
\"name\": \"$app_ver\", \
\"body\": \"Download from [Bintray](https://bintray.com/obsidiandynamics/kafdrop/download_file?file_path=com%2Fobsidiandynamics%2Fkafdrop%2Fkafdrop%2F${app_ver}%2Fkafdrop-${app_ver}.jar)\", \
\"draft\": false, \
\"prerelease\": false \
}"
set +x
curl -u $GITHUB_USER:$GITHUB_PASS -X POST $repo_url/releases -d "$release_json"
elif [ $get_release_status == "200" ]; then
echo "Release already exists; skipping"
else
echo "Unexpected error checking release status: $get_release_status"
exit 1
fi
fi
fi

if [ $BINTRAY_UPLOAD_ENABLED = 1 ]; then
set +x
curl -X DELETE https://api.bintray.com/packages/obsidiandynamics/kafdrop/main/versions/$app_ver -u ${BINTRAY_USER}:${BINTRAY_KEY} || echo Skipped 'delete'
cat settings.xml.template | sed "s/{{BINTRAY_USER}}/${BINTRAY_USER}/g" | sed "s/{{BINTRAY_KEY}}/${BINTRAY_KEY}/g" > settings.xml
set -x
mvn -B deploy -s settings.xml
if [ $BINTRAY_UPLOAD_ENABLED = 1 ]; then
set +x
curl -X DELETE https://api.bintray.com/packages/obsidiandynamics/kafdrop/main/versions/$app_ver -u ${BINTRAY_USER}:${BINTRAY_KEY} || echo Skipped 'delete'
cat settings.xml.template | sed "s/{{BINTRAY_USER}}/${BINTRAY_USER}/g" | sed "s/{{BINTRAY_KEY}}/${BINTRAY_KEY}/g" > settings.xml
set -x
mvn -B deploy -s settings.xml
fi
else
echo "Snapshot version"
fi
else
echo "Snapshot version"
echo "Pull request detected; reverting to a minimal build"
fi