Skip to content

Commit

Permalink
set automatic release on circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
cvgaviao committed Oct 23, 2018
1 parent 255c9d1 commit f7cce8a
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 22 deletions.
65 changes: 43 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2 # use CircleCI 2.0

defaults: &defaults
docker: # run the steps with Docker
- image: circleci/openjdk:8u181-jdk-stretch

working_directory: ~/repo # directory where repository will be checked-out and steps will run

environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m


version: 2

jobs: # a collection of steps
build: # runs not using Workflows must have a `build` job as entry point

branches:
ignore:
- gh-pages

docker: # run the steps with Docker
# specify the version you desire here
- image: circleci/openjdk:8u181-jdk-stretch

working_directory: ~/repo # directory where steps will run
<<: *defaults

environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m

steps: # a collection of executable commands
- add_ssh_keys

- checkout # check out source code to working directory

# Download and cache dependencies
Expand All @@ -30,21 +34,38 @@ jobs: # a collection of steps
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: mvn -s .circleci/.circleci.settings.xml -fn -DskipTests dependency:go-offline
# Build
- run: mvn -s .circleci/settings.xml -fn -DskipTests dependency:go-offline

- save_cache: # saves the project dependencies
name: Dependencies caching
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}

# run tests!
- run: mvn -s .circleci/.circleci.settings.xml -Dc8tech.build.test.coverage clean install

deployment:
main:
branch: master
commands:
- mvn -s .circleci/.circleci.settings.xml -DskipTests deploy
# Run tests!
- run: mvn -s .circleci/settings.xml -Dc8tech.build.test.coverage clean install


# Deploy if on master branch. If the $RELEASE and $NEXT variables are set then prepare a full maven release.
- deploy:
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
echo $C8TECH_GPG_KEY | base64 --decode > signing-key
gpg --pinentry-mode=loopback --passphrase $C8TECH_GPG_PASSPHRASE --import signing-key
shred signing-key
echo "1234" | gpg --pinentry-mode=loopback --passphrase "${C8TECH_GPG_PASSPHRASE}" -o /dev/null --local-user "${C8TECH_GPG_KEY_ID}" -as - && echo "The correct passphrase was entered for this key"
if [[ -n "${RELEASE_VERSION}" && -n "${NEXT_VERSION}" ]]; then
echo "starting release for release-version= ${RELEASE_VERSION} next-version= ${NEXT_VERSION}"
git config --global user.email "[email protected]"
git config --global user.name "c8tech releaser bot"
mvn -B -s .circleci/settings.xml release:prepare -DdryRun=${C8TECH_RELEASE_DRYRUN} -Darguments="-s .circleci/settings.xml" -Dc8tech.build.release -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$NEXT_VERSION -DscmCommentPrefix="release: "
else
mvn -B -s .circleci/settings.xml deploy -Dc8tech.build.release
fi
fi
23 changes: 23 additions & 0 deletions .circleci/run-build-locally.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash


if [[ ! -n "$CIRCLE_USER_TOKEN" ]]; then
echo "You must export CIRCLE_USER_TOKEN environment variable before run." 1>&2
exit 1
fi

if [[ ! -n "$1" ]]; then
echo "Commit hash (argument 1) should be informed" 1>&2
exit 1
fi

echo "building from commit " $1

curl --user ${CIRCLE_USER_TOKEN}: \
--request POST \
--form revision=$1\
--form [email protected] \
--form notify=false \
https://circleci.com/api/v1.1/project/github/cvgaviao/osgi-subsystem-maven-plugin/tree/master


156 changes: 156 additions & 0 deletions .circleci/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<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>
<!-- USING SONATYPE'S PROFILE -->
<id>c8tech-release-server</id>
<username>${env.C8TECH_SONATYPE_USER}</username>
<password>${env.C8TECH_SONATYPE_PASSWORD}</password>
</server>
<server>
<id>c8tech-snapshots-server</id>
<username>${env.C8TECH_SONATYPE_USER}</username>
<password>${env.C8TECH_SONATYPE_PASSWORD}</password>
</server>
<server>
<!-- USED BY SITE DEPLOYMENT AT GITHUB -->
<id>osgi-subsystem-maven-plugin-ghpages</id>
<password>${env.GHPAGES_PASSWORD}</password>
</server>

</servers>

<activeProfiles>
<activeProfile>CI</activeProfile>
<activeProfile>Signing</activeProfile>
</activeProfiles>
<profiles>

<profile>
<id>Signing</id>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.keyname>${env.C8TECH_GPG_KEY_ID}</gpg.keyname>
<gpg.passphrase>${env.C8TECH_GPG_PASSPHRASE}</gpg.passphrase>
<gpg.homedir>/home/circleci/.gnupg/</gpg.homedir>
</properties>
</profile>
<profile>
<id>CI</id>
<properties>

<!-- ** WORKSPACE ** -->
<c8tech.workspace.dir>
${CIRCLE_WORKING_DIRECTORY}${file.separator}workspace${file.separator}
</c8tech.workspace.dir>

<!-- ======================== -->
<!-- SCM PROPERTIES -->
<!-- ======================== -->

<project.scm.id>github.com</project.scm.id>

<c8tech.scm.user>cvgaviao</c8tech.scm.user>
<c8tech.scm.branch>master</c8tech.scm.branch>
<c8tech.scm.domain>
https://github.com/
</c8tech.scm.domain>
<c8tech.scm.connection.protocol>
scm:git:git://
</c8tech.scm.connection.protocol>
<c8tech.scm.connection.host>
github.com/
</c8tech.scm.connection.host>
<c8tech.scm.connection.dev.protocol>
scm:git:ssh://
</c8tech.scm.connection.dev.protocol>
<c8tech.scm.connection.dev.host>
[email protected]
</c8tech.scm.connection.dev.host>


<!-- ========================= -->
<!-- DISTRIBUTION PROPERTIES -->
<!-- ========================= -->
<!-- Set distribution repositories -->
<c8tech.distribution.repository.release.id>c8tech-release-server</c8tech.distribution.repository.release.id>
<c8tech.distribution.repository.snapshot.id>c8tech-snapshots-server</c8tech.distribution.repository.snapshot.id>

<c8tech.distribution.repository.base.url>
https://oss.sonatype.org/
</c8tech.distribution.repository.base.url>
<c8tech.distribution.repository.release.url>
${c8tech.distribution.repository.base.url}/service/local/staging/deploy/maven2/
</c8tech.distribution.repository.release.url>
<c8tech.distribution.repository.snapshot.url>
${c8tech.distribution.repository.base.url}/content/repositories/snapshots/
</c8tech.distribution.repository.snapshot.url>

<!-- ======================== -->
<!-- SITE PROPERTIES -->
<!-- ======================== -->
<!-- Set Site Server Location -->

<c8tech.site.user>cvgaviao</c8tech.site.user>
<c8tech.distribution.site.name>
${project.name} Site
</c8tech.distribution.site.name>

<!-- points to the root of project's site at github -->
<c8tech.site.domain>http://${c8tech.site.user}.github.io/
</c8tech.site.domain>
<c8tech.distribution.protocol>github:
</c8tech.distribution.protocol>

<!-- Set Issue Management -->
<c8tech.im.system>Github</c8tech.im.system>
<c8tech.im.server.domain>
https://github.com
</c8tech.im.server.domain>
<c8tech.im.server.dir>
${c8tech.scm.user}/${c8tech.scm.repo.name}/issues
</c8tech.im.server.dir>

<!-- Set CI system and location -->
<c8tech.ci.system>Circle-CI</c8tech.ci.system>
<c8tech.ci.server.domain>
https://circleci.com/gh/
</c8tech.ci.server.domain>
<c8tech.ci.server.user>c8tech-releaser-bot</c8tech.ci.server.user>

</properties>

<repositories>
<repository>
<id>sonatype-stage</id>
<name>Sonatype Nexus Staged Releases</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>
https://oss.sonatype.org/content/groups/staging
</url>
</repository>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>
https://oss.sonatype.org/content/repositories/snapshots
</url>
</repository>
</repositories>
</profile>
</profiles>

</settings>
39 changes: 39 additions & 0 deletions .circleci/trigger-remote-release-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash


if [[ ! -n "$CIRCLE_USER_TOKEN" ]]; then
echo "You must export CIRCLE_USER_TOKEN environment variable before run." 1>&2
exit 1
fi

if [[ ! -n "$1" || ! -n "$2" ]]; then
echo "Both release version (argument 1) and next version (argument 2) should be informed" 1>&2
exit 1
fi



RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

release_version=$1
next_version=$2
if [[ -z $3 ]]; then
dryrun=true
else
dryrun=false
fi

echo -e "Releasing version ${RED} $release_version ${NC} and preparing next version ${GREEN} $next_version ${NC}"

template_parameter='{"build_parameters": {"RELEASE_VERSION": "%s", "NEXT_VERSION": "%s", "C8TECH_RELEASE_DRYRUN": "%s"}}'
json_parameter=$(printf "$template_parameter" "$release_version" "$next_version", "$dryrun")

curl \
--header "Content-Type: application/json" \
--data "$json_parameter" \
--request POST \
https://circleci.com/api/v1.1/project/github/cvgaviao/osgi-subsystem-maven-plugin/tree/master?circle-token=$CIRCLE_USER_TOKEN


0 comments on commit f7cce8a

Please sign in to comment.