Skip to content

Commit 2646e78

Browse files
authored
Merge pull request #4715 from DataDog/tonycthsu/refactor-update-system-tests
Refactor system test update job
2 parents b9784c5 + 780e2d4 commit 2646e78

File tree

3 files changed

+56
-30
lines changed

3 files changed

+56
-30
lines changed

.github/scripts/update_reference.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/scripts/update_reference.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# This script updates the reference in a YAML file.
4+
5+
# Check if required environment variables are set
6+
if [ -z "$TARGET" ]; then
7+
echo "Error: TARGET environment variable is not set"
8+
exit 1
9+
fi
10+
11+
if [ -z "$REF" ]; then
12+
echo "Error: REF environment variable is not set"
13+
exit 1
14+
fi
15+
16+
if [ -z "$PATTERN" ]; then
17+
echo "Error: PATTERN environment variable is not set"
18+
exit 1
19+
fi
20+
21+
echo "Target: $TARGET"
22+
echo "Ref: $REF"
23+
24+
# Remove leading and trailing forward slashes from pattern
25+
CLEAN_PATTERN=$(echo "$PATTERN" | sed 's/^\///;s/\/$//')
26+
echo "Pattern: $CLEAN_PATTERN"
27+
28+
# Create a temporary file
29+
TEMP_FILE=$(mktemp)
30+
31+
# Set trap to cleanup on script exit
32+
trap 'rm -f "$TEMP_FILE"' EXIT
33+
34+
# Read the file and perform the substitution
35+
if [ -f "$TARGET" ]; then
36+
# Perform the substitution and save to temporary file
37+
# We use perl here because sed's regex support varies across platforms
38+
perl -pe "s/$CLEAN_PATTERN/\${1}$REF\${3}/g" "$TARGET" > "$TEMP_FILE"
39+
40+
# Compare files to check if any changes were made
41+
if cmp -s "$TARGET" "$TEMP_FILE"; then
42+
echo "No references found in $TARGET"
43+
else
44+
# Copy the temp file back to the target
45+
cp "$TEMP_FILE" "$TARGET"
46+
echo "✓ Updated references in $TARGET"
47+
fi
48+
else
49+
echo "Error: Target file $TARGET does not exist"
50+
exit 1
51+
fi

.github/workflows/update-system-tests.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ jobs:
4040
persist-credentials: false
4141
ref: ${{ github.event.inputs.ref || '' }}
4242

43-
- run: .github/scripts/update_reference.rb
43+
- run: .github/scripts/update_reference.sh
4444
env:
4545
TARGET: ".github/workflows/system-tests.yml"
4646
PATTERN: '(\s*SYSTEM_TESTS_REF:\s+)(\S+)(\s+# Automated:.*)'
4747
REF: ${{ steps.system-test-ref.outputs.commit }}
4848

49-
- run: .github/scripts/update_reference.rb
49+
- run: .github/scripts/update_reference.sh
5050
env:
5151
TARGET: ".github/workflows/parametric-tests.yml"
5252
PATTERN: '(\s*SYSTEM_TESTS_REF:\s+)(\S+)(\s+# Automated:.*)'
@@ -70,12 +70,13 @@ jobs:
7070
branch: auto-generate/update-system-tests
7171
title: '[🤖] Update System Tests'
7272
base: master
73+
sign-commits: true
7374
labels: dev/internal
74-
commit-message: "[🤖] Update System Tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
75+
commit-message: "[🤖] Update System Tests: ${{github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
7576
delete-branch: true
7677
add-paths: |
7778
.github/
7879
body: |
79-
_This is an auto-generated PR from [here](https://github.com/DataDog/dd-trace-rb/blob/master/.github/workflows/update-system-tests.yml)_
80+
_This is an auto-generated PR from [here](${{github.server_url}}/${{ github.repository }}/blob/master/.github/workflows/update-system-tests.yml)_
8081
The PR updates the system tests (Updated to commit: ${{ steps.system-test-ref.outputs.commit }})
8182
Please review the changes and merge when ready

0 commit comments

Comments
 (0)