From 1c569ef783e8e0bc4e9ab4d64f53a7f7d3bfadab Mon Sep 17 00:00:00 2001 From: Jamal Kaabi-Mofrad Date: Tue, 12 Nov 2019 13:31:33 +0000 Subject: [PATCH] AUTH-420: Added scripts to build and release alfresco theme. (#8) --- .gitignore | 5 +++ Dockerfile | 3 -- build.properties | 1 + build.sh | 20 ++++++++++ release.sh | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 3 deletions(-) delete mode 100644 Dockerfile create mode 100644 build.properties create mode 100644 build.sh create mode 100644 release.sh diff --git a/.gitignore b/.gitignore index fd19ea9..6449b5c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,11 @@ *.iml *.iws +# Package Files # +*.jar +*.zip +*.tar.gz + # Visual Studio Code .vscode/ diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4f6c2e5..0000000 --- a/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM busybox -RUN mkdir /alfresco -COPY theme /alfresco diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..b7633e6 --- /dev/null +++ b/build.properties @@ -0,0 +1 @@ +THEME_VERSION=0.1 \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..8b21b63 --- /dev/null +++ b/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -o errexit + +declare -r currentDir="$(dirname "${BASH_SOURCE[0]}")" +source "${currentDir}/build.properties" + +DISTRIBUTION_NAME=alfresco-keycloak-theme-$THEME_VERSION + +# prepare and zip the theme content +echo "info::: Removing an existing '$DISTRIBUTION_NAME.zip' file." +rm -rf $DISTRIBUTION_NAME.zip + +mkdir alfresco +echo "info::: Packaging alfresco theme as '$DISTRIBUTION_NAME.zip'" + +cp -rf theme/* alfresco/ +zip -r $DISTRIBUTION_NAME.zip alfresco + +echo "info::: Cleanup temp files and folders." +rm -rf alfresco diff --git a/release.sh b/release.sh new file mode 100644 index 0000000..f568fa6 --- /dev/null +++ b/release.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# Available parameters: +# - username +# - paasword +# - prerelease +# +# Example: +# release.sh username=johndoe password=pass prerelease=true +# + +set -o errexit + +declare -r currentDir="$(dirname "${BASH_SOURCE[0]}")" +source "${currentDir}/build.properties" + +log_info() { + echo "info::: $1" +} + +log_error() { + echo "error::: $1" + exit 1 +} + +ARGS=$@ +for arg in $ARGS; do + eval "$arg" +done + +REPO_URL="https://api.github.com/repos/Alfresco/alfresco-keycloak-theme" +TAG_URL="$REPO_URL/releases/tags/$THEME_VERSION" +AUTH="$username:$password" +PRE_RELEASE="${prerelease:-false}" +DISTRIBUTION_NAME="alfresco-keycloak-theme-$THEME_VERSION.zip" + +if [ ! -f "$DISTRIBUTION_NAME" ]; then + log_error "$DISTRIBUTION_NAME does not exist." +fi + +log_info "Tag the current branch as $THEME_VERSION" +git tag "$THEME_VERSION" + +log_info "Push $THEME_VERSION tag." +git push origin "$THEME_VERSION" + +log_info "Create $THEME_VERSION release..." +STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$RELEASES_URL" -u "$AUTH" \ + -H 'Content-Type: application/json' \ + -d "{ + \"tag_name\": \"$THEME_VERSION\", + \"name\": \"$THEME_VERSION\", + \"draft\": false, + \"prerelease\": $PRE_RELEASE +}") + +if [ $STATUS_CODE -eq "201"]; then + log_info "$THEME_VERSION has been released successfully." +else + log_error "Couldn't release $THEME_VERSION. Status Code: $STATUS_CODE" +fi + +WAIT_COUNTER=0 +WAIT_COUNTER_MAX=10 +WAIT_SLEEP_SECONDS=2 +while [ "$WAIT_COUNTER" -lt "$WAIT_COUNTER_MAX" ]; do + STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$TAGS_URL" -u "$AUTH") + if [ $STATUS_CODE -eq "200" ]; then + log_info "$THEME_VERSION release has been published." + break + fi + log_info "Waiting for $THEME_VERSION release to be published..." + WAIT_COUNTER=$((WAIT_COUNTER + 1)) + sleep "$WAIT_SLEEP_SECONDS" + continue +done + +# check credentials +STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" $REPO_URL -u "$AUTH") +if [ $STATUS_CODE -eq "401" ] || [ $STATUS_CODE -eq "404" ]; then + log_error "Bad credentials. Status Code: $STATUS_CODE" +fi + +# Get upload_url +log_info "Getting upload asset URL from: $TAG_URL" +UPLOAD_URL=$(curl -s "$TAG_URL" -u "$AUTH") | jq -r ".upload_url" | cut -d'{' -f 1 + +log_info "Upload asset URL is: '$UPLOAD_URL'" + +if [ -z "$UPLOAD_URL" ]; then + log_error "upload_url is not found." +fi + +log_info "Uploading '$DISTRIBUTION_NAME' asset... " + +# Add asset name to the URL +UPLOAD_ASSET_URL="$UPLOAD_URL?name=$(basename $DISTRIBUTION_NAME)" +# Upload asset +curl $UPLOAD_ASSET_URL -u "$AUTH" -H "Content-Type: application/octet-stream" -F "file=@$DISTRIBUTION_NAME"