Skip to content

Commit

Permalink
[Storage] Verify versions at release. (#22572)
Browse files Browse the repository at this point in the history
* print devops variables?

* add tests.
  • Loading branch information
kasobol-msft authored Jun 25, 2021
1 parent 692b9ce commit ed14d0a
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.blob

import com.azure.storage.common.test.shared.ServiceVersionSpec

class BlobServiceVersionTest extends ServiceVersionSpec {
@Override
protected Class getServiceVersionClass() {
return BlobServiceVersion.class
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.common.test.shared;

import java.util.Optional;

public final class DevopsPipeline {

private static final DevopsPipeline INSTANCE = readFromEnvironment();

private final String jobName;
private final String buildId;
private final String definitionName;
private final String buildReason;
private final String teamProject;
private final boolean setsDevVersion;

private DevopsPipeline(String jobName, String buildId, String definitionName, String buildReason,
String teamProject, boolean setsDevVersion) {
this.jobName = jobName;
this.buildId = buildId;
this.definitionName = definitionName;
this.buildReason = buildReason;
this.teamProject = teamProject;
this.setsDevVersion = setsDevVersion;
}

public static Optional<DevopsPipeline> getInstance() {
return Optional.ofNullable(INSTANCE);
}

private static DevopsPipeline readFromEnvironment() {
boolean isRunningOnAgent = Boolean.parseBoolean(
System.getenv().getOrDefault("TF_BUILD", "false"));
if (isRunningOnAgent) {
String jobName = System.getenv("AGENT_JOBNAME");
String buildId = System.getenv("BUILD_BUILDID");
String definitionName = System.getenv("BUILD_DEFINITIONNAME");
String buildReason = System.getenv("BUILD_REASON");
String teamProject = System.getenv("SYSTEM_TEAMPROJECT");
String setDevVersionString = System.getenv("SETDEVVERSION");
boolean setDevVersion = Boolean.parseBoolean(setDevVersionString);
return new DevopsPipeline(jobName, buildId, definitionName, buildReason, teamProject, setDevVersion);
} else {
return null;
}
}

public String getJobName() {
return jobName;
}

public String getBuildId() {
return buildId;
}

public String getDefinitionName() {
return definitionName;
}

public String getBuildReason() {
return buildReason;
}

public String getTeamProject() {
return teamProject;
}

public boolean getSetsDevVersion() {
return setsDevVersion;
}

public boolean releasesToMavenCentral() {
return definitionName.equals("java - storage")
&& buildReason.equalsIgnoreCase("manual")
&& !setsDevVersion;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.common.test.shared

import com.azure.storage.common.implementation.Constants
import spock.lang.IgnoreIf
import spock.lang.Specification

abstract class ServiceVersionSpec extends Specification {

protected abstract Class getServiceVersionClass();

@IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) })
def "getLatest points to latest"() {
when:
Class clazz = getServiceVersionClass()
def lastVersion = clazz.getEnumConstants().last()
def latestVersion = clazz.getLatest()

then:
latestVersion == lastVersion
}

@IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) })
def "Sas version should match last when we release"() {
when:
Class clazz = getServiceVersionClass()
def latestVersion = clazz.getLatest()

then:
Constants.SAS_SERVICE_VERSION == latestVersion.getVersion()
}

@IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) })
def "Header version should match last when we release"() {
when:
Class clazz = getServiceVersionClass()
def latestVersion = clazz.getLatest()

then:
Constants.HeaderConstants.TARGET_STORAGE_VERSION == latestVersion.getVersion()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ def numberOfProcessors = Runtime.getRuntime().availableProcessors()
printf("Parallelization is enabled=%b, factor=%.2f, processors=%d config=%s%n",
isParallelEnabled, factor, numberOfProcessors, this.class.protectionDomain.codeSource.location)

def isRunningOnAgent = System.getenv().getOrDefault("TF_BUILD", "false").toBoolean()
if (isRunningOnAgent) {
printf("%s=%s%n", "AGENT_JOBNAME", System.getenv("AGENT_JOBNAME"))
printf("%s=%s%n", "BUILD_BUILDID", System.getenv("BUILD_BUILDID"))
printf("%s=%s%n", "BUILD_DEFINITIONNAME", System.getenv("BUILD_DEFINITIONNAME"))
printf("%s=%s%n", "BUILD_REASON", System.getenv("BUILD_REASON"))
printf("%s=%s%n", "SYSTEM_TEAMPROJECT", System.getenv("SYSTEM_TEAMPROJECT"))
printf("%s=%s%n", "SETDEVVERSION", System.getenv("SETDEVVERSION"))
}

runner {
parallel {
enabled isParallelEnabled
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.file.datalake

import com.azure.storage.common.test.shared.ServiceVersionSpec

class DataLakeServiceVersionTest extends ServiceVersionSpec {
@Override
protected Class getServiceVersionClass() {
return DataLakeServiceVersion.class
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.file.share

import com.azure.storage.common.test.shared.ServiceVersionSpec

class ShareServiceVersionTest extends ServiceVersionSpec {
@Override
protected Class getServiceVersionClass() {
return ShareServiceVersion.class
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.queue

import com.azure.storage.common.test.shared.ServiceVersionSpec

class QueueServiceVersionTest extends ServiceVersionSpec {
@Override
protected Class getServiceVersionClass() {
return QueueServiceVersion.class
}
}

0 comments on commit ed14d0a

Please sign in to comment.