Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
Setup release script and gradle release / publish tasks (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
etanshaul authored Dec 12, 2018
1 parent d78d568 commit b6918f9
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
20 changes: 20 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
* limitations under the License.
*/

import net.researchgate.release.GitAdapter
import org.jetbrains.intellij.tasks.PublishTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.jetbrains.intellij") version "0.3.7"
id("com.diffplug.gradle.spotless") version "3.14.0"
id("net.researchgate.release") version "2.7.0"

kotlin("jvm") version "1.3.11"
}
Expand Down Expand Up @@ -79,3 +82,20 @@ dependencies {

compile("com.google.protobuf:protobuf-java:2.5.0")
}

val intellijRepoChannel: String by project
val publishPlugin: PublishTask by tasks
publishPlugin {
username(System.getenv("CONTAINER_TOOLS_REPO_USERNAME"))
password(System.getenv("CONTAINER_TOOLS_REPO_PASSWORD"))
channels(intellijRepoChannel)
}

release {
tagTemplate = "v\${version}"

val git: GitAdapter.GitConfig = getProperty("git") as GitAdapter.GitConfig
git.requireBranch = "/^release_v\\d+.*$/"
}

inline operator fun <T : Task> T.invoke(a: T.() -> Unit): T = apply(a)
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
ideaEdition = IC
ideaVersion = 2018.3
intellijRepoUrl = https://www.jetbrains.com/intellij-repository
intellijRepoChannel = alpha
version = 18.12.1-alpha-SNAPSHOT
86 changes: 86 additions & 0 deletions kokoro/unix/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
# Copyright 2018, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

## Release script that publishes our plugins to Github and Jetbrains plugin repository

## Assert required environment variables

[ -z "$ANALYTICS_ID" ] && \
echo "ERROR: Releasing requires the ANALYTICS_ID environment variable" && exit 1;
[ -z "$GITHUB_TOKEN" ] && \
echo "ERROR: Releasing requires the GITHUB_TOKEN environment variable" && exit 1;

cd github/google-container-tools-intellij

export SOURCE_VERSION=$(sed -n 's/version[ tab]*=[ tab]*\(.*\)/\1/p' gradle.properties)
[ -z "$SOURCE_VERSION" ] && \
echo "ERROR: gradle.properties could not be parsed. Perhaps we're not in the project root?"\
"$(pwd)" && exit 1;
export GIT_TAG_NAME=$(git describe)
[ -z "$GIT_TAG_NAME" ] && \
echo "ERROR: 'git describe' failed. We're probably not in a git workspace."\
&& exit 1;
export TAG_VERSION=${GIT_TAG_NAME:1}

if [ "$SOURCE_VERSION" != "$TAG_VERSION" ]
then
echo "ERROR: The version ($SOURCE_VERSION) configured in gradle.properties does not match"\
"the version ($TAG_VERSION) in the git tag."
echo "Failing release.."
exit 1 # terminate and indicate error
fi

echo "Installing itchio/gothub.."
sudo /usr/local/go/bin/go get github.com/itchio/gothub
echo "Building plugin"
./gradlew buildPlugin

echo "Creating Github release for tag: $GIT_TAG_NAME"

## GITHUB_USER and GITHUB_REPO are used by gothub command.
export GITHUB_USER=GoogleContainerTools
export GITHUB_REPO=google-container-tools-intellij

if [[ $GIT_TAG_NAME =~ RC[0-9]+$ ]]
then
# Release candidates are marked as pre-releases.
gothub release --tag $GIT_TAG_NAME --pre-release
else
gothub release --tag $GIT_TAG_NAME
fi

echo "Uploading Google Cloud Tools Plugin artifact to release $GIT_TAG_NAME"
gothub upload --tag $GIT_TAG_NAME --file \
build/distributions/google-container-tools-intellij-${VERSION}.zip \
--name google-container-tools-intellij-${VERSION}.zip
echo "Upload complete."

echo "Publishing plugin to Jetbrains plugin repository"
./gradlew :publishPlugin

0 comments on commit b6918f9

Please sign in to comment.