Skip to content

Commit dae2904

Browse files
committed
Clean workflow and script
1 parent c0a94e8 commit dae2904

4 files changed

Lines changed: 63 additions & 97 deletions

File tree

.github/scripts/update_system_test_reference.sh

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

.github/workflows/create-release-branch.yaml

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,18 @@ jobs:
3232
else
3333
TAG=${GITHUB_REF#refs/tags/}
3434
fi
35-
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
36-
echo "Processing release tag: ${TAG}"
37-
38-
- name: Validate tag format
39-
run: |
40-
TAG=${{ steps.determine-tag.outputs.tag }}
4135
if ! [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.0$ ]]; then
42-
echo "Error: Tag $TAG is not a valid minor release tag (expected format: vX.Y.0)"
36+
echo "Error: Tag $TAG is not in the expected format: vX.Y.0"
4337
exit 1
4438
fi
45-
echo "Tag format is valid"
39+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
4640
4741
- name: Define branch name from tag
4842
id: define-branch
4943
run: |
5044
TAG=${{ steps.determine-tag.outputs.tag }}
51-
BRANCH=$(echo "$TAG" | sed -E 's/^(v[0-9]+\.[0-9]+)\.0$/release\/\1.x/')
45+
BRANCH="release/${TAG%.0}.x"
5246
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
53-
echo "Target branch: ${BRANCH}"
5447
5548
- name: Checkout dd-trace-java
5649
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
@@ -60,52 +53,28 @@ jobs:
6053
run: |
6154
BRANCH=${{ steps.define-branch.outputs.branch }}
6255
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
63-
echo "exists=true" >> "$GITHUB_OUTPUT"
64-
echo "Branch $BRANCH already exists, skipping following steps"
56+
echo "creating_new_branch=false" >> "$GITHUB_OUTPUT"
57+
echo "Branch $BRANCH already exists - skipping following steps"
6558
else
66-
echo "exists=false" >> "$GITHUB_OUTPUT"
67-
echo "Branch $BRANCH does not exist, proceeding with following steps"
59+
echo "creating_new_branch=true" >> "$GITHUB_OUTPUT"
60+
echo "Branch $BRANCH does not exist - proceeding with following steps"
6861
fi
6962
70-
- name: Checkout system-tests to get latest SHA
71-
if: steps.check-branch.outputs.exists == 'false'
72-
id: system-test-ref
73-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
74-
with:
75-
repository: "DataDog/system-tests"
76-
path: system-tests
77-
ref: main
78-
79-
- name: Update reference 1/2 in run-system-tests.yaml
80-
if: steps.check-branch.outputs.exists == 'false'
81-
run: .github/scripts/update_system_test_reference.sh
82-
env:
83-
TARGET: ".github/workflows/run-system-tests.yaml"
84-
PATTERN: '(\s*system-tests\.yml@)(\S+)(\s+# system tests.*)'
85-
REF: ${{ steps.system-test-ref.outputs.commit }}
86-
87-
- name: Update reference 2/2 in run-system-tests.yaml
88-
if: steps.check-branch.outputs.exists == 'false'
89-
run: .github/scripts/update_system_test_reference.sh
90-
env:
91-
TARGET: ".github/workflows/run-system-tests.yaml"
92-
PATTERN: '(\s*ref: )(\S+)(\s+# system tests.*)'
93-
REF: ${{ steps.system-test-ref.outputs.commit }}
63+
- name: Update system-tests references to latest commit SHA on main
64+
if: steps.check-branch.outputs.creating_new_branch == 'true'
65+
run: BRANCH=main ./tooling/update_system_test_reference.sh
9466

9567
- name: Commit changes
96-
if: steps.check-branch.outputs.exists == 'false'
68+
if: steps.check-branch.outputs.creating_new_branch == 'true'
9769
id: create-commit
9870
run: |
99-
BRANCH=${{ steps.define-branch.outputs.branch }}
100-
SHA=${{ steps.system-test-ref.outputs.commit }}
101-
10271
git config user.name "github-actions[bot]"
10372
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
10473
git commit -m "chore: Pin system-tests for release branch" .github/workflows/run-system-tests.yaml
10574
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
10675
10776
- name: Push changes
108-
if: steps.check-branch.outputs.exists == 'false'
77+
if: steps.check-branch.outputs.creating_new_branch == 'true'
10978
uses: DataDog/commit-headless@5a0f3876e0fbdd3a86b3e008acf4ec562db59eee # action/v2.0.1
11079
with:
11180
token: "${{ steps.octo-sts.outputs.token }}"

.github/workflows/run-system-tests.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ jobs:
6060
main:
6161
needs:
6262
- build
63-
uses: DataDog/system-tests/.github/workflows/system-tests.yml@main # system tests are pinned for releases only: the create-release-branch workflow depends on this comment to update the reference
63+
# If you change the following comment, update the pattern in the update_system_test_reference.sh script to match.
64+
uses: DataDog/system-tests/.github/workflows/system-tests.yml@main # system tests are pinned for releases only
6465
secrets: inherit
6566
permissions:
6667
contents: read
6768
id-token: write
6869
packages: write
6970
with:
7071
library: java
71-
ref: main # system tests are pinned for releases only: the create-release-branch workflow depends on this comment to update the reference
72+
# If you change the following comment, update the pattern in the update_system_test_reference.sh script to match.
73+
ref: main # system tests are pinned for releases only
7274
binaries_artifact: binaries
7375
desired_execution_time: 900 # 15 minutes
7476
scenarios_groups: tracer-release
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# This script updates the system-tests reference in run-system-tests.yaml.
5+
# 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.
6+
# Usage: BRANCH=<branch-name> tooling/update_system_test_reference.sh
7+
8+
# Set BRANCH to main if not set
9+
if [ -z "${BRANCH:-}" ]; then
10+
BRANCH="main"
11+
echo "BRANCH is not set. Defaulting to 'main'."
12+
fi
13+
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
17+
18+
echo "Fetching latest commit SHA for system-tests branch: $BRANCH"
19+
REF=$(git ls-remote https://github.com/DataDog/system-tests "refs/heads/$BRANCH" | cut -f 1)
20+
if [ -z "$REF" ]; then
21+
echo "Error: Failed to fetch commit SHA for branch $BRANCH"
22+
exit 1
23+
fi
24+
echo "Fetched SHA: $REF"
25+
26+
if [ ! -f "$TARGET" ]; then
27+
echo "Error: Target file $TARGET does not exist"
28+
exit 1
29+
fi
30+
31+
# Save the substitution results to a temporary file first
32+
TEMP_FILE=$(mktemp)
33+
34+
# Update the "system-tests.yml@" reference
35+
echo "Updating 'system-tests.yml@' reference..."
36+
perl -pe "s/$PATTERN_1/\${1}$REF\${3}/g" "$TARGET" > "$TEMP_FILE"
37+
cp "$TEMP_FILE" "$TARGET"
38+
39+
# Update the "ref:" reference
40+
echo "Updating 'ref:' reference..."
41+
perl -pe "s/$PATTERN_2/\${1}$REF\${3}/g" "$TARGET" > "$TEMP_FILE"
42+
cp "$TEMP_FILE" "$TARGET"
43+
44+
# Clean up temporary file
45+
rm -f "$TEMP_FILE"
46+
47+
echo "Done updating system-tests references to $REF"

0 commit comments

Comments
 (0)