11#! /usr/bin/env bash
22set -euo pipefail
33
4- # This script updates the system-tests reference in run-system-tests.yaml.
4+ # This script updates the system-tests references used by GitHub Actions ( run-system-tests.yaml) and GitLab CI (.gitlab-ci.yml) .
55# The reference will be updated with the latest commit SHA of the given branch (or `main` if not set) of https://github.com/DataDog/system-tests.
66# Usage: BRANCH=<branch-name> tooling/update_system_test_reference.sh
77
@@ -11,9 +11,11 @@ if [ -z "${BRANCH:-}" ]; then
1111 echo " BRANCH is not set. Defaulting to 'main'."
1212fi
1313
14- TARGET=" .github/workflows/run-system-tests.yaml" # target file to update
15- PATTERN_1=' (\s*system-tests\.yml@)(\S+)(\s+# system tests.*)' # pattern to update the "system-tests.yml@" reference
16- PATTERN_2=' (\s*ref: )(\S+)(\s+# system tests.*)' # pattern to update the "ref:" reference
14+ GITHUB_TARGET=" .github/workflows/run-system-tests.yaml"
15+ GITLAB_TARGET=" .gitlab-ci.yml"
16+ GITHUB_PATTERN_1=' (\s*system-tests\.yml@)(\S+)(\s+# system tests.*)' # pattern to update the "system-tests.yml@" reference
17+ GITHUB_PATTERN_2=' (\s*ref: )(\S+)(\s+# system tests.*)' # pattern to update the "ref:" reference
18+ GITLAB_PATTERN=' (\s*SYSTEM_TESTS_REF:\s*)(\S+)(\s+# system tests.*)' # pattern to update the GitLab SYSTEM_TESTS_REF variable
1719
1820echo " Fetching latest commit SHA for system-tests branch: $BRANCH "
1921REF=$( git ls-remote https://github.com/DataDog/system-tests " refs/heads/$BRANCH " | cut -f 1)
@@ -23,8 +25,13 @@ if [ -z "$REF" ]; then
2325fi
2426echo " Fetched SHA: $REF "
2527
26- if [ ! -f " $TARGET " ]; then
27- echo " Error: Target file $TARGET does not exist"
28+ if [ ! -f " $GITHUB_TARGET " ]; then
29+ echo " Error: Target file $GITHUB_TARGET does not exist"
30+ exit 1
31+ fi
32+
33+ if [ ! -f " $GITLAB_TARGET " ]; then
34+ echo " Error: Target file $GITLAB_TARGET does not exist"
2835 exit 1
2936fi
3037
@@ -33,13 +40,18 @@ TEMP_FILE=$(mktemp)
3340
3441# Update the "system-tests.yml@" reference
3542echo " Updating 'system-tests.yml@' reference..."
36- perl -pe " s/$PATTERN_1 /\$ {1}$REF \$ {3}/g" " $TARGET " > " $TEMP_FILE "
37- cp " $TEMP_FILE " " $TARGET "
43+ perl -pe " s/$GITHUB_PATTERN_1 /\$ {1}$REF \$ {3}/g" " $GITHUB_TARGET " > " $TEMP_FILE "
44+ cp " $TEMP_FILE " " $GITHUB_TARGET "
3845
3946# Update the "ref:" reference
4047echo " Updating 'ref:' reference..."
41- perl -pe " s/$PATTERN_2 /\$ {1}$REF \$ {3}/g" " $TARGET " > " $TEMP_FILE "
42- cp " $TEMP_FILE " " $TARGET "
48+ perl -pe " s/$GITHUB_PATTERN_2 /\$ {1}$REF \$ {3}/g" " $GITHUB_TARGET " > " $TEMP_FILE "
49+ cp " $TEMP_FILE " " $GITHUB_TARGET "
50+
51+ # Update the GitLab SYSTEM_TESTS_REF variable
52+ echo " Updating 'SYSTEM_TESTS_REF' reference..."
53+ perl -pe " s/$GITLAB_PATTERN /\$ {1}$REF \$ {3}/g" " $GITLAB_TARGET " > " $TEMP_FILE "
54+ cp " $TEMP_FILE " " $GITLAB_TARGET "
4355
4456# Clean up temporary file
4557rm -f " $TEMP_FILE "
0 commit comments