diff --git a/.github/chainguard/self.update-system-tests.push.sts.yaml b/.github/chainguard/self.update-system-tests.push.sts.yaml new file mode 100644 index 00000000000..0127556df84 --- /dev/null +++ b/.github/chainguard/self.update-system-tests.push.sts.yaml @@ -0,0 +1,12 @@ +issuer: https://token.actions.githubusercontent.com + +subject: repo:DataDog/dd-trace-java:ref:refs/(heads/master|tags/v[0-9]+.[0-9]+.0) + +claim_pattern: + event_name: (push|workflow_dispatch) + ref: refs/(heads/master|tags/v[0-9]+\.[0-9]+\.0) + ref_protected: "true" + job_workflow_ref: DataDog/dd-trace-java/\.github/workflows/create-release-branch\.yaml@refs/heads/master + +permissions: + contents: write diff --git a/.github/workflows/create-release-branch.yaml b/.github/workflows/create-release-branch.yaml new file mode 100644 index 00000000000..bcd3bc4aa77 --- /dev/null +++ b/.github/workflows/create-release-branch.yaml @@ -0,0 +1,84 @@ +name: Create Release Branch and Pin System-Tests + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.0' # Trigger on minor release tags (e.g. v1.54.0) + workflow_dispatch: + inputs: + tag: + description: 'The minor release tag (e.g. v1.54.0)' + required: true + type: string + +jobs: + create-release-branch: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # Required for OIDC token federation + steps: + - uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3 + id: octo-sts + with: + scope: DataDog/dd-trace-java + policy: self.update-system-tests.push + + - name: Determine tag + id: determine-tag + run: | + if [ -n "${{ github.event.inputs.tag }}" ]; then + TAG=${{ github.event.inputs.tag }} + else + TAG=${GITHUB_REF#refs/tags/} + fi + if ! [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.0$ ]]; then + echo "Error: Tag $TAG is not in the expected format: vX.Y.0" + exit 1 + fi + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + + - name: Define branch name from tag + id: define-branch + run: | + TAG=${{ steps.determine-tag.outputs.tag }} + BRANCH="release/${TAG%.0}.x" + echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT" + + - name: Checkout dd-trace-java + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0 + + - name: Check if branch already exists + id: check-branch + run: | + BRANCH=${{ steps.define-branch.outputs.branch }} + if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then + echo "creating_new_branch=false" >> "$GITHUB_OUTPUT" + echo "Branch $BRANCH already exists - skipping following steps" + else + echo "creating_new_branch=true" >> "$GITHUB_OUTPUT" + echo "Branch $BRANCH does not exist - proceeding with following steps" + fi + + - name: Update system-tests references to latest commit SHA on main + if: steps.check-branch.outputs.creating_new_branch == 'true' + run: BRANCH=main ./tooling/update_system_test_reference.sh + + - name: Commit changes + if: steps.check-branch.outputs.creating_new_branch == 'true' + id: create-commit + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git commit -m "chore: Pin system-tests for release branch" .github/workflows/run-system-tests.yaml + echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + + - name: Push changes + if: steps.check-branch.outputs.creating_new_branch == 'true' + uses: DataDog/commit-headless@5a0f3876e0fbdd3a86b3e008acf4ec562db59eee # action/v2.0.1 + with: + token: "${{ steps.octo-sts.outputs.token }}" + branch: "${{ steps.define-branch.outputs.branch }}" + branch-from: "${{ github.sha }}" + command: push + commits: "${{ steps.create-commit.outputs.commit }}" diff --git a/.github/workflows/run-system-tests.yaml b/.github/workflows/run-system-tests.yaml index 01bf54dfa98..694f3e02829 100644 --- a/.github/workflows/run-system-tests.yaml +++ b/.github/workflows/run-system-tests.yaml @@ -60,7 +60,8 @@ jobs: main: needs: - build - uses: DataDog/system-tests/.github/workflows/system-tests.yml@main + # If you change the following comment, update the pattern in the update_system_test_reference.sh script to match. + uses: DataDog/system-tests/.github/workflows/system-tests.yml@main # system tests are pinned for releases only secrets: inherit permissions: contents: read @@ -68,6 +69,8 @@ jobs: packages: write with: library: java + # If you change the following comment, update the pattern in the update_system_test_reference.sh script to match. + ref: main # system tests are pinned for releases only binaries_artifact: binaries desired_execution_time: 900 # 15 minutes scenarios_groups: tracer-release diff --git a/tooling/update_system_test_reference.sh b/tooling/update_system_test_reference.sh new file mode 100644 index 00000000000..951fe8e4b1d --- /dev/null +++ b/tooling/update_system_test_reference.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -euo pipefail + +# This script updates the system-tests reference in run-system-tests.yaml. +# 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. +# Usage: BRANCH= tooling/update_system_test_reference.sh + +# Set BRANCH to main if not set +if [ -z "${BRANCH:-}" ]; then + BRANCH="main" + echo "BRANCH is not set. Defaulting to 'main'." +fi + +TARGET=".github/workflows/run-system-tests.yaml" # target file to update +PATTERN_1='(\s*system-tests\.yml@)(\S+)(\s+# system tests.*)' # pattern to update the "system-tests.yml@" reference +PATTERN_2='(\s*ref: )(\S+)(\s+# system tests.*)' # pattern to update the "ref:" reference + +echo "Fetching latest commit SHA for system-tests branch: $BRANCH" +REF=$(git ls-remote https://github.com/DataDog/system-tests "refs/heads/$BRANCH" | cut -f 1) +if [ -z "$REF" ]; then + echo "Error: Failed to fetch commit SHA for branch $BRANCH" + exit 1 +fi +echo "Fetched SHA: $REF" + +if [ ! -f "$TARGET" ]; then + echo "Error: Target file $TARGET does not exist" + exit 1 +fi + +# Save the substitution results to a temporary file first +TEMP_FILE=$(mktemp) + +# Update the "system-tests.yml@" reference +echo "Updating 'system-tests.yml@' reference..." +perl -pe "s/$PATTERN_1/\${1}$REF\${3}/g" "$TARGET" > "$TEMP_FILE" +cp "$TEMP_FILE" "$TARGET" + +# Update the "ref:" reference +echo "Updating 'ref:' reference..." +perl -pe "s/$PATTERN_2/\${1}$REF\${3}/g" "$TARGET" > "$TEMP_FILE" +cp "$TEMP_FILE" "$TARGET" + +# Clean up temporary file +rm -f "$TEMP_FILE" + +echo "Done updating system-tests references to $REF"