Skip to content

Commit

Permalink
SDKJAVA-136 Github CI for Gradle Resolver
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Vyshniak <[email protected]>
  • Loading branch information
molekyla committed May 28, 2024
1 parent 5fdfa54 commit f8aee95
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .github/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -ev

export GPG_TTY=$(tty)

gpg --version

export ORG_GRADLE_PROJECT_asciiArmoredSigningKey=$(echo $GPG_PRIVATE_KEY | base64 -d)
export ORG_GRADLE_PROJECT_signingPassword=$GPG_PASSPHRASE
export ORG_GRADLE_PROJECT_ossrhUsername=$OSSRH_USERNAME
export ORG_GRADLE_PROJECT_ossrhPassword=$OSSRH_PASSWORD

RELEASE_TAG=$(git describe --abbrev=0)
./gradlew clean publish closeAndReleaseStagingRepositories -PprojVersion=$RELEASE_TAG --info
19 changes: 19 additions & 0 deletions .github/scripts/push-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -ev

# Prepare release
PREVIOUS_RELEASE_TAG=$(git describe --abbrev=0)
if [[ $PREVIOUS_RELEASE_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Set current released version
RELEASE_TAG=$(echo ${PREVIOUS_RELEASE_TAG} | awk -F. -v OFS=. '{$NF += 1 ; print}')
else
echo "Cannot parse the latest release tag: ${PREVIOUS_RELEASE_TAG}"
exit 1
fi

git config user.name "GitHub CI"
git config user.email "[email protected]"

git tag -a "${RELEASE_TAG}" -m "Release ${RELEASE_TAG} from build ${GITHUB_JOB}"

git push origin --tags
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release

on:
push:
branches: [ master ]

jobs:
release:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip release]')"
steps:
- uses: actions/checkout@v2
with:
ref: master
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Test
run: ./gradlew test
- name: Push git tag
run: .github/scripts/push-tag.sh
- name: Deploy Release
env:
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_KEY }}
run: .github/scripts/deploy.sh
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test

# Controls when the workflow will run
on:
# Triggers the workflow on pull request events but only for the master branch
pull_request:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Validate
run: ./gradlew spotlessCheck
- name: Test
run: ./gradlew test
32 changes: 31 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,37 @@ To publish the plugin into the local Maven repository run the command `./gradlew
The project has unit tests based on `junit-jupiter` and `mockito`. To run the tests run the command: `./gradlew test`.

## Continuous Integration
todo describe CI/CD workflow

The CI is run on GitHub, meaning that files in the `.github` folder are used to define the workflows.

### Presubmit Verification
The purpose of this verification is to do a check that the code is not broken.

The presubmit verification does the following:

#### `Test` workflow

##### `Validate` step
This step checks the code style in all `.groovy` and `.java` files in the project. This job fails if the code is not formatted properly.

##### `Test` step
This step runs unit tests

### Submit Verification
The purpose of this workflow is to verify that the `master` branch is always in the `ready for a deploy`
state and release the plugin into the [Maven Central repository](https://repo.maven.apache.org/maven2/com/here/platform/artifact/gradle/gradle-resolver/).

The submit verification runs all the [Presubmit Verification](#presubmit-verification) workflows with the following additional steps:
#### `Release` workflow

##### `Test` step
This step runs unit tests

##### `Push git tag` step
The step increments the current version and pushes a new git tag

##### `Deploy Release` step
This step releases the plugin to the [Maven Central repository](https://repo.maven.apache.org/maven2/com/here/platform/artifact/gradle/gradle-resolver/).

## Coding Standards

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Build Status](https://github.com/heremaps/here-artifact-gradle-resolver/actions/workflows/release.yml/badge.svg)](https://github.com/heremaps/here-artifact-gradle-resolver/actions?query=workflow%3ARelease+branch%3Amaster)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.here.platform.artifact.gradle/gradle-resolver/badge.svg)](https://search.maven.org/artifact/com.here.platform.artifact.gradle/gradle-resolver)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)

# HERE Gradle Resolver for Workspace and Marketplace

## Introduction
Expand Down
72 changes: 69 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@ plugins {
id 'maven-publish'
id 'groovy'
id 'groovy-gradle-plugin'
id "com.diffplug.spotless" version "6.13.0"
id 'com.diffplug.spotless' version '6.13.0'
id 'signing'
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
}

repositories {
mavenLocal()
mavenCentral()
}

group = "com.here.platform.artifact"
group = "com.here.platform.artifact.gradle"

version = "0.0.1-SNAPSHOT"
if (project.hasProperty('projVersion')) {
project.version = project.projVersion
} else {
project.version = '0.0.1-SNAPSHOT'
}

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}

dependencies {
Expand All @@ -36,10 +46,14 @@ test {
}

gradlePlugin {
vcsUrl = "https://github.com/heremaps/here-artifact-gradle-resolver"
website = "https://github.com/heremaps/here-artifact-gradle-resolver"
plugins {
create("hereArtifactResolver") {
id = "com.here.platform.artifact.gradle"
implementationClass = "com.here.platform.artifact.gradle.ArtifactResolver"
displayName = "HERE platform Gradle Resolver plugin"
description = "The HERE platform Gradle resolver plugin provides Java and Scala developers with access to HERE platform artifacts via Gradle"
}
}
}
Expand All @@ -49,4 +63,56 @@ spotless {
target '**/*.java'
eclipse().configFile(rootProject.file('codestyle-formatter-settings.xml'))
}
}

publishing {
afterEvaluate {
publications {
withType(MavenPublication) {
pom {
name = "HERE platform Gradle Resolver plugin"
url = "https://github.com/heremaps/here-artifact-gradle-resolver"
description = "The HERE platform Gradle resolver plugin provides Java and Scala developers with access to HERE platform artifacts via Gradle"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection = "scm:https://github.com/heremaps/here-artifact-gradle-resolver.git"
developerConnection = "scm:[email protected]:heremaps/here-artifact-gradle-resolver.git"
url = "https://github.com/heremaps/here-artifact-gradle-resolver"
}
developers {
developer {
name = "HERE Artifact Service Team"
email = "[email protected]"
organization = "HERE Europe B.V."
organizationUrl = "https://github.com/heremaps"
}
}
}
}
}
}
}

signing {
required { isReleaseVersion }
def signingKey = findProperty("asciiArmoredSigningKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications
}

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
username.set(project.properties["ossrhUsername"].toString())
password.set(project.properties["ossrhPassword"].toString())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public class ArtifactPropertiesResolver {
ArtifactPropertiesResolver() {
}

/**
* Get or create singleton instance
*
* @return ArtifactPropertiesResolver instance
*/
public static ArtifactPropertiesResolver getInstance() {
if (INSTANCE == null) {
INSTANCE = new ArtifactPropertiesResolver();
Expand All @@ -96,6 +101,7 @@ public static ArtifactPropertiesResolver getInstance() {
*
* @param tokenUrl here token url
* @return resolved default artifact service url
* @throws java.io.IOException in case of a problem with connection
*/
public String resolveArtifactServiceUrl(String tokenUrl) throws IOException {
String artifactApiLookupUrl = getApiLookupUrl(tokenUrl) + "/platform/apis/artifact/v1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public class CredentialsResolver {
private static final String HERE_CREDENTIALS_PATH = ".here/credentials.properties";
private static final String HERE_CREDENTIALS_ENV = "HERE_CREDENTIALS_FILE";

/**
* Resolve credentials based on a precedence: 1) -DhereCredentialsFile system property * 2) HERE_CREDENTIALS_FILE
* environment variable 3) HERE_CREDENTIALS_STRING environment variable 4) * ~/.here/credentials.properties file
*
* @return resolved credentials
*/
public Properties resolveCredentials() {
Properties properties = new Properties();
File file = resolveFile();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/here/platform/artifact/gradle/HereAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

import java.util.Properties;

/**
* Responsible for a handling of HERE authentication
*/
public class HereAuth {

private static final int OAUTH_CONNECTION_TIMEOUT_IN_MS = 20000;
Expand All @@ -46,17 +49,32 @@ public class HereAuth {
this.hereCredentials = credentialsResolver.resolveCredentials();
}

/**
* Get or create singleton instance
*
* @return HereAuth instance
*/
public static HereAuth getInstance() {
if (INSTANCE == null) {
INSTANCE = new HereAuth(new CredentialsResolver());
}
return INSTANCE;
}

/**
* Return token endpoint URL based on resolved credentials
*
* @return token endpoint URL
*/
public String getTokenEndpointUrl() {
return hereCredentials.getProperty(HERE_ENDPOINT_URL_KEY);
}

/**
* Request new bearer token
*
* @return token
*/
public String getToken() {
TokenEndpoint tokenEndpoint = HereAccount
.getTokenEndpoint(createHttpProvider(), new FromProperties(new SettableSystemClock(), hereCredentials));
Expand Down

0 comments on commit f8aee95

Please sign in to comment.