diff --git a/.github/scripts/update_reference.sh b/.github/scripts/update_reference.sh new file mode 100755 index 00000000000..4851043cd21 --- /dev/null +++ b/.github/scripts/update_reference.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# This script updates the reference in a YAML file. + +# Check if required environment variables are set +if [ -z "$TARGET" ]; then + echo "Error: TARGET environment variable is not set" + exit 1 +fi + +if [ -z "$REF" ]; then + echo "Error: REF environment variable is not set" + exit 1 +fi + +if [ -z "$PATTERN" ]; then + echo "Error: PATTERN environment variable is not set" + exit 1 +fi + +echo "Target: $TARGET" +echo "Ref: $REF" + +# Remove leading and trailing forward slashes from pattern +CLEAN_PATTERN=$(echo "$PATTERN" | sed 's/^\///;s/\/$//') +echo "Pattern: $CLEAN_PATTERN" + +# Create a temporary file +TEMP_FILE=$(mktemp) + +# Read the file and perform the substitution +if [ -f "$TARGET" ]; then + # Perform the substitution and save to temporary file + # We use perl here because sed's regex support varies across platforms + perl -pe "s/$CLEAN_PATTERN/\${1}$REF\${3}/g" "$TARGET" > "$TEMP_FILE" + + # Compare files to check if any changes were made + if cmp -s "$TARGET" "$TEMP_FILE"; then + echo "No references found in $TARGET" + else + # Copy the temp file back to the target + cp "$TEMP_FILE" "$TARGET" + echo "✓ Updated references in $TARGET" + fi +else + echo "Error: Target file $TARGET does not exist" + rm -f "$TEMP_FILE" + exit 1 +fi + +# Clean up temporary file +rm -f "$TEMP_FILE" \ No newline at end of file diff --git a/.github/workflows/run-system-tests.yaml b/.github/workflows/run-system-tests.yaml index 2a2319e4a7e..0e05e0dd7bc 100644 --- a/.github/workflows/run-system-tests.yaml +++ b/.github/workflows/run-system-tests.yaml @@ -50,13 +50,14 @@ jobs: main: needs: - build - uses: DataDog/system-tests/.github/workflows/system-tests.yml@main + uses: DataDog/system-tests/.github/workflows/system-tests.yml@84c7354433427ffb4d1a48ad60166627fac8cee3 # Automated: This reference is automatically updated. secrets: inherit permissions: contents: read packages: write with: library: java + ref: 84c7354433427ffb4d1a48ad60166627fac8cee3 # Automated: This reference is automatically updated. binaries_artifact: binaries desired_execution_time: 900 # 15 minutes scenarios_groups: tracer-release diff --git a/.github/workflows/update-system-tests.yml b/.github/workflows/update-system-tests.yml new file mode 100644 index 00000000000..b2314a5bf59 --- /dev/null +++ b/.github/workflows/update-system-tests.yml @@ -0,0 +1,74 @@ +name: Update System Tests + +on: # yamllint disable-line rule:truthy + schedule: + - cron: '0 0 * * 0' # Every Sunday at midnight + workflow_dispatch: + inputs: + ref: + description: Reference to be updated (commit hash, branch, or tag) + required: false + type: string + dry-run: + description: Skip PR creation and only show changes + required: false + type: boolean + default: false + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +# Default permissions for all jobs +permissions: {} + +jobs: + update-system-tests: + name: "Update System Tests" + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: true + + - name: Checkout System Test + id: system-test-ref + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: "DataDog/system-tests" + path: system-tests + persist-credentials: false + ref: ${{ github.event.inputs.ref || '' }} + + - run: .github/scripts/update_reference.sh + env: + TARGET: ".github/workflows/run-system-tests.yaml" + PATTERN: '(\s*system-tests.yml@)(\S+)(\s+# Automated:.*)' + REF: ${{ steps.system-test-ref.outputs.commit }} + + - run: .github/scripts/update_reference.sh + env: + TARGET: ".github/workflows/run-system-tests.yaml" + PATTERN: '(\s*ref: )(\S+)(\s+# Automated:.*)' + REF: ${{ steps.system-test-ref.outputs.commit }} + + + - run: git diff --color=always + + - name: Create Pull Request + if: ${{ github.event.inputs.dry-run != true }} + id: cpr + uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 + with: + branch: auto-generate/update-system-tests + title: '[🤖] Update System Tests' + base: master + commit-message: "[🤖] Update System Tests: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + sign-commits: true + delete-branch: true + add-paths: | + .github/ + body: | + _This is an auto-generated PR from [here](${{ github.server_url }}/${{ github.repository }}/blob/master/.github/workflows/update-system-tests.yml)_ + The PR updates the system tests (Updated to commit: ${{ steps.system-test-ref.outputs.commit }}) + Please review the changes and merge when ready