Skip to content

Commit 92a7f62

Browse files
Merge pull request #57 from bitrise-io/config-cache
feat: ACI-2926 Generate config cache compatible config
2 parents f600e2a + dc313a4 commit 92a7f62

File tree

5 files changed

+29
-39
lines changed

5 files changed

+29
-39
lines changed

internal/config/common/auth.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,29 @@ func (cac CacheAuthConfig) TokenInGradleFormat() string {
2323
}
2424

2525
// ReadAuthConfigFromEnvironments reads auth information from the environment variables
26-
// - if BITRISEIO_BITRISE_SERVICES_ACCESS_TOKEN is provided, use that
27-
// - otherwise, if BITRISE_BUILD_CACHE_AUTH_TOKEN and BITRISE_BUILD_CACHE_WORKSPACE_ID is provided, use that
28-
// - otherwise return error
2926
func ReadAuthConfigFromEnvironments(envProvider func(string) string) (CacheAuthConfig, error) {
27+
authTokenEnv := envProvider("BITRISE_BUILD_CACHE_AUTH_TOKEN")
28+
workspaceIDEnv := envProvider("BITRISE_BUILD_CACHE_WORKSPACE_ID")
29+
30+
if len(authTokenEnv) > 0 && len(workspaceIDEnv) > 0 {
31+
return CacheAuthConfig{
32+
AuthToken: authTokenEnv,
33+
WorkspaceID: workspaceIDEnv,
34+
}, nil
35+
}
36+
37+
// Try to fall back to JWT which is always available on Bitrise.
38+
// It's a JWT token which already includes the workspace ID.
3039
if serviceToken := envProvider("BITRISEIO_BITRISE_SERVICES_ACCESS_TOKEN"); len(serviceToken) > 0 {
31-
// Bitrise service access token specified, use it for auth.
32-
// It's a JWT token which already includes the workspace ID.
3340
return CacheAuthConfig{
3441
AuthToken: serviceToken,
3542
}, nil
3643
}
3744

38-
// No Bitrise Service Access Token specified.
39-
// In this case both AuthToken and Workspace ID required,
40-
authTokenEnv := envProvider("BITRISE_BUILD_CACHE_AUTH_TOKEN")
45+
// Write specific errors for each case.
4146
if len(authTokenEnv) < 1 {
4247
return CacheAuthConfig{}, errAuthTokenNotProvided
4348
}
4449

45-
workspaceIDEnv := envProvider("BITRISE_BUILD_CACHE_WORKSPACE_ID")
46-
if len(workspaceIDEnv) < 1 {
47-
return CacheAuthConfig{}, errWorkspaceIDNotProvided
48-
}
49-
50-
return CacheAuthConfig{
51-
AuthToken: authTokenEnv,
52-
WorkspaceID: workspaceIDEnv,
53-
}, nil
50+
return CacheAuthConfig{}, errWorkspaceIDNotProvided
5451
}

internal/config/common/endpoint_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func Test_ReadAuthConfigFromEnvironments(t *testing.T) {
5353
"BITRISE_BUILD_CACHE_WORKSPACE_ID": "WorkspaceIDValue",
5454
}))
5555
require.NoError(t, err)
56-
// BITRISEIO_BITRISE_SERVICES_ACCESS_TOKEN wins
57-
assert.Equal(t, CacheAuthConfig{AuthToken: "ServiceAccessTokenValue"}, authToken)
56+
// BITRISE_BUILD_CACHE_AUTH_TOKEN wins
57+
assert.Equal(t, CacheAuthConfig{AuthToken: "AuthTokenValue", WorkspaceID: "WorkspaceIDValue"}, authToken)
5858
})
5959
}
6060

internal/config/gradle/gradleconfig_test.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ func TestGenerateInitGradle(t *testing.T) {
5353
CIProvider: "BestCI",
5454
RepoURL: "https://github.com/some/repo",
5555
// Bitrise CI specific
56-
BitriseAppID: "BitriseAppID1",
57-
BitriseBuildID: "BitriseBuildID1",
58-
BitriseWorkflowName: "BitriseWorkflowName1",
56+
BitriseAppID: "BitriseAppID1",
5957
},
6058
},
6159
want: expectedInitScriptWithoutMetrics,
@@ -76,9 +74,7 @@ func TestGenerateInitGradle(t *testing.T) {
7674
CIProvider: "BestCI",
7775
RepoURL: "https://github.com/some/repo",
7876
// Bitrise CI specific
79-
BitriseAppID: "BitriseAppID1",
80-
BitriseBuildID: "BitriseBuildID1",
81-
BitriseWorkflowName: "BitriseWorkflowName1",
77+
BitriseAppID: "BitriseAppID1",
8278
},
8379
},
8480
want: expectedInitScriptWithMetrics,
@@ -155,7 +151,7 @@ initscript {
155151
maven(url="https://jitpack.io")
156152
}
157153
dependencies {
158-
classpath("io.bitrise.gradle:remote-cache:1.2.8")
154+
classpath("io.bitrise.gradle:remote-cache:1.2.9")
159155
classpath("io.bitrise.gradle:gradle-analytics:2.1.7")
160156
}
161157
}
@@ -174,6 +170,7 @@ settingsEvaluated {
174170
isPush = true
175171
debug = true
176172
blobValidationLevel = "warning"
173+
collectMetadata = false
177174
}
178175
}
179176
}
@@ -193,8 +190,6 @@ rootProject {
193190
194191
bitrise {
195192
appSlug.set("BitriseAppID1")
196-
buildSlug.set("BitriseBuildID1")
197-
workflowName.set("BitriseWorkflowName1")
198193
}
199194
}
200195
}
@@ -211,7 +206,7 @@ initscript {
211206
maven(url="https://jitpack.io")
212207
}
213208
dependencies {
214-
classpath("io.bitrise.gradle:remote-cache:1.2.8")
209+
classpath("io.bitrise.gradle:remote-cache:1.2.9")
215210
classpath("io.bitrise.gradle:gradle-analytics:2.1.7")
216211
}
217212
}
@@ -230,6 +225,7 @@ settingsEvaluated {
230225
isPush = true
231226
debug = true
232227
blobValidationLevel = "warning"
228+
collectMetadata = false
233229
}
234230
}
235231
}
@@ -264,7 +260,7 @@ initscript {
264260
maven(url="https://jitpack.io")
265261
}
266262
dependencies {
267-
classpath("io.bitrise.gradle:remote-cache:1.2.8")
263+
classpath("io.bitrise.gradle:remote-cache:1.2.9")
268264
}
269265
}
270266
@@ -298,7 +294,7 @@ initscript {
298294
maven(url="https://jitpack.io")
299295
}
300296
dependencies {
301-
classpath("io.bitrise.gradle:remote-cache:1.2.8")
297+
classpath("io.bitrise.gradle:remote-cache:1.2.9")
302298
}
303299
}
304300
@@ -332,7 +328,7 @@ initscript {
332328
maven(url="https://jitpack.io")
333329
}
334330
dependencies {
335-
classpath("io.bitrise.gradle:remote-cache:1.2.8")
331+
classpath("io.bitrise.gradle:remote-cache:1.2.9")
336332
}
337333
}
338334

internal/config/gradle/initd.gradle.kts.gotemplate

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ settingsEvaluated {
3030
isPush = {{ .IsPushEnabled }}
3131
debug = {{ .IsDebugEnabled }}
3232
blobValidationLevel = "{{ .ValidationLevel }}"
33+
{{- if .IsAnalyticsEnabled }}
34+
collectMetadata = false
35+
{{- end }}
3336
}
3437
}
3538
}
@@ -53,12 +56,6 @@ rootProject {
5356
{{- if .CacheConfigMetadata.BitriseAppID }}
5457
appSlug.set("{{ .CacheConfigMetadata.BitriseAppID }}")
5558
{{- end }}
56-
{{- if .CacheConfigMetadata.BitriseBuildID }}
57-
buildSlug.set("{{ .CacheConfigMetadata.BitriseBuildID }}")
58-
{{- end }}
59-
{{- if .CacheConfigMetadata.BitriseWorkflowName }}
60-
workflowName.set("{{ .CacheConfigMetadata.BitriseWorkflowName }}")
61-
{{- end }}
6259
}
6360
}
6461
}

internal/consts/consts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const (
1010
AnalyticsServiceEndpoint = "https://xcode-analytics.services.bitrise.io"
1111

1212
// Gradle Remote Build Cache related consts
13-
GradleRemoteBuildCachePluginDepVersion = "1.2.8"
13+
GradleRemoteBuildCachePluginDepVersion = "1.2.9"
1414

1515
// Gradle Analytics related consts
1616
GradleAnalyticsPluginDepVersion = "2.1.7"

0 commit comments

Comments
 (0)