Skip to content

Commit 096bb24

Browse files
Merge pull request #105 from bitrise-io/bazel-fields
feat: ACI-3563 collect host cache config metadata
2 parents 2d4a971 + f38d1e4 commit 096bb24

19 files changed

+451
-60
lines changed

bitrise.yml

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ workflows:
9191
machine_type_id: g2-m1.8core
9292
stack: osx-xcode-edge
9393
test:
94-
triggers:
95-
push:
96-
- branch: "main"
97-
pull_request:
98-
- source_branch: "*"
9994
steps:
10095
- activate-ssh-key@4:
10196
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
@@ -266,11 +261,6 @@ workflows:
266261
envs:
267262
- TEST_APP_URL: [email protected]:duckduckgo/Android.git
268263
- BRANCH: develop
269-
triggers:
270-
push:
271-
- branch: "main"
272-
pull_request:
273-
- source_branch: "*"
274264
steps:
275265
- bundle::feature-e2e-setup: {}
276266
- script:
@@ -284,27 +274,23 @@ workflows:
284274
inputs:
285275
- content: |-
286276
set -exo pipefail
287-
(./gradlew debug 2>&1) | tee logs.txt
277+
(./gradlew debug 2>&1) | tee "$BITRISE_DEPLOY_DIR/logs.txt"
288278
- script:
289279
title: Check for cache invocations
290280
inputs:
291281
- content: |-
292282
set -exo pipefail
293283
294-
../scripts/check_pattern.sh "$PWD/logs.txt" \
284+
../scripts/check_pattern.sh "$BITRISE_DEPLOY_DIR/logs.txt" \
295285
'\[Bitrise Build Cache\].*🤖 Bitrise remote cache enabled' \
296286
'\[Bitrise Build Cache\].*Request metadata invocationId' \
297287
'\[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}'
288+
- deploy-to-bitrise-io@2: {}
298289

299290
feature-e2e-gradle-bitwarden:
300291
envs:
301292
- TEST_APP_URL: [email protected]:bitwarden/android.git
302293
- BRANCH: main
303-
triggers:
304-
push:
305-
- branch: "main"
306-
pull_request:
307-
- source_branch: "*"
308294
steps:
309295
- bundle::feature-e2e-setup: {}
310296
- script:
@@ -345,28 +331,27 @@ workflows:
345331
inputs:
346332
- content: |-
347333
set -exo pipefail
348-
(./gradlew debug --configuration-cache 2>&1) | tee logs.txt
334+
(./gradlew debug --configuration-cache 2>&1) | tee "$BITRISE_DEPLOY_DIR/logs.txt"
349335
- script:
350336
title: Check for cache invocations
351337
inputs:
352338
- content: |-
353339
set -exo pipefail
354340
355-
../scripts/check_pattern.sh "$PWD/logs.txt" \
341+
../scripts/check_pattern.sh "$BITRISE_DEPLOY_DIR/logs.txt" \
356342
'Reusing configuration cache.' \
357343
'\[Bitrise Build Cache\].*🤖 Bitrise remote cache enabled' \
358344
'\[Bitrise Build Cache\].*Request metadata invocationId' \
359345
'\[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}'
346+
- deploy-to-bitrise-io@2: {}
360347

361348
feature-e2e-bazel:
349+
meta:
350+
bitrise.io:
351+
stack: linux-docker-android-22.04
362352
envs:
363353
- TEST_APP_URL: [email protected]:bitrise-io/bazel.git
364354
- BRANCH: master
365-
triggers:
366-
push:
367-
- branch: "main"
368-
pull_request:
369-
- source_branch: "*"
370355
steps:
371356
- bundle::feature-e2e-setup: {}
372357
- script@1:
@@ -387,17 +372,23 @@ workflows:
387372
inputs:
388373
- content: |-
389374
set -exo pipefail
390-
(/usr/local/bin/bazel build //src:bazel-dev --announce_rc --copt='-w' 2>&1) | tee logs.txt
375+
(/usr/local/bin/bazel build //src:bazel-dev --announce_rc --copt='-w' 2>&1) | tee "$BITRISE_DEPLOY_DIR/logs.txt"
391376
- script:
392377
title: Check for cache invocations
393378
inputs:
394379
- content: |-
395380
#!/bin/bash
396381
set -exo pipefail
397382
398-
../scripts/check_pattern.sh "$PWD/logs.txt" \
383+
../scripts/check_pattern.sh "$BITRISE_DEPLOY_DIR/logs.txt" \
399384
'--remote_cache=grpcs:\/\/remote-build-cache\.services\.bitrise\.io' \
400-
'Invocation ID: '
385+
'Invocation ID: ' \
386+
'--bes_header=x-os=Linux' \
387+
'--bes_header=x-cpu-cores=[0-9]+' \
388+
'--bes_header=x-mem-size=[0-9]+' \
389+
'--bes_header=x-locale=\w+' \
390+
'--bes_header=x-default-charset=\w+' \
391+
- deploy-to-bitrise-io@2: {}
401392

402393
step_bundles:
403394
generate_gradle_verification_reference:
@@ -559,6 +550,7 @@ step_bundles:
559550
pipelines:
560551
features-e2e:
561552
workflows:
553+
test: {}
562554
feature-e2e-bazel: {}
563555
feature-e2e-gradle-duckduck: {}
564556
feature-e2e-gradle-bitwarden: {}

cmd/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type CreateKVClientParams struct {
2020
ClientName string
2121
AuthConfig common.CacheAuthConfig
2222
EnvProvider common.EnvProviderFunc
23+
CommandFunc common.CommandFunc
2324
Logger log.Logger
2425
}
2526

@@ -44,7 +45,7 @@ func createKVClient(ctx context.Context,
4445
ClientName: params.ClientName,
4546
AuthConfig: params.AuthConfig,
4647
Logger: params.Logger,
47-
CacheConfigMetadata: common.NewCacheConfigMetadata(params.EnvProvider),
48+
CacheConfigMetadata: common.NewCacheConfigMetadata(params.EnvProvider, params.CommandFunc, params.Logger),
4849
CacheOperationID: params.CacheOperationID,
4950
})
5051
if err != nil {

cmd/deleteXcodeDerivedData.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package cmd
22

33
import (
4+
"context"
45
"fmt"
56
"os"
6-
7-
"github.com/spf13/cobra"
8-
9-
"context"
7+
"os/exec"
108
"strings"
119
"time"
1210

@@ -17,6 +15,7 @@ import (
1715
"github.com/bitrise-io/bitrise-build-cache-cli/internal/xcode"
1816
"github.com/bitrise-io/go-utils/v2/log"
1917
"github.com/google/uuid"
18+
"github.com/spf13/cobra"
2019
"google.golang.org/grpc/codes"
2120
"google.golang.org/grpc/status"
2221
)
@@ -38,7 +37,13 @@ var deleteXcodeDerivedDataCmd = &cobra.Command{
3837
cacheKey, _ := cmd.Flags().GetString("key")
3938
empty, _ := cmd.Flags().GetBool("empty")
4039

41-
if err := deleteXcodeDerivedDataCmdFn(cmd.Context(), cacheKey, empty, logger, os.Getenv); err != nil {
40+
if err := deleteXcodeDerivedDataCmdFn(cmd.Context(), cacheKey, empty, logger,
41+
os.Getenv,
42+
func(name string, v ...string) (string, error) {
43+
output, err := exec.Command(name, v...).Output()
44+
45+
return string(output), err
46+
}); err != nil {
4247
return fmt.Errorf("delete Xcode DerivedData into Bitrise Build Cache: %w", err)
4348
}
4449

@@ -55,7 +60,12 @@ func init() {
5560
deleteXcodeDerivedDataCmd.Flags().Bool("empty", false, "If true, upload an empty metadata")
5661
}
5762

58-
func deleteXcodeDerivedDataCmdFn(ctx context.Context, providedCacheKey string, uploadEmpty bool, logger log.Logger, envProvider func(string) string) error {
63+
func deleteXcodeDerivedDataCmdFn(ctx context.Context,
64+
providedCacheKey string,
65+
uploadEmpty bool,
66+
logger log.Logger,
67+
envProvider func(string) string,
68+
commandFunc func(string, ...string) (string, error)) error {
5969
logger.Infof("(i) Check Auth Config")
6070
authConfig, err := common.ReadAuthConfigFromEnvironments(envProvider)
6171
if err != nil {
@@ -79,6 +89,7 @@ func deleteXcodeDerivedDataCmdFn(ctx context.Context, providedCacheKey string, u
7989
ClientName: ClientNameXcode,
8090
AuthConfig: authConfig,
8191
EnvProvider: envProvider,
92+
CommandFunc: commandFunc,
8293
Logger: logger,
8394
})
8495
if err != nil {

cmd/enableForBazel.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"path/filepath"
78

89
bazelconfig "github.com/bitrise-io/bitrise-build-cache-cli/internal/config/bazel"
@@ -79,7 +80,13 @@ func enableForBazelCmdFn(logger log.Logger, homeDirPath string, envProvider func
7980
}
8081
}
8182
// Metadata
82-
cacheConfig := common.NewCacheConfigMetadata(os.Getenv)
83+
cacheConfig := common.NewCacheConfigMetadata(os.Getenv,
84+
func(name string, v ...string) (string, error) {
85+
output, err := exec.Command(name, v...).Output()
86+
87+
return string(output), err
88+
},
89+
logger)
8390
logger.Infof("(i) Cache Config: %+v", cacheConfig)
8491

8592
logger.Infof("(i) Check ~/.bazelrc")

cmd/enableForGradle.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"os"
7+
"os/exec"
78
"path/filepath"
89

910
"github.com/bitrise-io/bitrise-build-cache-cli/internal/config/common"
@@ -125,7 +126,12 @@ func enableForGradleCmdFn(logger log.Logger, gradleHomePath string, envProvider
125126
return errInvalidCacheLevel
126127
}
127128
// Metadata
128-
cacheConfigMetadata := common.NewCacheConfigMetadata(os.Getenv)
129+
cacheConfigMetadata := common.NewCacheConfigMetadata(os.Getenv,
130+
func(name string, v ...string) (string, error) {
131+
output, err := exec.Command(name, v...).Output()
132+
133+
return string(output), err
134+
}, logger)
129135
logger.Infof("(i) Cache Config Metadata: %+v", cacheConfigMetadata)
130136

131137
prefs := gradleconfig.Preferences{

cmd/gradleVerificationAddDeps.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67

78
"github.com/bitrise-io/bitrise-build-cache-cli/internal/config/common"
89
gradleconfig "github.com/bitrise-io/bitrise-build-cache-cli/internal/config/gradle"
@@ -57,7 +58,11 @@ func addGradlePluginsFn(logger log.Logger, gradleHomePath string, envProvider fu
5758
logger.Infof("(i) Debug mode and verbose logs: %t", isDebugLogMode)
5859

5960
// Metadata
60-
cacheConfigMetadata := common.NewCacheConfigMetadata(os.Getenv)
61+
cacheConfigMetadata := common.NewCacheConfigMetadata(os.Getenv, func(name string, v ...string) (string, error) {
62+
output, err := exec.Command(name, v...).Output()
63+
64+
return string(output), err
65+
}, logger)
6166
logger.Infof("(i) Cache Config Metadata: %+v", cacheConfigMetadata)
6267

6368
authToken := "placeholder-token"

cmd/restoreGradleConfigurationCache.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"os/exec"
89
"strings"
910

1011
"github.com/bitrise-io/bitrise-build-cache-cli/internal/build_cache/kv"
@@ -44,7 +45,12 @@ var restoreGradleConfigCacheCmd = &cobra.Command{
4445
authConfig,
4546
cacheKey,
4647
logger,
47-
os.Getenv)
48+
os.Getenv,
49+
func(name string, v ...string) (string, error) {
50+
output, err := exec.Command(name, v...).Output()
51+
52+
return string(output), err
53+
})
4854
if err != nil {
4955
return fmt.Errorf("restore Gradle config cache from Bitrise Build Cache: %w", err)
5056
}
@@ -65,13 +71,15 @@ func restoreGradleConfigCacheCmdFn(ctx context.Context,
6571
authConfig common.CacheAuthConfig,
6672
providedCacheKey string,
6773
logger log.Logger,
68-
envProvider func(string) string) error {
74+
envProvider func(string) string,
75+
commandFunc func(string, ...string) (string, error)) error {
6976
kvClient, err := createKVClient(ctx,
7077
CreateKVClientParams{
7178
CacheOperationID: uuid.NewString(),
7279
ClientName: ClientNameGradleConfigCache,
7380
AuthConfig: authConfig,
7481
EnvProvider: envProvider,
82+
CommandFunc: commandFunc,
7583
Logger: logger,
7684
})
7785
if err != nil {

cmd/restoreXcodeDerivedDataFiles.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"os/exec"
89
"os/user"
910
"strings"
1011
"time"
@@ -60,8 +61,24 @@ var restoreXcodeDerivedDataFilesCmd = &cobra.Command{
6061
return fmt.Errorf("read auth config from environments: %w", err)
6162
}
6263

63-
op, cmdError := restoreXcodeDerivedDataFilesCmdFn(cmd.Context(), authConfig, XCodeCacheMetadataPath, projectRoot,
64-
cacheKey, logger, tracker, startT, os.Getenv, isDebugLogMode, skipExisting, forceOverwrite, maxLoggedErrors)
64+
op, cmdError := restoreXcodeDerivedDataFilesCmdFn(cmd.Context(),
65+
authConfig,
66+
XCodeCacheMetadataPath,
67+
projectRoot,
68+
cacheKey,
69+
logger,
70+
tracker,
71+
startT,
72+
os.Getenv,
73+
func(name string, v ...string) (string, error) {
74+
output, err := exec.Command(name, v...).Output()
75+
76+
return string(output), err
77+
},
78+
isDebugLogMode,
79+
skipExisting,
80+
forceOverwrite,
81+
maxLoggedErrors)
6582
if op != nil {
6683
if cmdError != nil {
6784
errStr := cmdError.Error()
@@ -97,15 +114,24 @@ func init() {
97114
restoreXcodeDerivedDataFilesCmd.Flags().Int("max-logged-errors", 150, "The maximum number of errors logged to the console during restoring the cache.")
98115
}
99116

100-
func restoreXcodeDerivedDataFilesCmdFn(ctx context.Context, authConfig common.CacheAuthConfig, cacheMetadataPath, projectRoot, providedCacheKey string, logger log.Logger,
101-
tracker xcode.StepAnalyticsTracker, startT time.Time, envProvider func(string) string, isDebugLogMode, skipExisting, forceOverwrite bool, maxLoggedDownloadErrors int) (*xa.CacheOperation, error) {
117+
func restoreXcodeDerivedDataFilesCmdFn(ctx context.Context,
118+
authConfig common.CacheAuthConfig,
119+
cacheMetadataPath, projectRoot, providedCacheKey string,
120+
logger log.Logger,
121+
tracker xcode.StepAnalyticsTracker,
122+
startT time.Time,
123+
envProvider func(string) string,
124+
commandFunc func(string, ...string) (string, error),
125+
isDebugLogMode, skipExisting, forceOverwrite bool,
126+
maxLoggedDownloadErrors int) (*xa.CacheOperation, error) {
102127
op := newCacheOperation(startT, xa.OperationTypeDownload, envProvider)
103128
kvClient, err := createKVClient(ctx,
104129
CreateKVClientParams{
105130
CacheOperationID: op.OperationID,
106131
ClientName: ClientNameXcode,
107132
AuthConfig: authConfig,
108133
EnvProvider: envProvider,
134+
CommandFunc: commandFunc,
109135
Logger: logger,
110136
})
111137
if err != nil {

0 commit comments

Comments
 (0)