From 8945c1bd42e61c80e80360b8bbc70c005ccbaf4c Mon Sep 17 00:00:00 2001
From: Mira Ressel <mira@parity.io>
Date: Wed, 15 Mar 2023 17:37:34 +0100
Subject: [PATCH] timestamp gitlab ci job outputs (#13605)

* timestamp gitlab ci job outputs

Based on previous work by @alvicsam in #13047.

* inline timestamp script

Some of our jobs don't check out the substrate repo.

* include .timestamp in pipelines overriding the default before_script

Still not including it in the zombienet jobs, they have their own
timestamping anyway.

* move timestamp.yml to shared pipeline repo

https://gitlab.parity.io/parity/infrastructure/ci_cd/shared
---
 substrate/.gitlab-ci.yml                       | 4 ++++
 substrate/scripts/ci/gitlab/pipeline/build.yml | 3 +++
 substrate/scripts/ci/gitlab/pipeline/test.yml  | 5 ++++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/substrate/.gitlab-ci.yml b/substrate/.gitlab-ci.yml
index 94fb3c608b7..44f98db3bf1 100644
--- a/substrate/.gitlab-ci.yml
+++ b/substrate/.gitlab-ci.yml
@@ -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:
@@ -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]
@@ -310,6 +312,8 @@ include:
   - local: scripts/ci/gitlab/default-pipeline.yml
     rules:
       - if: $PIPELINE != "automatic-crate-publishing"
+  - project: parity/infrastructure/ci_cd/shared
+    file: /common/timestamp.yml
 
 #### stage:                        notify
 
diff --git a/substrate/scripts/ci/gitlab/pipeline/build.yml b/substrate/scripts/ci/gitlab/pipeline/build.yml
index 02f25a02a2c..0a36599c70e 100644
--- a/substrate/scripts/ci/gitlab/pipeline/build.yml
+++ b/substrate/scripts/ci/gitlab/pipeline/build.yml
@@ -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]
@@ -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]
@@ -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:
diff --git a/substrate/scripts/ci/gitlab/pipeline/test.yml b/substrate/scripts/ci/gitlab/pipeline/test.yml
index 49dbb194fb6..fd031d9aa56 100644
--- a/substrate/scripts/ci/gitlab/pipeline/test.yml
+++ b/substrate/scripts/ci/gitlab/pipeline/test.yml
@@ -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]
@@ -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"
@@ -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]
-- 
GitLab