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
102 changes: 102 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
pipeline {
agent {
label 'master'
}
tools {
jdk 'default'
}
environment {
VERSION = readFile("${WORKSPACE}/version.txt").trim()
}

stages {
stage('create-tag') {
when {
branch 'develop'
}
steps {
script {
withCredentials([gitUsernamePassword(credentialsId: 'github-http', gitToolName: 'Default')]) {
// Clear all tags locally and fetch from origin. If pushing a tag fails for some reason, it will
// continue to exist in jenkins even though it won't be present in origin
sh "git tag | xargs git tag -d"
sh "git fetch --tags"
sh "git tag -a v${env.VERSION} -m \"github-zenhub-sdk version v${env.VERSION}\""
}
}
}
}

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

// Note: tagging stage MUST come before publishing to prevent a new artifact from overwriting an existing
// artifact for a specific version. Tagging will fail if you attempt to duplicate a tag, and prevents a duplicated
// artifact from being published
stage('push-tag') {
when {
branch 'develop'
}
steps {
script {
withCredentials([gitUsernamePassword(credentialsId: 'github-http', gitToolName: 'Default')]) {
sh "git push origin v${env.VERSION}"
}
}
}
}

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

}
}

stage('create-draft-release') {
when {
branch 'develop'
}
steps {
script {
withCredentials([gitUsernamePassword(credentialsId: 'github-http', gitToolName: 'Default', usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN')]) {
sh """
# Check if GitHub CLI is available
if ! command -v gh &> /dev/null; then
echo "GitHub CLI (gh) not found - skipping draft release creation"
echo "Please install GitHub CLI on Jenkins agent or create release manually"
exit 0
fi

gh release create v${env.VERSION} \\
--title "Release v${env.VERSION}" \\
--generate-notes \\
--draft \\
--repo Stack8/github-zenhub-sdk
"""
}
}
}
}
}
}
25 changes: 24 additions & 1 deletion 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 @@ -79,7 +79,30 @@ To publish the SDK, you can run the following command:
./gradlew publish
```

### Development:

To publish a snapshot for use during development, you can run the following command:
```bash
./gradlew publish -Psnapshot
```

This will publish a snapshot of the library to our internal Maven repository at https://repository.goziro.com/ with
the name `<branchName>-SNAPSHOT`

### Merging Your Changes

Other projects ***SHOULD NOT*** be consuming snapshots (aside from locally during development). Instead, they should only consume
proper releases. Publishing and tagging releases is handled by Jenkins. When you merge your changes to `develop`, it triggers a Jenkins
job which builds and tests the repo, then attempts to tag the appropriate commit and publish a release on the nexus repository.

YOU MUST BUMP THE VERSION IN `./version.txt` WHEN MAKING CODE CHANGES FOR THIS SYSTEM TO WORK.

ZIRO-CLI MUST BE UPDATED TO CONSUME THE NEWEST VERSION OF

### Release Notes
Once you merge your changes, CI will publish a new version to Nexus and tag the repo. The last thing to do is to go to:

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!
40 changes: 32 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
var currentVersion = "5.5.0"
var currentVersion = file("version.txt").readText().trim()

fun getBranchName(): String {
return try {
val process = ProcessBuilder("git", "branch", "--show-current")
.directory(rootDir)
.start()
process.inputStream.bufferedReader().readText().trim()
} catch (e: Exception) {
"unknown"
}
}

if (project.hasProperty("snapshot")) {
currentVersion = "${currentVersion}-SNAPSHOT"
val branchName = getBranchName()
currentVersion = "${branchName}-SNAPSHOT"
}

plugins {
Expand Down Expand Up @@ -38,12 +50,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 = System.getenv("SONATYPE_USERNAME") ?: ""
password = System.getenv("SONATYPE_PASSWORD") ?: ""
}
}
}
Expand Down Expand Up @@ -106,3 +114,19 @@ tasks.register("updateSchemas") {
"downloadZenhubApolloSchemaFromIntrospection"
)
}

tasks.register("validatePublishCredentials") {
group = "Publishing"
description = "Validates that publishing credentials are set"
doLast {
val username = System.getenv("SONATYPE_USERNAME")
val password = System.getenv("SONATYPE_PASSWORD")
if (username.isNullOrBlank() || password.isNullOrBlank()) {
throw GradleException("SONATYPE_USERNAME and SONATYPE_PASSWORD environment variables must be set for publishing. Please see the README for instructions.")
}
}
}

tasks.withType<PublishToMavenRepository> {
dependsOn("validatePublishCredentials")
}
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