Skip to content

Commit ad1c1d5

Browse files
authored
Merge pull request #121 from bitrise-io/add-os-to-key
Add os to gradle configuration cache key
2 parents c3c4c1f + 624b40b commit ad1c1d5

File tree

3 files changed

+140
-8
lines changed

3 files changed

+140
-8
lines changed

bitrise.yml

Lines changed: 124 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ workflows:
291291
feature-e2e-gradle-bitwarden:
292292
envs:
293293
- TEST_APP_URL: git@github.com:bitwarden/android.git
294-
- BRANCH: main
294+
- COMMIT: 2c71ab7d27d7f976766adee7bfd1828d5eda0850
295295
steps:
296296
- bundle::feature-e2e-setup: {}
297297
- script:
@@ -391,6 +391,125 @@ workflows:
391391
'--bes_header=x-default-charset=\w+' \
392392
- deploy-to-bitrise-io@2: {}
393393

394+
gradle-configuration-e2e-osx:
395+
meta:
396+
bitrise.io:
397+
machine_type_id: g2-m1.8core
398+
stack: osx-xcode-edge
399+
envs:
400+
- TEST_APP_URL: git@github.com:bitwarden/android.git
401+
- COMMIT: 2c71ab7d27d7f976766adee7bfd1828d5eda0850
402+
steps:
403+
- bundle::feature-e2e-setup: {}
404+
- script:
405+
title: Enable build cache
406+
inputs:
407+
- content: |-
408+
set -exo pipefail
409+
../bitrise-build-cache-cli enable-for gradle --metrics -d
410+
- script:
411+
title: Create local configuration cache
412+
inputs:
413+
- content: |-
414+
set -exo pipefail
415+
./gradlew debug --configuration-cache --dry-run
416+
- script:
417+
title: Save configuration cache
418+
inputs:
419+
- content: |-
420+
set -exo pipefail
421+
../bitrise-build-cache-cli save-gradle-configuration-cache \
422+
--config-cache-dir "$PWD/.gradle/configuration-cache"
423+
- script:
424+
title: Delete local configuration cache
425+
inputs:
426+
- content: |-
427+
set -exo pipefail
428+
rm -rf .gradle/configuration-cache
429+
- script:
430+
title: Restore configuration cache
431+
inputs:
432+
- content: |-
433+
set -exo pipefail
434+
../bitrise-build-cache-cli restore-gradle-configuration-cache
435+
- script:
436+
title: Build and capture logs
437+
inputs:
438+
- content: |-
439+
set -exo pipefail
440+
(./gradlew debug --configuration-cache 2>&1) | tee "$BITRISE_DEPLOY_DIR/logs.txt"
441+
- script:
442+
title: Check for cache invocations
443+
inputs:
444+
- content: |-
445+
set -exo pipefail
446+
447+
../scripts/check_pattern.sh "$BITRISE_DEPLOY_DIR/logs.txt" \
448+
'Reusing configuration cache.' \
449+
'\[Bitrise Build Cache\].*🤖 Bitrise remote cache enabled' \
450+
'\[Bitrise Build Cache\].*Request metadata invocationId' \
451+
'\[Bitrise Analytics\].*🤖 Bitrise analytics enabled for tasks.*Invocation ID: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
452+
- deploy-to-bitrise-io@2: {}
453+
454+
gradle-configuration-e2e-linux:
455+
meta:
456+
bitrise.io:
457+
stack: linux-docker-android-22.04
458+
envs:
459+
- TEST_APP_URL: git@github.com:bitwarden/android.git
460+
- COMMIT: 2c71ab7d27d7f976766adee7bfd1828d5eda0850
461+
steps:
462+
- bundle::feature-e2e-setup: {}
463+
- script:
464+
title: Enable build cache
465+
inputs:
466+
- content: |-
467+
set -exo pipefail
468+
../bitrise-build-cache-cli enable-for gradle --metrics -d
469+
- script:
470+
title: Create local configuration cache
471+
inputs:
472+
- content: |-
473+
set -exo pipefail
474+
./gradlew debug --configuration-cache --dry-run
475+
- script:
476+
title: Save configuration cache
477+
inputs:
478+
- content: |-
479+
set -exo pipefail
480+
../bitrise-build-cache-cli save-gradle-configuration-cache \
481+
--config-cache-dir "$PWD/.gradle/configuration-cache"
482+
- script:
483+
title: Delete local configuration cache
484+
inputs:
485+
- content: |-
486+
set -exo pipefail
487+
rm -rf .gradle/configuration-cache
488+
- script:
489+
title: Restore configuration cache
490+
inputs:
491+
- content: |-
492+
set -exo pipefail
493+
../bitrise-build-cache-cli restore-gradle-configuration-cache
494+
- script:
495+
title: Build and capture logs
496+
inputs:
497+
- content: |-
498+
set -exo pipefail
499+
(./gradlew debug --configuration-cache 2>&1) | tee "$BITRISE_DEPLOY_DIR/logs.txt"
500+
- script:
501+
title: Check for cache invocations
502+
inputs:
503+
- content: |-
504+
set -exo pipefail
505+
506+
../scripts/check_pattern.sh "$BITRISE_DEPLOY_DIR/logs.txt" \
507+
'Reusing configuration cache.' \
508+
'\[Bitrise Build Cache\].*🤖 Bitrise remote cache enabled' \
509+
'\[Bitrise Build Cache\].*Request metadata invocationId' \
510+
'\[Bitrise Analytics\].*🤖 Bitrise analytics enabled for tasks.*Invocation ID: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
511+
- deploy-to-bitrise-io@2: {}
512+
394513
step_bundles:
395514
generate_gradle_verification_reference:
396515
steps:
@@ -537,6 +656,7 @@ step_bundles:
537656
- repository_url: "$TEST_APP_URL"
538657
- clone_into_dir: "./_tmp"
539658
- branch: "$BRANCH"
659+
- commit: "$COMMIT"
540660
- git-clone: {}
541661
- script:
542662
title: build CLI
@@ -555,7 +675,9 @@ pipelines:
555675
test: {}
556676
feature-e2e-bazel: {}
557677
feature-e2e-gradle-duckduck: {}
558-
# feature-e2e-gradle-bitwarden: {} Until config cache is fixed in their repo
678+
feature-e2e-gradle-bitwarden: {}
679+
gradle-configuration-e2e-osx: {}
680+
gradle-configuration-e2e-linux: {}
559681
triggers:
560682
pull_request:
561683
- source_branch: "*"

internal/gradle/key.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package gradle
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
47

58
type CacheKeyParams struct {
69
IsFallback bool
@@ -17,9 +20,11 @@ func (g *Cache) GetCacheKey(keyParams CacheKeyParams) (string, error) {
1720
return "", fmt.Errorf("cache key is required if BITRISE_APP_SLUG env var is not set")
1821
}
1922

23+
os := runtime.GOOS
24+
2025
if keyParams.IsFallback {
21-
return fmt.Sprintf("gradle-config-cache-metadata-%s", appSlug), nil
26+
return fmt.Sprintf("gradle-config-cache-metadata-%s-%s", appSlug, os), nil
2227
}
2328

24-
return fmt.Sprintf("gradle-config-cache-metadata-%s-%s", appSlug, branch), nil
29+
return fmt.Sprintf("gradle-config-cache-metadata-%s-%s-%s", appSlug, branch, os), nil
2530
}

internal/xcode/cache_key.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package xcode
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
47

58
type CacheKeyParams struct {
69
IsFallback bool
@@ -17,9 +20,11 @@ func GetCacheKey(envProvider func(string) string, keyParams CacheKeyParams) (str
1720
return "", fmt.Errorf("cache key is required if BITRISE_APP_SLUG env var is not set")
1821
}
1922

23+
os := runtime.GOOS
24+
2025
if keyParams.IsFallback {
21-
return fmt.Sprintf("xcode-cache-metadata-%s", appSlug), nil
26+
return fmt.Sprintf("xcode-cache-metadata-%s-%s", appSlug, os), nil
2227
}
2328

24-
return fmt.Sprintf("xcode-cache-metadata-%s-%s", appSlug, branch), nil
29+
return fmt.Sprintf("xcode-cache-metadata-%s-%s-%s", appSlug, branch, os), nil
2530
}

0 commit comments

Comments
 (0)