-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean buildscript and add bintray release
- Loading branch information
1 parent
f85fed9
commit 45ac5e3
Showing
4 changed files
with
219 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters