Skip to content

Commit

Permalink
AUTH-420: Added scripts to build and release alfresco theme. (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalkm authored Nov 12, 2019
1 parent b60871d commit 1c569ef
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*.iml
*.iws

# Package Files #
*.jar
*.zip
*.tar.gz

# Visual Studio Code
.vscode/

Expand Down
3 changes: 0 additions & 3 deletions Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THEME_VERSION=0.1
20 changes: 20 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
99 changes: 99 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 1c569ef

Please sign in to comment.