Skip to content

Commit

Permalink
Add Metrics version to request
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian committed Jan 22, 2021
1 parent c6ced9f commit a95ef19
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate-metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
echo "::set-output name=version::$version"
- name: Generate Metrics Class
if: ${{ !endsWith(steps.read-version.outputs.version, 'SNAPSHOT') }}
run: ./gradlew generateMetrics
run: ./gradlew test generateMetrics
- name: Commit Metrics Class
if: ${{ !endsWith(steps.read-version.outputs.version, 'SNAPSHOT') }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
java-version: 11
- name: Publish
run: gradle publish
run: ./gradlew test publish
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Update Version
if: ${{ !endsWith(steps.read-version.outputs.version, 'SNAPSHOT') }}
run: |
./gradlew incrementVersion
./gradlew test incrementVersion
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add gradle.properties
Expand Down
4 changes: 4 additions & 0 deletions base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}

tasks.test {
systemProperty("metrics-version", version.toString())
}
6 changes: 6 additions & 0 deletions base/src/main/java/org/bstats/MetricsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@

public class MetricsBase {

/**
* The version of the Metrics class.
*/
public static final String METRICS_VERSION = "2.0.2-SNAPSHOT";

private static final ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics"));
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
Expand Down Expand Up @@ -144,6 +149,7 @@ private void submitData() {
serviceJsonBuilder.appendField("customCharts", chartData);
baseJsonBuilder.appendField("service", serviceJsonBuilder.build());
baseJsonBuilder.appendField("serverUUID", serverUuid);
baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION);

JsonObjectBuilder.JsonObject data = baseJsonBuilder.build();

Expand Down
22 changes: 22 additions & 0 deletions base/src/test/java/org/bstats/ConsistentMetricsVersionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.bstats;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class ConsistentMetricsVersionTest {

/**
* Makes sure that the version constant {@link MetricsBase#METRICS_VERSION} is consistent
* with the version in the {@code gradle.properties} file.
*/
@Test
public void testConsistentMetricsVersion() {
// The environment variable is set by the Gradle script
String versionInGradleProperties = System.getProperty("metrics-version");
assertNotNull(versionInGradleProperties, "Failed to find metrics version");
assertEquals(versionInGradleProperties, MetricsBase.METRICS_VERSION);
}

}
5 changes: 5 additions & 0 deletions increment-version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ tasks.register("incrementVersion") {
file("gradle.properties").writeText(
file("gradle.properties").readText().replace(version.toString(), newVersion)
)

file("base/src/main/java/org/bstats/MetricsBase.java").writeText(
file("base/src/main/java/org/bstats/MetricsBase.java").readText()
.replace("METRICS_VERSION = \"${version.toString()}\";", "METRICS_VERSION = \"${newVersion}\";")
)
}
}

0 comments on commit a95ef19

Please sign in to comment.