Skip to content

feat(maven): build artifacts to maven #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 57 additions & 61 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ language: java
dist: xenial

jdk:
- openjdk8
- openjdk8

notifications:
email: true

env:
global:
- MVN_ARGS="--settings build/.travis.settings.xml"
- BINTRAY_ORG=ibm-cloud-sdks
- BINTRAY_REPO=vpc-java-sdk

branches:
except:
- gh-pages
Expand All @@ -22,63 +16,65 @@ cache:
directories:
- "$HOME/.m2"

env:
global:
- MVN_ARGS="--settings build/.travis.settings.xml"

stages:
- name: Build-Test
- name: Semantic-Release
if: branch = main AND type = push AND fork = false
- name: Publish-Release
if: tag IS present

before_install:
- sudo apt-get update
- sudo apt-get install python
- nvm install 12
- npm install -g [email protected]
- >-
[ -z "${TRAVIS_TAG}" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]
&& openssl aes-256-cbc -K $encrypted_9d748cee9f61_key -iv $encrypted_9d748cee9f61_iv -in vpc.env.enc -out vpc.env -d
|| true
install:
- curl -s https://codecov.io/bash > $HOME/codecov-bash.sh && chmod +x $HOME/codecov-bash.sh
- sudo apt-get update
- env | grep TRAVIS

before_script:
- echo "TRAVIS_TAG = '${TRAVIS_TAG}'"
- >-
[ -n "${TRAVIS_TAG}" ]
&& mvn versions:set -DnewVersion=${TRAVIS_TAG} -DgenerateBackupPoms=false
|| true
script:
- mvn clean verify -DskipITs $MVN_ARGS
jobs:
include:
- stage: Build-Test
jdk: openjdk8
install:
- curl -s https://codecov.io/bash > $HOME/codecov-bash.sh && chmod +x $HOME/codecov-bash.sh
script:
- build/setMavenVersion.sh
- mvn verify -fae -DskipITs $MVN_ARGS
after_success:
- build/publishCodeCoverage.sh

before_deploy:
- pip install --user bump2version
- npm install @semantic-release/changelog
- npm install @semantic-release/exec
- npm install @semantic-release/git
- npm install @semantic-release/github
- stage: Semantic-Release
install:
- sudo apt-get install python
- nvm install 12
- npm install -g [email protected]
- pip install --user bump2version
- npm install @semantic-release/changelog
- npm install @semantic-release/exec
- npm install @semantic-release/git
- npm install @semantic-release/github
script:
- npx semantic-release
after_success:
- echo "Semantic release has successfully created a new tagged-release"

deploy:
# On master, run semrel to create a new tagged-release.
- provider: script
script: npx semantic-release
skip_cleanup: true
on:
branch: master
# Publish jars on bintray for a tagged release.
- provider: script
script:
- >-
mvn deploy $MVN_ARGS -DskipTests
&& build/bintraySync.sh $BINTRAY_USER $BINTRAY_APIKEY $BINTRAY_ORG $BINTRAY_REPO $TRAVIS_TAG
skip_cleanup: true
on:
tags: true
- stage: Publish-Release
jdk: openjdk8
# Publish javadocs to gh-pages only for a tagged-release.
- provider: script
script: "./build/publish-javadoc.sh"
skip_cleanup: true
on:
tags: true
jdk: openjdk8
# Upload code coverage reports to codecov.io for master or tagged release
- provider: script
script: $HOME/codecov-bash.sh -s modules/coverage-reports/target/site/jacoco-aggregate -t $CODECOV_TOKEN
skip_cleanup: true
on:
condition: $TRAVIS_BRANCH == master || -n "$TRAVIS_TAG"
jdk: openjdk8
name: Publish-Javadoc
install: true
script:
- build/setMavenVersion.sh
- mvn clean javadoc:aggregate $MVN_ARGS
- build/publishJavadoc.sh
after_success:
- echo "Javadocs successfully published to gh-pages!"

- jdk: openjdk8
name: Publish-To-Maven-Central
install: true
script:
- build/setupSigning.sh
- build/setMavenVersion.sh
- mvn deploy $MVN_ARGS -DskipTests -P central
after_success:
- echo "Maven artifacts successfully published to Maven Central!"
17 changes: 9 additions & 8 deletions build/.travis.settings.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>bintray</id>
<username>${env.BINTRAY_USER}</username>
<password>${env.BINTRAY_APIKEY}</password>
</server>
</servers>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>ossrh</id>
<username>${env.OSSRH_USERNAME}</username>
<password>${env.OSSRH_PASSWORD}</password>
</server>
</servers>
</settings>
33 changes: 0 additions & 33 deletions build/bintraySync.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,5 @@ echo '<!DOCTYPE html>
ls docs | grep --invert-match index.html | sed 's/^.*/<li><a href="docs\/&">&<\/a><\/li>/'
echo ' </ul>
</div>
<script>
(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,"script","//www.google-analytics.com/analytics.js","ga");
ga("create", "UA-59827755-4", "auto");
ga("send", "pageview");
</script>
</body>
</html>'
12 changes: 12 additions & 0 deletions build/publishCodeCoverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# This script will publish code coverage info for a build of the main branch
# or a tagged release.

if [[ -n "${TRAVIS_TAG}" || "${TRAVIS_BRANCH}" == "main" && "${TRAVIS_PULL_REQUEST}" == "false" ]]; then
printf ">>>>> Publishing code coverage info for branch: %s\n" ${TRAVIS_BRANCH}
$HOME/codecov-bash.sh -s modules/coverage-reports/target/site/jacoco-aggregate -t $CODECOV_TOKEN
else
printf ">>>>> Bypassing code coverage publish step for feature branch/PR build.\n"
fi

21 changes: 13 additions & 8 deletions build/publish-javadoc.sh → build/publishJavadoc.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
#!/bin/bash

# This script will publish the aggregated javadocs found in the project's "target" directory.
# The javadocs are committed and pushed to the git repository's gh-pages branch.
# Be sure to customize this file to reflect your SDK project's settings (git url,

# Avoid publishing javadocs for a PR build
if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" ]; then

printf "\n>>>>> Publishing javadoc for release build: repo=%s branch=%s build_num=%s job_num=%s\n" ${TRAVIS_REPO_SLUG} ${TRAVIS_BRANCH} ${TRAVIS_BUILD_NUMBER} ${TRAVIS_JOB_NUMBER}
printf "\n>>>>> Publishing javadoc for release build: repo=%s branch=%s build_num=%s job_num=%s\n" ${TRAVIS_REPO_SLUG} ${TRAVIS_BRANCH} ${TRAVIS_BUILD_NUMBER} ${TRAVIS_JOB_NUMBER}

printf "\n>>>>> Cloning repository's gh-pages branch into directory 'gh-pages'"
git clone --branch=gh-pages https://${GH_TOKEN}@github.com/IBM/vpc-java-sdk.git gh-pages
printf "\n>>>>> Cloning repository's gh-pages branch into directory 'gh-pages'\n"
rm -fr ./gh-pages
git clone --branch=gh-pages https://${GH_TOKEN}@XXXGH_URL_NOSCHEMEXXX.git gh-pages

printf "\n>>>>> Finished cloning...\n"


pushd gh-pages

# Create a new directory for this branch/tag and copy the aggregated javadocs there.
printf "\n>>>>> Copying aggregated javadocs to new tagged-release directory: %s\n" ${TRAVIS_BRANCH}
rm -rf docs/${TRAVIS_BRANCH}
mkdir -p docs/${TRAVIS_BRANCH}
cp -rf ../target/site/apidocs/* docs/${TRAVIS_BRANCH}

printf "\n>>>>> Generating gh-pages index.html...\n"
../build/generate-index-html.sh > index.html
../build/generateJavadocIndex.sh > index.html

# Update the 'latest' symlink to point to this branch if it's a tagged release.
if [ -n "$TRAVIS_TAG" ]; then
Expand All @@ -39,10 +44,10 @@ if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" ]; then

popd

printf "\n>>>>> Published javadoc for release build: repo=%s branch=%s build_num=%s job_num=%s\n" ${TRAVIS_REPO_SLUG} ${TRAVIS_BRANCH} ${TRAVIS_BUILD_NUMBER} ${TRAVIS_JOB_NUMBER}
printf "\n>>>>> Published javadoc for release build: repo=%s branch=%s build_num=%s job_num=%s\n" ${TRAVIS_REPO_SLUG} ${TRAVIS_BRANCH} ${TRAVIS_BUILD_NUMBER} ${TRAVIS_JOB_NUMBER}

else

printf "\n>>>>> Javadoc publishing bypassed for non-release build: repo=%s branch=%s build_num=%s job_num=%s\n" ${TRAVIS_REPO_SLUG} ${TRAVIS_BRANCH} ${TRAVIS_BUILD_NUMBER} ${TRAVIS_JOB_NUMBER}
printf "\n>>>>> Javadoc publishing bypassed for non-release build: repo=%s branch=%s build_num=%s job_num=%s\n" ${TRAVIS_REPO_SLUG} ${TRAVIS_BRANCH} ${TRAVIS_BUILD_NUMBER} ${TRAVIS_JOB_NUMBER}

fi
12 changes: 12 additions & 0 deletions build/setMavenVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# This script will check $TRAVIS_TAG to see if we need to run maven to
# set the artifact version #'s.

if [[ -n "${TRAVIS_TAG}" ]]; then
printf "\n>>>>> Setting artifact version #'s to: %s\n" ${TRAVIS_TAG}
mvn versions:set -DnewVersion=${TRAVIS_TAG} -DgenerateBackupPoms=false
else
printf "\n>>>>> Bypassing artifact version setting for non-tagged build\n"
fi

19 changes: 19 additions & 0 deletions build/setupSigning.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -x

# This script is responsible for decrypting your encrypted signing key file
# (build/signing.key.enc), and importing it into the gpg keystore.
# This is done so that your maven build will be able to properly sign your jars
# prior to publishing them on maven central.

echo "Importing signing key..."

# Modify the command below to use the correct environment variables
# that were added to your Travis build settings when you encrypted your signing.key file.
openssl aes-256-cbc -K $encrypted_4b7d603e7466_key -iv $encrypted_4b7d603e7466_iv -in build/signing.key.enc -out build/signing.key -d

gpg --version
gpg --fast-import build/signing.key
rm build/signing.key

echo "Signing key import finished!"
Binary file added build/signing.key.enc
Binary file not shown.
13 changes: 6 additions & 7 deletions modules/coverage-reports/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@
</dependency>
</dependencies>

<properties>
<!-- There is no need to publish this module's artifacts on maven central -->
<maven.deploy.skip>true</maven.deploy.skip>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</properties>

<build>
<plugins>
<!-- No need to deploy this artifact since it contains only coverage info -->
<plugin>
<groupId>com.carrotgarden.maven</groupId>
<artifactId>bintray-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Loading