diff --git a/.circleci/config.yml b/.circleci/config.yml index 36ac8b1459..3660664278 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -128,3 +136,7 @@ workflows: filters: branches: only: master + - RELEASE: + filters: + branches: + only: release-project \ No newline at end of file diff --git a/scripts/prepare-environment.sh b/scripts/prepare-environment.sh new file mode 100644 index 0000000000..857a47e136 --- /dev/null +++ b/scripts/prepare-environment.sh @@ -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 \ No newline at end of file diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100644 index 0000000000..b3e3947e12 --- /dev/null +++ b/scripts/release.sh @@ -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 diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100644 index 0000000000..73f5f9b9c4 --- /dev/null +++ b/scripts/utils.sh @@ -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 fabric8cd@gmail.com + 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 +} \ No newline at end of file