Skip to content

Commit

Permalink
Refactor build + add publish script
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Aug 21, 2024
1 parent 7154bdc commit ec3062e
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 4 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,23 @@ jobs:
- name: Tests
run: |
./gradlew check
- name: Release
if: "contains(github.event.head_commit.message, '[release]')"
run: |
bash publish.sh unsafe-tracker
env:
GRADLE_OPTS: '-Dorg.gradle.daemon=false'
AWS_ACCESS_KEY_ID: ${{secrets.TOWER_CI_AWS_ACCESS}}
AWS_SECRET_ACCESS_KEY: ${{secrets.TOWER_CI_AWS_SECRET}}
AWS_DEFAULT_REGION: 'eu-west-1'
PUBLISH_REPO_URL: "s3://maven.seqera.io/releases"

- name: Publish tests report
if: failure()
uses: actions/upload-artifact@v3
with:
name: test-reports-jdk-${{ matrix.java_version }}
path: |
**/build/reports/tests/test
...
20 changes: 20 additions & 0 deletions app/build.gradle → build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id "com.github.johnrengelman.shadow" version "8.1.1"
id 'maven-publish'
}

repositories {
Expand Down Expand Up @@ -46,6 +47,7 @@ tasks.named('test') {
useJUnitPlatform()
}

group = 'io.seqera'
version = rootProject.file('VERSION').text.trim()

application {
Expand All @@ -68,3 +70,21 @@ shadowJar {
)
}
}

publishing {
repositories {
maven {
name = "SeqeraRepository"
url = project.findProperty('publish_repo_url') ?: System.getenv('PUBLISH_REPO_URL') ?: "s3://maven.seqera.io/snapshots"
credentials(AwsCredentials) {
accessKey = project.findProperty('aws_access_key_id') ?: System.getenv('AWS_ACCESS_KEY_ID')
secretKey = project.findProperty('aws_secret_access_key') ?: System.getenv('AWS_SECRET_ACCESS_KEY')
}
}
}
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
51 changes: 51 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

#
# Copyright 2024, Seqera Labs
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#

if [ $# -ne 1 ]; then
echo "Specify the library to publish"
exit 1
fi

if [[ ! -n "$AWS_REGION" && ! -n "$AWS_DEFAULT_REGION" ]]; then
export AWS_DEFAULT_REGION="eu-west-1"
fi

NAME=$1
VERSION=$(cat VERSION)
PUBLISH_REPO_URL=${PUBLISH_REPO_URL:-s3://maven.seqera.io/snapshots}
BASE_URL=${PUBLISH_REPO_URL#s3://}
BUCKET=$(dirname $BASE_URL)
BASE_PATH=$(basename $BASE_URL)
KEY=$BASE_PATH/io/seqera/$NAME/$VERSION/$NAME-$VERSION.pom

echo "Publishing '$NAME-$VERSION' to $BUCKET/$KEY"
ret=$(aws s3api head-object --bucket $BUCKET --key $KEY 2>&1) && {
# already exists => just a message
echo "NOTE: Library $NAME-$VERSION already exist - skipping publishing"
} || {
if [[ $ret == *"Not Found"* ]]; then
# the lib does not exist => publish it
./gradlew publishMavenPublicationToSeqeraRepositoryRepository
else
# print the error message
echo $ret >&2
exit 1
fi
}

6 changes: 3 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
java \
-javaagent:$PWD/app/build/libs/unsafe-tracker-0.1.0.jar \
-Xbootclasspath/a:$PWD/app/build/libs/unsafe-tracker-0.1.0.jar \
-cp ./app/build/classes/groovy/test \
-javaagent:$PWD/build/libs/unsafe-tracker-0.1.0.jar \
-Xbootclasspath/a:$PWD/build/libs/unsafe-tracker-0.1.0.jar \
-cp ./build/classes/groovy/test \
io.seqera.debug.UnsafeTest
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ plugins {
}

rootProject.name = 'unsafe-tracker'
include('app')

0 comments on commit ec3062e

Please sign in to comment.