-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Storage] Verify versions at release. (#22572)
* print devops variables? * add tests.
- Loading branch information
1 parent
692b9ce
commit ed14d0a
Showing
7 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...age/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobServiceVersionTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...rage-common/src/test-shared/java/com/azure/storage/common/test/shared/DevopsPipeline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ommon/src/test-shared/java/com/azure/storage/common/test/shared/ServiceVersionSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeServiceVersionTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...rage-file-share/src/test/java/com/azure/storage/file/share/ShareServiceVersionTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../azure-storage-queue/src/test/java/com/azure/storage/queue/QueueServiceVersionTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |