Skip to content

Commit

Permalink
add build scripts for CD
Browse files Browse the repository at this point in the history
(cherry picked from commit 9ccc613)
  • Loading branch information
martinfrancois committed Aug 19, 2019
1 parent 411b0bf commit cf4dd8c
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .github/.travis.settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<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-${env.BINTRAY_SUBJECT}-${env.BINTRAY_REPO}</id>
<username>${env.BINTRAY_USER}</username>
<password>${env.BINTRAY_API_KEY}</password>
</server>
</servers>
</settings>
15 changes: 15 additions & 0 deletions .github/deploy_bintray_central.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
echo "Copy settings.xml for deployment"
cp .github/.travis.settings.xml $HOME/.m2/settings.xml
echo "Deploy to Bintray"
mvn deploy -DskipTests
echo "Sync to Maven Central"
result=$(curl -X POST -u $BINTRAY_USER:$BINTRAY_API_KEY https://api.bintray.com/maven_central_sync/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/versions/$TRAVIS_TAG)
if [[ $result == *"Successfully synced and closed repo."* ]]
then
echo Successfully synced to Maven Central
exit 0
else
echo Failed sync to Maven Central: $result
exit 1
fi
51 changes: 51 additions & 0 deletions .github/deploy_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Script will zip the javadoc for upload to the release later, generate the changelog and increment the version in the pom.xml file to the one of the tag

echo TRAVIS_TAG=$TRAVIS_TAG
echo TAG_BRANCH=$TAG_BRANCH

if [[ "$TRAVIS_PULL_REQUEST" != "false" || ("$TAG_BRANCH" != "master" && "$TAG_BRANCH" != "master-11") || "$TRAVIS_TAG" == "" ]]
then
echo "No tag was made from master or master-11, skipping deployment preparation."
exit 0
fi

rev=$(git rev-parse --short HEAD)

echo "Install Dependencies for Changelog Generation"
gem install rack -v 1.6.4
gem install github_changelog_generator
echo "Finished Install Dependencies for Changelog Generation"

git config user.name "Travis CI"
git config user.email "[email protected]"

echo "Prepare Git for Commits"
git remote add upstream "https://$GITHUB_TOKEN@github.com/$TRAVIS_REPO_SLUG.git"
git fetch upstream
git checkout $TAG_BRANCH
echo "Finished Prepare Git for Commits"

echo "Generate Changelog"
github_changelog_generator -t $GITHUB_TOKEN
git add -A CHANGELOG.md
git commit -m "update changelog at ${rev}"
echo "Finished Generate Changelog"

echo "Increment Version"
mvn versions:set -DnewVersion=$TRAVIS_TAG -DoldVersion=* -DgroupId=* -DartifactId=*
# increment version of children modules
mvn versions:update-child-modules
git commit -am "increment version to ${TRAVIS_TAG}"
echo "Finished Increment Version"

echo "Push commits"
git push upstream $TAG_BRANCH
echo "Finished Push commits"

echo "Running mvn package"
mvn package -DskipTests
echo "Making zip of javadoc"
cd ${TRAVIS_BUILD_DIR}/CalendarFXView/target/apidocs
zip -r ${TRAVIS_BUILD_DIR}/javadoc.zip .
66 changes: 60 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,63 @@
language: java

# to make the build work with oraclejdk8: https://travis-ci.community/t/solved-oraclejdk8-installation-failing-still-again/3428
dist: trusty

sudo: false # Linux OS: run in container

env:
global:
# get all the branches referencing this commit
- TAG_BRANCH=$(git ls-remote origin | sed -n "\|$TRAVIS_COMMIT\s\+refs/heads/|{s///p}")

# Necessary environment variables on Travis CI:
#
# GITHUB_TOKEN: Token from here: https://github.com/settings/tokens => with scope "public_repo"
# BINTRAY_USER: Bintray username
# BINTRAY_API_KEY: API key from here: https://bintray.com/profile/edit => API Key
#
# The Bintray URL follows the following pattern: https://bintray.com/subject/repo/package
# BINTRAY_SUBJECT=subject
# BINTRAY_REPO=repo
# BINTRAY_PACKAGE=package

jdk: oraclejdk8

addons:
apt:
packages:
- p7zip-full

before_install:
- if [[ "${TRAVIS_OS_NAME}" == linux ]]; then export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; fi

install: true

cache:
directories:
- $HOME/.m2/
before_script:
- mvn -v
script: mvn package
jdk: openjdk11
env: TERM=dumb
- $HOME/.m2

script: mvn test -B

after_success:
- .github/deploy_prepare.sh

deploy:
- provider: releases
api_key: $GITHUB_TOKEN
file_glob: true
file:
- javadoc.zip
- /**/target/*.jar
skip_cleanup: true
name: Release $TRAVIS_TAG
body: See [CHANGELOG.md](https://github.com/$TRAVIS_REPO_SLUG/blob/master/CHANGELOG.md)
on: &on
repo: $TRAVIS_REPO_SLUG
tags: true
all_branches: true
condition: $TAG_BRANCH =~ ^(master|master-11)$
- provider: script
script: .github/deploy_bintray_central.sh
skip_cleanup: true
on: *on

0 comments on commit cf4dd8c

Please sign in to comment.