Skip to content

Commit

Permalink
Convert to GitHub Actions (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Jun 21, 2021
1 parent f979d1a commit be92e62
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 85 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: GitHub Build Actions For JNats NATS.io Java Client

on:
pull_request:
types: [opened, synchronize, edited, reopened]
push:
branches:
- main
release:
branches:
- main
types: [released]

jobs:
build:
runs-on: ubuntu-latest
env:
BUILD_EVENT: ${{ github.event_name }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
steps:
- name: Setup JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Setup GO
uses: actions/setup-go@v2
with:
go-version: 1.16.3
- name: Install Nats Server
run: |
cd $GITHUB_WORKSPACE
git clone https://github.com/nats-io/nats-server.git
cd nats-server
export NS_LATEST_TAG=$(git describe --tags --abbrev=0)
git checkout tags/${NS_LATEST_TAG} -b nslatestbranch
go build main.go
mkdir -p ~/.local/bin
cp main ~/.local/bin/nats-server
cd ..
rm -rf nats-server
nats-server -v
- name: Check out code
uses: actions/checkout@v2
- name: Build and Test
run: chmod +x gradlew && ./gradlew clean test
- name: On Pull Request, Verify Javadoc
if: ${{ success() && github.event_name == 'pull_request' }}
run: ./gradlew javadoc
- name: On Merge to Main, Verify and Publish Snapshot
if: ${{ success() && github.event_name == 'push' }}
run: ./gradlew -i publishToSonatype
- name: On Tag Release Main, Verify, Sign and Publish Release
if: ${{ success() && github.event_name == 'release' }}
run: ./gradlew -i sign publishToSonatype closeAndReleaseRepository

45 changes: 0 additions & 45 deletions .travis.yml

This file was deleted.

56 changes: 17 additions & 39 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,16 @@ import aQute.bnd.gradle.Bundle
// src/main/java/io/nats/client/Nats.java
// src/main/java/io/nats/client/package-info.java
// CHANGELOG.md
def jarVersion = "2.11.5"
def jarVersion = "2.11.5.beta1"

// TRAVIS_BRANCH equals TRAVIS_TAG when a tag exists / a tag event
def secureEnv = System.getenv("TRAVIS_SECURE_ENV_VARS") != null ? System.getenv("TRAVIS_SECURE_ENV_VARS") : "false"
def branch = System.getenv("TRAVIS_BRANCH") != null ? System.getenv("TRAVIS_BRANCH") : ""
def tag = System.getenv("TRAVIS_TAG") != null ? System.getenv("TRAVIS_TAG") : ""
def isRelease = System.getenv("BUILD_EVENT") == "release"

// we only sign when we have a tag which means a release (non -SNAPSHOT)
def useSigning = "true" == secureEnv && tag == branch
// version is the variable the build actually uses.
version = isRelease ? jarVersion : jarVersion + "-SNAPSHOT"

// all releases that are not tagged from github will have snapshot on them
def getVersionName = { ->
if ("" == tag) {
return jarVersion + "-SNAPSHOT"
}
return jarVersion
}

version = getVersionName()
archivesBaseName = 'jnats'
group = 'io.nats'

// Get signing properties set up from outside (env var can't handle the dot)
if (System.getenv('SONATYPE_USERNAME') != null) {
project.ext['ossrhUsername'] = System.getenv('SONATYPE_USERNAME')
project.ext['ossrhPassword'] = System.getenv('SONATYPE_PASSWORD')
project.ext['signing.secretKeyRingFile'] = System.getenv('GPG_KEYRING_FILE')
project.ext['signing.keyId'] = System.getenv('GPG_KEY_ID')
project.ext['signing.password'] = System.getenv('GPG_KEY_PASSPHRASE')
}

// If these aren't set, just set them to empty so we don't have issues getting them
if (!project.hasProperty('ossrhUsername')) {
project.ext['ossrhUsername'] = ""
project.ext['ossrhPassword'] = ""
}

tasks {
closeRepository {
onlyIf { nexusPublishing.useStaging.get() }
Expand Down Expand Up @@ -208,16 +181,21 @@ artifacts {
archives javadocJar, sourcesJar, examplesJar
}

if (useSigning) {
if (isRelease) {
signing {
def signingKeyId = System.getenv('SIGNING_KEY_ID')
def signingKey = System.getenv('SIGNING_KEY')
def signingPassword = System.getenv('SIGNING_PASSWORD')
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign configurations.archives
sign publishing.publications.mavenJava
}
}

nexusStaging {
packageGroup = group
username = project.getProperty('ossrhUsername')
password = project.getProperty('ossrhPassword')
username = System.getenv('OSSRH_USERNAME')
password = System.getenv('OSSRH_PASSWORD')
}

publishing {
Expand Down Expand Up @@ -257,7 +235,7 @@ publishing {
def pomFile = file("${project.buildDir}/generated-pom.xml")
writeTo(pomFile)

if (useSigning) {
if (isRelease) {
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
artifact(pomAscFile) {
classifier = null
Expand All @@ -267,7 +245,7 @@ publishing {
}

// create the signed artifacts
if (useSigning) {
if (isRelease) {
project.tasks.signArchives.signatureFiles.each {
artifact(it) {
def matcher = it.file =~ /-(sources|javadoc|examples)\.jar\.asc$/
Expand All @@ -286,8 +264,8 @@ publishing {
nexusPublishing {
repositories {
sonatype {
username = project.getProperty('ossrhUsername')
password = project.getProperty('ossrhPassword')
username = System.getenv('OSSRH_USERNAME')
password = System.getenv('OSSRH_PASSWORD')
}
}
}
Expand All @@ -298,7 +276,7 @@ publishing {
}

tasks.publishMavenJavaPublicationToSonatypeRepository {
if (useSigning) {
if (isRelease) {
dependsOn project.tasks.signArchives
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit be92e62

Please sign in to comment.