Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

timestamp gitlab ci job outputs #13605

Merged
merged 4 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ variables:
.kubernetes-env:
image: "${CI_IMAGE}"
before_script:
- !reference [.timestamp, before_script]
- !reference [.job-switcher, before_script]
- !reference [.prepare-env, before_script]
tags:
Expand Down Expand Up @@ -141,6 +142,7 @@ variables:
.docker-env:
image: "${CI_IMAGE}"
before_script:
- !reference [.timestamp, before_script]
- !reference [.job-switcher, before_script]
- !reference [.prepare-env, before_script]
- !reference [.rust-info-script, script]
Expand Down Expand Up @@ -310,6 +312,7 @@ include:
- local: scripts/ci/gitlab/default-pipeline.yml
rules:
- if: $PIPELINE != "automatic-crate-publishing"
- scripts/ci/gitlab/timestamp.yml

#### stage: notify

Expand Down
3 changes: 3 additions & 0 deletions scripts/ci/gitlab/pipeline/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ build-linux-substrate:
- job: test-linux-stable
artifacts: false
before_script:
- !reference [.timestamp, before_script]
- !reference [.job-switcher, before_script]
- mkdir -p ./artifacts/substrate/
- !reference [.rusty-cachier, before_script]
Expand Down Expand Up @@ -95,6 +96,7 @@ build-linux-substrate:
# this variable gets overriden by "rusty-cachier environment inject", use the value as default
CARGO_TARGET_DIR: "$CI_PROJECT_DIR/target"
before_script:
- !reference [.timestamp, before_script]
- !reference [.job-switcher, before_script]
- mkdir -p ./artifacts/subkey
- !reference [.rusty-cachier, before_script]
Expand All @@ -120,6 +122,7 @@ build-subkey-macos:
# duplicating before_script & script sections from .build-subkey hidden job
# to overwrite rusty-cachier integration as it doesn't work on macos
before_script:
# skip timestamp script, the osx bash doesn't support printf %()T
- !reference [.job-switcher, before_script]
- mkdir -p ./artifacts/subkey
script:
Expand Down
5 changes: 4 additions & 1 deletion scripts/ci/gitlab/pipeline/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ cargo-check-benches:
- .collect-artifacts
- .pipeline-stopper-artifacts
before_script:
- !reference [.timestamp, before_script]
# perform rusty-cachier operations before any further modifications to the git repo to make cargo feel cheated not so much
- !reference [.rust-info-script, script]
- !reference [.job-switcher, before_script]
Expand Down Expand Up @@ -145,7 +146,8 @@ node-bench-regression-guard:
artifacts: true
variables:
CI_IMAGE: "paritytech/node-bench-regression-guard:latest"
before_script: [""]
before_script:
- !reference [.timestamp, before_script]
script:
- echo "------- IMPORTANT -------"
- echo "node-bench-regression-guard depends on the results of a cargo-check-benches job"
Expand Down Expand Up @@ -419,6 +421,7 @@ cargo-check-each-crate-macos:
- .collect-artifacts
- .pipeline-stopper-artifacts
before_script:
# skip timestamp script, the osx bash doesn't support printf %()T
- !reference [.job-switcher, before_script]
- !reference [.rust-info-script, script]
- !reference [.pipeline-stopper-vars, script]
Expand Down
27 changes: 27 additions & 0 deletions scripts/ci/gitlab/timestamp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.timestamp:
before_script:
- |
echo "Install timestamp handler"
eval '
# https://gist.github.com/altaua/477285db40181ef1793bbed5bae32c6b
# based on https://gist.github.com/jstine35/e0fc0e06ec06d74bc3ebd67585bf2a1d

s_datestamp() {
TZ=UTC
eof=""
while [[ -z "${eof}" ]]; do
IFS="" read -r line || eof=1
printf "[%(%F %T)T] %s\n" -1 "${line}"
done
}

cleanup() {
exec >/dev/null 2>&1
wait "${TIMESTAMP_PID}"
}

exec > >(s_datestamp) 2>&1

TIMESTAMP_PID=$!
trap cleanup EXIT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I don't understand what is it for) Could you please explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's to fix a bug in the original script: The main job script might finish before the s_datestamp process substitution has had a chance to process all output; if we don't wait for it, bash will just exit immediately, killing s_datestamp and thus discarding the last chunk of output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Incidentally, that's what made us not see the timeout error message in test-linux-stable-int for #13047)

'