Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1514 from dev-gaur/add_circleci_cd
Browse files Browse the repository at this point in the history
Added Release workflow on CircleCI
  • Loading branch information
Devang Gaur authored Feb 14, 2019
2 parents 3728322 + 7b4849c commit 66cb664
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ jobs:
key: fmp-sonar-{{ checksum "pom.xml" }}
paths:
- ~/.m2
RELEASE:
machine: true
steps:
- checkout
- run:
command: |
bash ./scripts/prepare-environment.sh
bash ./scripts/release.sh
workflows:
version: 2
Expand All @@ -128,3 +136,7 @@ workflows:
filters:
branches:
only: master
- RELEASE:
filters:
branches:
only: release-project
21 changes: 21 additions & 0 deletions scripts/prepare-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright 2016 Red Hat, Inc.
#
# Red Hat licenses this file to you 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.
#

echo $SETTINGS_XML | base64 --decode > $HOME/.m2/settings.xml
echo $PUBRING | base64 --decode > $HOME/.gnupg/pubring.gpg
echo $SEC_JENKINS | base64 --decode > $HOME/.gnupg/sec_jenkins.gpg
echo $SECRING | base64 --decode > $HOME/.gnupg/secring.gpg
echo $TRUSTDB | base64 --decode > $HOME/.gnupg/trustdb.gpg
31 changes: 31 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
#
# Copyright 2016 Red Hat, Inc.
#
# Red Hat licenses this file to you 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.
#

#!/bin/bash

set -x

project="fabric8io/fabric8-maven-plugin"

source ./scripts/utils.sh

# stage
output=$(stage_project)
echo $output

# promote
release_sonatype_repo
84 changes: 84 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
#
# Copyright 2016 Red Hat, Inc.
#
# Red Hat licenses this file to you 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.
#


function get_project_version() {
project_version=$(mvn -q \
-Dexec.executable="echo" \
-Dexec.args='${project.version}' \
--non-recursive \
org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
echo $project_version
}

function setup_git_ssh() {
git config --global user.email [email protected]
git config --global user.name fabric8cd
}

function push_tag() {
release_version=$1
git tag -fa v${release_version} -m 'Release version ${release_version}'
git push origin v${release_version}
}

# check the logic of this for getting repo_id
function get_repo_ids() {
find target/ -maxdepth 1 -name "*.properties" > target/repos.txt
filename=$(cat target/repos.txt)
repo_id=$filename
echo $repo_id
exit 0
}

# check this
function stage_sonatype_repo() {
mvn clean -B
mvn -V -B -e -U install org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7:deploy -P release -DnexusUrl=https://oss.sonatype.org -DserverId=oss-sonatype-staging
get_repo_ids
}

function stage_project() {
setup_git_ssh
if [ -z $GH_USER ]; then
GH_USER=fabric8cd
echo $GH_USER
fi
git remote set-url origin https://${GH_USER}:${GH_TOKEN}@github.com/${project}.git

version=$(get_project_version)

if [ -z $RELEASE_VERSION && -z $version ]; then
echo "NO RELEASE VERSION SET IN ENV AND POM! Exiting..."
exit 1
fi

if [ -z $version]; then
version=$RELEASE_VERSION
fi

mvn versions:set -DnewVersion=$version
repo_ids=$(stage_sonatype_repo)
push_tag $version
echo "$project,$version,$repo_ids"
}

# check how to handle if there is a failure in the release
function release_sonatype_repo() {
repo_id=$1
mvn -B org.sonatype.plugins:nexus-staging-maven-plugin:1.6.5:rc-release -DserverId=oss-sonatype-staging -DnexusUrl=https://oss.sonatype.org -DstagingRepositoryId=${repo_id} -Ddescription=\"Next release is ready\" -DstagingProgressTimeoutMinutes=60
}

0 comments on commit 66cb664

Please sign in to comment.