Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
pipeline {
agent {
label 'master'
}
tools {
jdk 'default'
}
environment {
VERSION = readFile("${WORKSPACE}/version.txt").trim()
CI_MODE = 'true'
}

stages {
stage('build') {
steps {
script {
sh "./gradlew build"
}
}
post {
always {
archiveArtifacts allowEmptyArchive: true,
artifacts: '**/reports/tests/**'
}
}
}

// Tag before publishing to prevent duplicate versions
stage('tag-and-push') {
when {
branch 'develop'
}
steps {
script {
withCredentials([gitUsernamePassword(credentialsId: 'github-http', gitToolName: 'Default')]) {
// Clean up any stale local tags from previous failed builds
sh 'git tag -d $(git tag -l)'
sh 'git fetch --tags'
sh "git tag -a v${VERSION} -m 'github-zenhub-sdk version v${VERSION}'"
sh "git push origin v${VERSION}"
}
}
}
}

stage('publish') {
when {
branch 'develop'
}
steps {
script {
withCredentials([
usernamePassword(credentialsId: 'sonatype-creds', usernameVariable: 'SONATYPE_USERNAME', passwordVariable: 'SONATYPE_PASSWORD')
]) {
sh "./gradlew publish"
}
}

}
}
}
}
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This library provides a convenient interface for interacting with GitHub and Zen

We follow [Semantic Versioning 2.0.0][semantic-versioning-2], as we do in most projects at ZIRO.

The version can be found in the [gradle build file][gradle-build-file].
The version can be found in `version.txt`. YOU MUST BUMP THE VERSION WHEN MAKING CODE CHANGES.

We should follow the git-flow process as we do in other projects.

Expand Down Expand Up @@ -74,12 +74,19 @@ export SONATYPE_USERNAME=gradle
export SONATYPE_PASSWORD=<get password from 1pass>
```

To publish the SDK, you can run the following command:
Snapshots are created automatically when working on untagged commits. To publish a snapshot:
```bash
./gradlew publish
```

To publish a snapshot for use during development, you can run the following command:
```bash
./gradlew publish -Psnapshot
```
This will publish a snapshot with the format `<branchName>-SNAPSHOT` (e.g. `feature-123-SNAPSHOT`).

### Releases

Release publishing is handled automatically by CI and is blocked for local development to prevent accidents. When CI runs on tagged commits, it publishes the official release version.

### Merging Your Changes

Once you merge your changes, the last thing to do is to go [here](https://github.com/Stack8/github-zenhub-sdk/releases) and
***publish a new release***. Click draft a new release, and select your tag, the previous tag, and click generate release notes.
Make sure "Set as the latest release" is selected and publish your release. Now you're good to go!
52 changes: 43 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
var currentVersion = "5.5.0"
fun resolveProjectVersion(): String {
val gitDescribe = runCatching {
ProcessBuilder(*"git describe --exact-match HEAD".split(" ").toTypedArray())
.directory(rootDir)
.start()
.inputStream
.bufferedReader()
.readText()
.trim()
}.getOrElse { "" }

if (project.hasProperty("snapshot")) {
currentVersion = "${currentVersion}-SNAPSHOT"
val version = file("version.txt").readText().trim()

val branchName = runCatching {
ProcessBuilder(*"git rev-parse --abbrev-ref HEAD".split(" ").toTypedArray())
.directory(rootDir)
.start()
.inputStream
.bufferedReader()
.readText()
.trim()
}.getOrElse { "unknown" }

return if (gitDescribe.isNotEmpty()) version else "$branchName-SNAPSHOT"
}

var currentVersion = resolveProjectVersion()

plugins {
java
`maven-publish`
Expand All @@ -24,6 +46,13 @@ repositories {
mavenCentral()
}

val sonatypeUsername = System.getenv("SONATYPE_USERNAME") ?: ""
val sonatypePassword = System.getenv("SONATYPE_PASSWORD") ?: ""

if (sonatypeUsername.isEmpty() || sonatypePassword.isEmpty()) {
println("WARNING: SONATYPE_USERNAME and/or SONATYPE_PASSWORD environment variables are not set! Publishing will fail if attempted.")
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
Expand All @@ -38,12 +67,8 @@ publishing {
maven {
url = uri("https://repository.goziro.com/repository/engineering/")
credentials {
try {
username = System.getenv("SONATYPE_USERNAME") as String
password = System.getenv("SONATYPE_PASSWORD") as String
} catch (e: NullPointerException) {
throw Exception("SONATYPE_USERNAME and SONATYPE_PASSWORD environment variables are not set! Please see the README for instructions on how to do this.", e)
}
username = sonatypeUsername
password = sonatypePassword
}
}
}
Expand Down Expand Up @@ -106,3 +131,12 @@ tasks.register("updateSchemas") {
"downloadZenhubApolloSchemaFromIntrospection"
)
}

tasks.withType<PublishToMavenRepository>().configureEach {
val predicate = provider {
version.toString().contains("SNAPSHOT") || System.getenv().getOrDefault("CI_MODE", "false") == "true"
}
onlyIf("Artifact is a snapshot or running in CI") {
predicate.get()
}
}
9 changes: 9 additions & 0 deletions src/test/kotlin/github/GitHubClientTest.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package github

import kotlin.test.assertEquals
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class GitHubClientTest {
private val gitHubClient = GitHubClient()

@BeforeEach
fun checkApiToken() {
assumeTrue(
System.getenv("GITHUB_API_TOKEN") != null,
"GITHUB_API_TOKEN not set - skipping integration tests")
}

@Test
fun whenGetFileFromBranchThenFileIsNotEmpty() {
val result = gitHubClient.getFileFromBranch(branch = "develop", filePath = "version.txt")
Expand Down
9 changes: 9 additions & 0 deletions src/test/kotlin/zenhub/ZenHubClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package zenhub

import kotlin.test.assertEquals
import kotlin.test.assertTrue
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class ZenHubClientTest {
private val zenHubClient = ZenHubClient()

@BeforeEach
fun checkApiToken() {
assumeTrue(
System.getenv("ZENHUB_GRAPHQL_TOKEN") != null,
"ZENHUB_GRAPHQL_TOKEN not set - skipping integration tests")
}

@Test
fun whenIssueByInfoThenCorrectIssueIsReturned() {
val issue =
Expand Down
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.6.0