Skip to content

Commit ed14d0a

Browse files
authored
[Storage] Verify versions at release. (#22572)
* print devops variables? * add tests.
1 parent 692b9ce commit ed14d0a

File tree

7 files changed

+185
-0
lines changed

7 files changed

+185
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.blob
5+
6+
import com.azure.storage.common.test.shared.ServiceVersionSpec
7+
8+
class BlobServiceVersionTest extends ServiceVersionSpec {
9+
@Override
10+
protected Class getServiceVersionClass() {
11+
return BlobServiceVersion.class
12+
}
13+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.common.test.shared;
5+
6+
import java.util.Optional;
7+
8+
public final class DevopsPipeline {
9+
10+
private static final DevopsPipeline INSTANCE = readFromEnvironment();
11+
12+
private final String jobName;
13+
private final String buildId;
14+
private final String definitionName;
15+
private final String buildReason;
16+
private final String teamProject;
17+
private final boolean setsDevVersion;
18+
19+
private DevopsPipeline(String jobName, String buildId, String definitionName, String buildReason,
20+
String teamProject, boolean setsDevVersion) {
21+
this.jobName = jobName;
22+
this.buildId = buildId;
23+
this.definitionName = definitionName;
24+
this.buildReason = buildReason;
25+
this.teamProject = teamProject;
26+
this.setsDevVersion = setsDevVersion;
27+
}
28+
29+
public static Optional<DevopsPipeline> getInstance() {
30+
return Optional.ofNullable(INSTANCE);
31+
}
32+
33+
private static DevopsPipeline readFromEnvironment() {
34+
boolean isRunningOnAgent = Boolean.parseBoolean(
35+
System.getenv().getOrDefault("TF_BUILD", "false"));
36+
if (isRunningOnAgent) {
37+
String jobName = System.getenv("AGENT_JOBNAME");
38+
String buildId = System.getenv("BUILD_BUILDID");
39+
String definitionName = System.getenv("BUILD_DEFINITIONNAME");
40+
String buildReason = System.getenv("BUILD_REASON");
41+
String teamProject = System.getenv("SYSTEM_TEAMPROJECT");
42+
String setDevVersionString = System.getenv("SETDEVVERSION");
43+
boolean setDevVersion = Boolean.parseBoolean(setDevVersionString);
44+
return new DevopsPipeline(jobName, buildId, definitionName, buildReason, teamProject, setDevVersion);
45+
} else {
46+
return null;
47+
}
48+
}
49+
50+
public String getJobName() {
51+
return jobName;
52+
}
53+
54+
public String getBuildId() {
55+
return buildId;
56+
}
57+
58+
public String getDefinitionName() {
59+
return definitionName;
60+
}
61+
62+
public String getBuildReason() {
63+
return buildReason;
64+
}
65+
66+
public String getTeamProject() {
67+
return teamProject;
68+
}
69+
70+
public boolean getSetsDevVersion() {
71+
return setsDevVersion;
72+
}
73+
74+
public boolean releasesToMavenCentral() {
75+
return definitionName.equals("java - storage")
76+
&& buildReason.equalsIgnoreCase("manual")
77+
&& !setsDevVersion;
78+
}
79+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.common.test.shared
5+
6+
import com.azure.storage.common.implementation.Constants
7+
import spock.lang.IgnoreIf
8+
import spock.lang.Specification
9+
10+
abstract class ServiceVersionSpec extends Specification {
11+
12+
protected abstract Class getServiceVersionClass();
13+
14+
@IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) })
15+
def "getLatest points to latest"() {
16+
when:
17+
Class clazz = getServiceVersionClass()
18+
def lastVersion = clazz.getEnumConstants().last()
19+
def latestVersion = clazz.getLatest()
20+
21+
then:
22+
latestVersion == lastVersion
23+
}
24+
25+
@IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) })
26+
def "Sas version should match last when we release"() {
27+
when:
28+
Class clazz = getServiceVersionClass()
29+
def latestVersion = clazz.getLatest()
30+
31+
then:
32+
Constants.SAS_SERVICE_VERSION == latestVersion.getVersion()
33+
}
34+
35+
@IgnoreIf({ DevopsPipeline.getInstance().map { !it.releasesToMavenCentral() }.orElse(true) })
36+
def "Header version should match last when we release"() {
37+
when:
38+
Class clazz = getServiceVersionClass()
39+
def latestVersion = clazz.getLatest()
40+
41+
then:
42+
Constants.HeaderConstants.TARGET_STORAGE_VERSION == latestVersion.getVersion()
43+
}
44+
}

sdk/storage/azure-storage-common/src/test/resources/SpockConfig.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ def numberOfProcessors = Runtime.getRuntime().availableProcessors()
55
printf("Parallelization is enabled=%b, factor=%.2f, processors=%d config=%s%n",
66
isParallelEnabled, factor, numberOfProcessors, this.class.protectionDomain.codeSource.location)
77

8+
def isRunningOnAgent = System.getenv().getOrDefault("TF_BUILD", "false").toBoolean()
9+
if (isRunningOnAgent) {
10+
printf("%s=%s%n", "AGENT_JOBNAME", System.getenv("AGENT_JOBNAME"))
11+
printf("%s=%s%n", "BUILD_BUILDID", System.getenv("BUILD_BUILDID"))
12+
printf("%s=%s%n", "BUILD_DEFINITIONNAME", System.getenv("BUILD_DEFINITIONNAME"))
13+
printf("%s=%s%n", "BUILD_REASON", System.getenv("BUILD_REASON"))
14+
printf("%s=%s%n", "SYSTEM_TEAMPROJECT", System.getenv("SYSTEM_TEAMPROJECT"))
15+
printf("%s=%s%n", "SETDEVVERSION", System.getenv("SETDEVVERSION"))
16+
}
17+
818
runner {
919
parallel {
1020
enabled isParallelEnabled
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.file.datalake
5+
6+
import com.azure.storage.common.test.shared.ServiceVersionSpec
7+
8+
class DataLakeServiceVersionTest extends ServiceVersionSpec {
9+
@Override
10+
protected Class getServiceVersionClass() {
11+
return DataLakeServiceVersion.class
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.file.share
5+
6+
import com.azure.storage.common.test.shared.ServiceVersionSpec
7+
8+
class ShareServiceVersionTest extends ServiceVersionSpec {
9+
@Override
10+
protected Class getServiceVersionClass() {
11+
return ShareServiceVersion.class
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.queue
5+
6+
import com.azure.storage.common.test.shared.ServiceVersionSpec
7+
8+
class QueueServiceVersionTest extends ServiceVersionSpec {
9+
@Override
10+
protected Class getServiceVersionClass() {
11+
return QueueServiceVersion.class
12+
}
13+
}

0 commit comments

Comments
 (0)