Skip to content

Commit

Permalink
Clean buildscript and add bintray release
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Sep 20, 2020
1 parent f85fed9 commit 45ac5e3
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 12 deletions.
93 changes: 93 additions & 0 deletions .github/actions/tools/bintray.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

# bintray_createPackage [REPO] [PACKAGE] [USER] [PASSWORD] [GIT REPO] [LICENSE]
function bintray_createPackage {
repo="$1"
package="$2"
user="$3"
password="$4"
srcrepo="$5"
license="$6"

repoUrl="https://api.bintray.com/packages/$repo"
if [ "`curl -u$user:$password -H Content-Type:application/json -H Accept:application/json \
--write-out %{http_code} --silent --output /dev/null -X GET \"$repoUrl/$package\"`" != "200" ];
then

if [ "$srcrepo" != "" -a "$license" != "" ];
then
echo "Package does not exist... create."
data="{
\"name\": \"${package}\",
\"labels\": [],
\"licenses\": [\"${license}\"],
\"vcs_url\": \"${srcrepo}\"
}"


curl -u$user:$password -H "Content-Type:application/json" -H "Accept:application/json" -X POST \
-d "${data}" "$repoUrl"
else
echo "Package does not exist... you need to specify a repo and license for it to be created."
fi
else
echo "The package already exists. Skip."
fi
}

# uploadFile file destination [REPO] "content" [PACKAGE] [USER] [PASSWORD] [SRCREPO] [LICENSE]
function bintray_uploadFile {
file="$1"
dest="$2"

echo "Upload $file to $dest"

repo="$3"
type="$4"
package="$5"

user="$6"
password="$7"

srcrepo="$8"
license="$9"
publish="${10}"

bintray_createPackage $repo $package $user $password $srcrepo $license

url="https://api.bintray.com/$type/$repo/$package/$dest"
if [ "$publish" = "true" ]; then url="$url;publish=1"; fi

curl -T "$file" -u$user:$password "$url"

}

function bintray_uploadAll {
path="$1"
destpath="$2"
repo="$3"
type="$4"
package="$5"

user="$6"
password="$7"

srcrepo="$8"
license="$9"
publish="${10}"

cdir="$PWD"
cd "$path"

files="`find . -type f -print`"
IFS="
"
set -f
for f in $files; do
destfile="$destpath/${f:2}"
bintray_uploadFile $f $destfile $repo $type $package $user $password $srcrepo $license $publish
done
set +f
unset IFS
cd "$cdir"
}
85 changes: 85 additions & 0 deletions .github/actions/tools/uploadToMaven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash
#############################################
#
# Usage
# uploadAllToMaven path/of/dist/maven https://api.bintray.com/maven/riccardo/sandbox-maven/ riccardo $BINTRAY_PASSWORD gitrepo license
# Note: gitrepo and license are needed only when uploading to bintray if you want to create missing packages automatically
# gitrepo must be a valid source repository
# license must be a license supported by bintray eg "BSD 3-Clause"
# or
# uploadAllToMaven path/of/dist/maven $GITHUB_PACKAGE_REPOSITORY user password
#
#############################################
root="`dirname ${BASH_SOURCE[0]}`"
source $root/bintray.sh

set -e
function uploadToMaven {
file="$1"
destfile="$2"
repourl="$3"
user="$4"
password="$5"
srcrepo="$6"
license="$7"

auth=""

if [ "$user" != "token" ];
then
echo "Upload with username $user and password"
auth="-u$user:$password"
else
echo "Upload with token"
auth="-H \"Authorization: token $password\""
fi


if [[ $repourl == https\:\/\/api.bintray.com\/* ]];
then
package="`dirname $destfile`"
version="`basename $package`"
package="`dirname $package`"
package="`basename $package`"

if [ "$user" = "" -o "$password" = "" ];
then
echo "Error! You need username and password to upload to bintray"
exit 1
fi
echo "Detected bintray"

bintrayRepo="${repourl/https\:\/\/api.bintray.com\/maven/}"
echo "Create package on $bintrayRepo"

bintray_createPackage $bintrayRepo $package $user $password $srcrepo $license

repourl="$repourl/$package"
fi

cmd="curl -T \"$file\" $auth \
\"$repourl/$destfile\" \
-vvv"

echo "Run $cmd"
eval "$cmd"
}
export -f uploadToMaven

function uploadAllToMaven {
path="$1"
cdir="$PWD"
cd "$path"
files="`find . \( -name "*.jar" -o -name "*.pom" \) -type f -print`"
IFS="
"
set -f
for art in $files; do
art="${art:2}"
uploadToMaven "$art" "$art" ${@:2}
done
set +f
unset IFS

cd "$cdir"
}
42 changes: 35 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,60 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Java CI with Gradle
name: Build and Deploy

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

release:
types: [published]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

with:
fetch-depth: 1

- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Build with Gradle
run: gradle build testJar
run: |
export VERSION="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`"
if [ "$VERSION" = "" ];
then
branch="`if [[ $GITHUB_REF == refs\/heads* ]]; then echo ${GITHUB_REF//refs\/heads\//}; fi`"
export VERSION="$branch-SNAPSHOT"
fi

mkdir -p dist/maven
gradle -Pin_version="$VERSION" build testJar install -Dmaven.repo.local="$PWD/dist/maven"


- uses: actions/upload-artifact@v2
with:
name: build-out
path: build/libs

- uses: actions/upload-artifact@v2
with:
name: maven
path: dist/maven

- name: Deploy to bintray
if: github.event_name == 'release'
run: |
source .github/actions/tools/uploadToMaven.sh
if [ "${{ secrets.BINTRAY_MAVEN_REPO }}" = "" ];
then
echo "Configure the following secrets to enable bintray deployment"
echo "BINTRAY_MAVEN_REPO, BINTRAY_USER, BINTRAY_APIKEY"
else
uploadAllToMaven dist/maven/ https://api.bintray.com/maven/${{ secrets.BINTRAY_MAVEN_REPO }} ${{ secrets.BINTRAY_USER }} ${{ secrets.BINTRAY_APIKEY }} "https://github.com/${GITHUB_REPOSITORY}" "${{ secrets.BINTRAY_LICENSE }}"
fi
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ apply plugin: 'maven'
apply plugin: 'java-library'


group = "com.jme.effekseer"
version= project.hasProperty('in_version') ? project.getProperty('in_version') : '-SNAPSHOT'

targetCompatibility = '1.8'
sourceCompatibility = '1.8'

repositories {
jcenter()
maven {
Expand All @@ -16,12 +22,7 @@ dependencies {
api "effekseer:effekseer-native:jme1.1.6"

compileOnly "org.jmonkeyengine:jme3-core:3.2.3-stable"
compileOnly "org.jmonkeyengine:jme3-lwjgl:3.2.3-stable"
compileOnly "org.jmonkeyengine:jme3-desktop:3.2.3-stable"
compileOnly "org.jmonkeyengine:jme3-bullet:3.2.3-stable"
compileOnly "org.jmonkeyengine:jme3-effects:3.2.3-stable"
compileOnly "org.jmonkeyengine:jme3-plugins:3.2.3-stable"
compileOnly "org.jmonkeyengine:jme3-bullet-native:3.2.3-stable"

testImplementation 'com.github.polincdev:JesseModel:-SNAPSHOT'
testImplementation "org.jmonkeyengine:jme3-core:3.2.3-stable"
Expand Down

0 comments on commit 45ac5e3

Please sign in to comment.