Skip to content

Commit 805a42e

Browse files
committed
Add GHA workflow to create a release branch and pin system tests commit sha after minor release
1 parent c85d09f commit 805a42e

File tree

4 files changed

+181
-1
lines changed

4 files changed

+181
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/dd-trace-java:ref:refs/(heads/master|tags/v[0-9]+.[0-9]+.0)
4+
5+
claim_pattern:
6+
event_name: (push|workflow_dispatch)
7+
ref: refs/(heads/master|tags/v[0-9]+\.[0-9]+\.0)
8+
ref_protected: "true"
9+
job_workflow_ref: DataDog/dd-trace-java/\.github/workflows/create-release-branch\.yaml@refs/heads/master
10+
11+
permissions:
12+
contents: write
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
# Read the file and perform the substitution
32+
if [ -f "$TARGET" ]; then
33+
# Perform the substitution and save to temporary file
34+
# We use perl here because sed's regex support varies across platforms
35+
perl -pe "s/$CLEAN_PATTERN/\${1}$REF\${3}/g" "$TARGET" > "$TEMP_FILE"
36+
37+
# Compare files to check if any changes were made
38+
if cmp -s "$TARGET" "$TEMP_FILE"; then
39+
echo "No references found in $TARGET"
40+
else
41+
# Copy the temp file back to the target
42+
cp "$TEMP_FILE" "$TARGET"
43+
echo "✓ Updated references in $TARGET"
44+
fi
45+
else
46+
echo "Error: Target file $TARGET does not exist"
47+
rm -f "$TEMP_FILE"
48+
exit 1
49+
fi
50+
51+
# Clean up temporary file
52+
rm -f "$TEMP_FILE"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Create Release Branch and Pin System-Tests
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.0' # Trigger on minor release tags (e.g. v1.54.0)
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: 'The minor release tag (e.g. v1.54.0)'
11+
required: true
12+
type: string
13+
14+
jobs:
15+
create-release-branch:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
id-token: write # Required for OIDC token federation
20+
steps:
21+
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
22+
id: octo-sts
23+
with:
24+
scope: DataDog/dd-trace-java
25+
policy: self.create-release-branch.push
26+
27+
- name: Determine tag
28+
id: determine-tag
29+
run: |
30+
if [ -n "${{ github.event.inputs.tag }}" ]; then
31+
TAG=${{ github.event.inputs.tag }}
32+
else
33+
TAG=${GITHUB_REF#refs/tags/}
34+
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 }}
41+
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)"
43+
exit 1
44+
fi
45+
echo "Tag format is valid"
46+
47+
- name: Define branch name from tag
48+
id: define-branch
49+
run: |
50+
TAG=${{ steps.determine-tag.outputs.tag }}
51+
BRANCH=$(echo "$TAG" | sed -E 's/^(v[0-9]+\.[0-9]+)\.0$/release\/\1.x/')
52+
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
53+
echo "Target branch: ${BRANCH}"
54+
55+
- name: Checkout dd-trace-java
56+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
57+
58+
- name: Check if branch already exists
59+
id: check-branch
60+
run: |
61+
BRANCH=${{ steps.define-branch.outputs.branch }}
62+
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"
65+
else
66+
echo "exists=false" >> "$GITHUB_OUTPUT"
67+
echo "Branch $BRANCH does not exist, proceeding with following steps"
68+
fi
69+
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 }}
94+
95+
- name: Commit changes
96+
if: steps.check-branch.outputs.exists == 'false'
97+
id: create-commit
98+
run: |
99+
BRANCH=${{ steps.define-branch.outputs.branch }}
100+
SHA=${{ steps.system-test-ref.outputs.commit }}
101+
102+
git config user.name "github-actions[bot]"
103+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
104+
git commit -m "chore: Pin system-tests for release branch" .github/workflows/run-system-tests.yaml
105+
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
106+
107+
- name: Push changes
108+
if: steps.check-branch.outputs.exists == 'false'
109+
uses: DataDog/commit-headless@5a0f3876e0fbdd3a86b3e008acf4ec562db59eee # action/v2.0.1
110+
with:
111+
token: "${{ steps.octo-sts.outputs.token }}"
112+
branch: "${{ steps.define-branch.outputs.branch }}"
113+
branch-from: "${{ github.sha }}"
114+
command: push
115+
commits: "${{ steps.create-commit.outputs.commit }}"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ jobs:
6060
main:
6161
needs:
6262
- build
63-
uses: DataDog/system-tests/.github/workflows/system-tests.yml@main
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
6464
secrets: inherit
6565
permissions:
6666
contents: read
6767
id-token: write
6868
packages: write
6969
with:
7070
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
7172
binaries_artifact: binaries
7273
desired_execution_time: 900 # 15 minutes
7374
scenarios_groups: tracer-release

0 commit comments

Comments
 (0)