daml/ci/upload-bazel-metrics.yml
Andreas Herrmann 7b94b0674e
Map shortened scala test suite names to long names on Windows (#10628)
* Generate short to long name mapping in aspect

Maps shortened test names in da_scala_test_suite on Windows to their
long name on Linux and MacOS.

Names are shortened on Windows to avoid exceeding MAX_PATH.

* Script to generate scala test name mapping

* Generate scala-test-suite-name-map.json on Windows

changelog_begin
changelog_end

* Generate UTF-8 with Unix line endings

Otherwise the file will be formatted using UTF-16 with CRLF line
endings, which confuses `jq` on Linux.

* Apply Scala test name remapping before ES upload

* Pipe bazel output into intermediate file

Bazel writes the output of --experimental_show_artifacts to stderr
instead of stdout. In Powershell this means that these outputs are not
plain strings, but instead error objects. Simply redirecting these to
stdout and piping them into further processing will lead to
indeterministically missing items or indeterministically introduced
additional newlines which may break paths.

To work around this we extract the error message from error objects,
introduce appropriate newlines, and write the output to a temporary file
before further processing.

This solution is taken and adapted from
https://stackoverflow.com/a/48671797/841562

* Add copyright header

Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
2021-08-24 17:03:45 +02:00

64 lines
3.2 KiB
YAML

# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
steps:
- template: bash-lib.yml
parameters:
var_name: bash_lib
- bash: |
set -euo pipefail
if [[ $(Agent.OS) = Windows* ]]; then
export PATH="$PATH:$(cygpath "$(powershell "./dev-env/windows/bin/dadew.ps1 enable >\$2; dadew where")/scoop/shims")"
else
eval "$(dev-env/bin/dade assist)"
fi
source $(bash_lib)
jq -nc >job-md.json '{
timestamp: "$(pipeline_timestamp)",
id: "$(pipeline_id)",
agent_id: "$(Agent.Id)",
agent_job_name: "$(Agent.JobName)",
agent_machine_name: "$(Agent.MachineName)",
agent_name: "$(Agent.Name)",
agent_os: "$(Agent.OS)",
agent_os_architecture: "$(Agent.OSArchitecture)",
build_build_id: "$(Build.BuildId)",
build_build_number: "$(Build.BuildNumber)",
build_definition_name: "$(Build.DefinitionName)",
build_source_branch: "$(Build.SourceBranch)",
build_source_branch_name: "$(Build.SourceBranchName)",
build_source_version: "$(Build.SourceVersion)",
system_job_attempt: "$(System.JobAttempt)",
system_job_display_name: "$(System.JobDisplayName)",
system_job_id: "$(System.JobId)",
system_job_name: "$(System.JobName)",
system_pullRequest_pullRequestId: "'"${SYSTEM_PULLREQUEST_PULLREQUESTID:-}"'",
system_pullRequest_pullRequestNumber: "'"${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER:-}"'",
system_pullRequest_mergedAt: "'"${SYSTEM_PULLREQUEST_MERGEDAT:-}"'",
system_pullRequest_sourceBranch: "'"${SYSTEM_PULLREQUEST_SOURCEBRANCH:-}"'",
system_pullRequest_targetBranch: "'"${SYSTEM_PULLREQUEST_TARGETBRANCH:-}"'",
system_pullRequest_sourceRepositoryUri: "'"${SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI:-}"'",
system_pullRequest_sourceCommitId: "'"${SYSTEM_PULLREQUEST_SOURCECOMMITID:-}"'",
git_branch_sha: "$(git_branch_sha)",
git_main_sha: "$(git_main_sha)",
git_fork_point: "$(git_fork_point_sha)",
git_current_branch: "'"$(git branch --show-current)"'",
git_current_commit: "'"$(git rev-parse HEAD)"'",
git_current_tree: "'"$(git rev-parse HEAD:./)"'",
}'
jq <job-md.json .
target_dir="$(Build.StagingDirectory)/$(pipeline_id)"
mkdir -p "$target_dir"
cp "job-md.json" "$target_dir/job-md.json"
for log_file in 'build-profile.json' 'build-events.json' 'test-profile.json' 'test-events.json' 'scala-test-suite-name-map.json'; do
[[ -f "$log_file" ]] && cp "$log_file" "$target_dir/$log_file" || echo "$log_file not found"
done
cd "$(Build.StagingDirectory)"
GZIP=-9 tar --force-local -c -z -f "build-event-logs.tar.gz" "$(pipeline_id)"
date="$(echo $(pipeline_id) | cut -c1-7)/$(echo $(pipeline_id) | cut -c9-10)"
gcs "$GCRED" cp "build-event-logs.tar.gz" "gs://daml-data/bazel-metrics/$date/$(pipeline_id).tar.gz"
condition: and(succeededOrFailed(), eq(variables['System.PullRequest.IsFork'], 'False'))
displayName: 'Upload Bazel metrics'
env:
GCRED: $(GOOGLE_APPLICATION_CREDENTIALS_CONTENT)