Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

CTPI-542: usage tracking #407

Merged
merged 3 commits into from
Jul 26, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
java-version: 8
- name: Build with Gradle
run: ./gradlew stage
run: ./gradlew setLibraryVersion stage
env:
CT_CLIENT_ID: ${{ secrets.CT_CLIENT_ID }}
CT_CLIENT_SECRET: ${{ secrets.CT_CLIENT_SECRET }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
java-version: 8
- name: Build with Gradle
run: ./gradlew ciBuild gitPublishPush
run: ./gradlew setLibraryVersion ciBuild gitPublishPush
env:
CT_CLIENT_ID: ${{ secrets.CT_CLIENT_ID }}
CT_CLIENT_SECRET: ${{ secrets.CT_CLIENT_SECRET }}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ allprojects {
}

apply from: "$rootDir/gradle-scripts/git-publish.gradle"

apply from: "$rootDir/gradle-scripts/set-library-version.gradle"
def depVersions = [
//all
commercetoolsSdkJvm: '1.64.0',
Expand Down
32 changes: 32 additions & 0 deletions gradle-scripts/set-library-version.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
task setLibraryVersion {
description 'If the env var "GITHUB_TAG" is set, injects the value in the ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you providing "GITHUB_TAG" variable somewhere? Because I see it will be always with value dev-version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the github-tag is createdwhen the lib is released,

'service/src/main/java/com/commercetools/util/PayoneSolutionInfo.java. Otherwise, if the env var is not ' +
'set it sets the version to the value "dev-version". Note: Should only be executed before compilation in ' +
'the CI tool (e.g. github action.)'
doLast {
def versionFile = 'service/src/main/java/com/commercetools/util/PayoneSolutionInfo.java'
def versionFileContents = new File(versionFile).text
def versionPlaceholder = '#{LIB_VERSION}'
def libVersion = 'dev-version'
def tagName = System.getenv('GITHUB_TAG')

if (!versionFileContents.contains(versionPlaceholder)) {
throw new InvalidUserCodeException("$versionFile does not contain the placeholder: $versionPlaceholder. " +
"Please make sure the file contains the placeholder, in order for the version to be injected " +
"correctly.")
}

// if build was triggered by a git tag, set version to tag name
if (tagName) {
libVersion = tagName
}

if (libVersion) {
println "Injecting the version: '$libVersion' in $versionFile"
ant.replace(file: versionFile, token: versionPlaceholder, value: libVersion)
} else {
throw new InvalidUserDataException("Unable to set library version in $versionFile. Please make sure the" +
" var 'libVersion' is set correctly.")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.commercetools.util;

import io.sphere.sdk.client.SolutionInfo;

public final class PayoneSolutionInfo extends SolutionInfo {
private static final String LIB_NAME = "commercetools-payone-integration";
/** This value is injected by the script at gradle-scripts/set-library-version.gradle. */
public static final String LIB_VERSION = "#{LIB_VERSION}";
public static final String LIB_WEBSITE = "https://github.com/commercetools/commercetools-payone-integration";

/**
* Extends {@link SolutionInfo} class of the JVM SDK to append to the User-Agent header with
* information of the commercetools-sync-java library
*
* <p>A User-Agent header with a solution information looks like this: {@code
* commercetools-jvm-sdk/1.46.1 (AHC/2.0) Java/1.8.0_92-b14 (Mac OS X; x86_64) {@value
* LIB_NAME}/{@value LIB_VERSION}}
*/
public PayoneSolutionInfo() {
setName(LIB_NAME);
setVersion(LIB_VERSION);
setWebsite(LIB_WEBSITE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.commercetools.util.PayoneSolutionInfo