@@ -5,115 +5,135 @@ import utest.*
5
5
object PublishSonatypeCentralSnapshotTests extends UtestIntegrationTestSuite {
6
6
private val ENV_VAR_PUBLISH_ORG = " MILL_TESTS_PUBLISH_ORG"
7
7
private val ENV_VAR_DRY_RUN = " MILL_TESTS_PUBLISH_DRY_RUN"
8
-
9
- val tests : Tests = Tests {
10
- test(" actual" ) - integrationTest { tester =>
11
- import tester .*
12
-
13
- val env = sys.env
14
- val maybePublishOrg = env.get(ENV_VAR_PUBLISH_ORG )
15
- val maybePublishUsername = env.get(USERNAME_ENV_VARIABLE_NAME )
16
- val maybePublishPassword = env.get(PASSWORD_ENV_VARIABLE_NAME )
17
-
18
- (maybePublishOrg, maybePublishUsername, maybePublishPassword) match {
19
- case (Some (publishOrg), Some (publishUsername), Some (publishPassword)) =>
20
- val res = eval(
21
- " testProject.publishSonatypeCentral" ,
22
- env = Map (
23
- ENV_VAR_PUBLISH_ORG -> publishOrg,
24
- USERNAME_ENV_VARIABLE_NAME -> publishUsername,
25
- PASSWORD_ENV_VARIABLE_NAME -> publishPassword
26
- )
8
+ private val PublishTaskName = " testProject.publishSonatypeCentral"
9
+ private val PublishDirName = os.SubPath (" testProject/publishSonatypeCentral.dest" )
10
+ private val PublishAllTaskName = " mill.javalib.SonatypeCentralPublishModule/publishAll"
11
+ private val PublishAllDirName =
12
+ os.SubPath (" mill/javalib/SonatypeCentralPublishModule/publishAll.dest" )
13
+
14
+ private def actual (taskName : String ): Unit = integrationTest { tester =>
15
+ import tester .*
16
+
17
+ val env = sys.env
18
+ val maybePublishOrg = env.get(ENV_VAR_PUBLISH_ORG )
19
+ val maybePublishUsername = env.get(USERNAME_ENV_VARIABLE_NAME )
20
+ val maybePublishPassword = env.get(PASSWORD_ENV_VARIABLE_NAME )
21
+
22
+ (maybePublishOrg, maybePublishUsername, maybePublishPassword) match {
23
+ case (Some (publishOrg), Some (publishUsername), Some (publishPassword)) =>
24
+ val res = eval(
25
+ taskName,
26
+ env = Map (
27
+ ENV_VAR_PUBLISH_ORG -> publishOrg,
28
+ USERNAME_ENV_VARIABLE_NAME -> publishUsername,
29
+ PASSWORD_ENV_VARIABLE_NAME -> publishPassword
27
30
)
28
- println(res.debugString )
29
- // Extract the values so that `assert` macro would print them out nicely if the test fails
30
- // instead of printing `res` twice.
31
- val isSuccess = res.isSuccess
32
- val err = res.err
33
- assert(isSuccess && err.contains( " finished with result: " ))
34
-
35
- case _ =>
36
- case class WithName [ A ]( name : String , description : String , value : A )
37
- val missingEnvVars = Vector (
38
- WithName (
39
- ENV_VAR_PUBLISH_ORG ,
40
- " The organization to publish to " ,
41
- maybePublishOrg
42
- ),
43
- WithName ( USERNAME_ENV_VARIABLE_NAME , " Sonatype Central username " , maybePublishUsername ),
44
- WithName (PASSWORD_ENV_VARIABLE_NAME , " Sonatype Central password " , maybePublishPassword)
45
- ).filter(_.value.isEmpty).map(v => s " ${v.name} ( ${v.description} ) " )
46
-
47
- println(
48
- s """ Test is disabled by default (due to the potential flakyness and slowness of Sonatype Central).
49
- |
50
- |To enable this test, set the following environment variables:
51
- | ${missingEnvVars.mkString( " \n " )} """ .stripMargin
52
- )
53
- }
31
+ )
32
+ println(res.debugString)
33
+ // Extract the values so that `assert` macro would print them out nicely if the test fails
34
+ // instead of printing ` res` twice.
35
+ val isSuccess = res.isSuccess
36
+ val err = res.err
37
+ assert(isSuccess && err.contains( " finished with result: " ))
38
+
39
+ case _ =>
40
+ case class WithName [ A ]( name : String , description : String , value : A )
41
+ val missingEnvVars = Vector (
42
+ WithName (
43
+ ENV_VAR_PUBLISH_ORG ,
44
+ " The organization to publish to " ,
45
+ maybePublishOrg
46
+ ),
47
+ WithName (USERNAME_ENV_VARIABLE_NAME , " Sonatype Central username " , maybePublishUsername),
48
+ WithName ( PASSWORD_ENV_VARIABLE_NAME , " Sonatype Central password " , maybePublishPassword )
49
+ ).filter(_.value.isEmpty).map(v => s " ${v.name} ( ${v.description} ) " )
50
+
51
+ println(
52
+ s """ Test is disabled by default (due to the potential flakyness and slowness of Sonatype Central).
53
+ |
54
+ |To enable this test, set the following environment variables:
55
+ | ${missingEnvVars.mkString( " \n " )} """ .stripMargin
56
+ )
54
57
}
58
+ }
55
59
56
- test( " dryRun" ) - integrationTest { tester =>
57
- import tester .*
60
+ private def dryRun ( taskName : String , dirName : os. SubPath ) : Unit = integrationTest { tester =>
61
+ import tester .*
58
62
59
- val res = eval(
60
- " testProject.publishSonatypeCentral" ,
61
- env = Map (
62
- ENV_VAR_PUBLISH_ORG -> " io.github.mill_tests" ,
63
- USERNAME_ENV_VARIABLE_NAME -> " mill-tests-username" ,
64
- PASSWORD_ENV_VARIABLE_NAME -> " mill-tests-password" ,
65
- ENV_VAR_DRY_RUN -> " 1"
66
- )
63
+ val res = eval(
64
+ taskName,
65
+ env = Map (
66
+ ENV_VAR_PUBLISH_ORG -> " io.github.mill_tests" ,
67
+ USERNAME_ENV_VARIABLE_NAME -> " mill-tests-username" ,
68
+ PASSWORD_ENV_VARIABLE_NAME -> " mill-tests-password" ,
69
+ ENV_VAR_DRY_RUN -> " 1"
67
70
)
68
- println(res.debugString)
69
- // Extract the values so that `assert` macro would print them out nicely if the test fails
70
- // instead of printing `res` twice.
71
- val isSuccess = res.isSuccess
72
- val err = res.err
73
- assert(isSuccess && err.contains(" finished with result:" ))
71
+ )
72
+ println(res.debugString)
73
+ // Extract the values so that `assert` macro would print them out nicely if the test fails
74
+ // instead of printing `res` twice.
75
+ val isSuccess = res.isSuccess
76
+ val err = res.err
77
+ assert(isSuccess && err.contains(" finished with result:" ))
74
78
75
- val publishedDir =
76
- workspacePath / " out" / " testProject" / " publishSonatypeCentral.dest" / " repository" / " io" / " github" /
77
- " mill_tests" / " testProject_3"
79
+ val publishedDir =
80
+ workspacePath / " out" / dirName / " repository" / " io" / " github" / " mill_tests" / " testProject_3"
78
81
79
- val rootMetadataFile = publishedDir / " maven-metadata.xml"
80
- assert(os.exists(rootMetadataFile))
82
+ val rootMetadataFile = publishedDir / " maven-metadata.xml"
83
+ assert(os.exists(rootMetadataFile))
81
84
82
- val rootMetadataContents = os.read(rootMetadataFile)
83
- assert(rootMetadataContents.contains(" <version>0.0.1-SNAPSHOT</version>" ))
85
+ val rootMetadataContents = os.read(rootMetadataFile)
86
+ assert(rootMetadataContents.contains(" <version>0.0.1-SNAPSHOT</version>" ))
84
87
85
- val publishedVersionDir = publishedDir / " 0.0.1-SNAPSHOT"
88
+ val publishedVersionDir = publishedDir / " 0.0.1-SNAPSHOT"
86
89
87
- val metadataFile = publishedVersionDir / " maven-metadata.xml"
88
- assert(os.exists(metadataFile))
90
+ val metadataFile = publishedVersionDir / " maven-metadata.xml"
91
+ assert(os.exists(metadataFile))
89
92
90
- val metadataContents : String = os.read(metadataFile)
91
- assert(metadataContents.contains(" <version>0.0.1-SNAPSHOT</version>" ))
93
+ val metadataContents : String = os.read(metadataFile)
94
+ assert(metadataContents.contains(" <version>0.0.1-SNAPSHOT</version>" ))
92
95
93
- val timestampRegex = """ <timestamp>(\d{8}\.\d{6})</timestamp>""" .r
94
- val timestamp = timestampRegex.findFirstMatchIn(metadataContents).map(_.group(1 )).getOrElse {
95
- throw new Exception (
96
- s " No timestamp found via $timestampRegex in $metadataFile: \n $metadataContents"
97
- )
98
- }
99
-
100
- val expectedFiles = Vector (
101
- rootMetadataFile,
102
- publishedDir / " maven-metadata.xml.md5" ,
103
- publishedDir / " maven-metadata.xml.sha1" ,
104
- metadataFile,
105
- publishedVersionDir / " maven-metadata.xml.md5" ,
106
- publishedVersionDir / " maven-metadata.xml.sha1" ,
107
- publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.jar " ,
108
- publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.jar.md5 " ,
109
- publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.jar.sha1 " ,
110
- publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.pom " ,
111
- publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.pom.md5 " ,
112
- publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.pom.sha1 "
96
+ val timestampRegex = """ <timestamp>(\d{8}\.\d{6})</timestamp>""" .r
97
+ val timestamp = timestampRegex.findFirstMatchIn(metadataContents).map(_.group(1 )).getOrElse {
98
+ throw new Exception (
99
+ s " No timestamp found via $timestampRegex in $metadataFile: \n $metadataContents"
113
100
)
114
- val actualFiles = os.walk(publishedDir).toVector
115
- val missingFiles = expectedFiles.filterNot(actualFiles.contains)
116
- assert(missingFiles.isEmpty)
101
+ }
102
+
103
+ val expectedFiles = Vector (
104
+ rootMetadataFile,
105
+ publishedDir / " maven-metadata.xml.md5" ,
106
+ publishedDir / " maven-metadata.xml.sha1" ,
107
+ metadataFile,
108
+ publishedVersionDir / " maven-metadata.xml.md5" ,
109
+ publishedVersionDir / " maven-metadata.xml.sha1" ,
110
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.jar " ,
111
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.jar.md5 " ,
112
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.jar.sha1 " ,
113
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1-sources.jar " ,
114
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1-sources.jar.md5 " ,
115
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1-sources.jar.sha1 " ,
116
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1-javadoc.jar " ,
117
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1-javadoc.jar.md5 " ,
118
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1-javadoc.jar.sha1 " ,
119
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.pom " ,
120
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.pom.md5 " ,
121
+ publishedVersionDir / s " testProject_3-0.0.1- $timestamp-1.pom.sha1 "
122
+ )
123
+ val actualFiles = os.walk(publishedDir).toVector
124
+ val missingFiles = expectedFiles.filterNot(actualFiles.contains)
125
+ assert(missingFiles.isEmpty)
126
+ }
127
+
128
+ val tests : Tests = Tests {
129
+ test(" actual" ) {
130
+ test(" module" ) - actual(PublishTaskName )
131
+ test(" externalModule" ) - actual(PublishAllTaskName )
132
+ }
133
+
134
+ test(" dryRun" ) {
135
+ test(" module" ) - dryRun(PublishTaskName , PublishDirName )
136
+ test(" externalModule" ) - dryRun(PublishAllTaskName , PublishAllDirName )
117
137
}
118
138
}
119
139
}
0 commit comments