From b00d46d8697e1cf93c6f83054c83c3dde9ce5065 Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Mon, 16 Dec 2024 10:01:43 -0300 Subject: [PATCH 1/2] Add script that checks if any file that changed is a windows-related file Signed-off-by: Arthur Silva Sens --- .github/workflows/e2e-tests-windows.yml | 11 ++++++ .../scripts/is_changed_file_windows.sh | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 .github/workflows/scripts/is_changed_file_windows.sh diff --git a/.github/workflows/e2e-tests-windows.yml b/.github/workflows/e2e-tests-windows.yml index 0745599b555f..0cfee2e4788c 100644 --- a/.github/workflows/e2e-tests-windows.yml +++ b/.github/workflows/e2e-tests-windows.yml @@ -19,6 +19,17 @@ env: SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2 jobs: + get-changed-files: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Get changed files + id: get_changed_files + run: echo "::set-output name=files::$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})" + - name: Print changed files + run: echo "${{ steps.get_changed_files.outputs.files }}" + collector-build: runs-on: windows-latest if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Windows') || github.event_name == 'push' || github.event_name == 'merge_group') }} diff --git a/.github/workflows/scripts/is_changed_file_windows.sh b/.github/workflows/scripts/is_changed_file_windows.sh new file mode 100755 index 000000000000..e1f7276e79ad --- /dev/null +++ b/.github/workflows/scripts/is_changed_file_windows.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# +# verifies if any changed file is related to windows architecture. +# this script is used to determine if e2e tests should be run on windows. +# +# It's intended to be used in a GitHub Actions workflow: +# bash .github/workflows/scripts/is_changed_file_windows.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }} + + +# Get changed files +base_sha=$1 +head_sha=$2 +changed_files=$(git diff --name-only $base_sha $head_sha) + +# Find windows related files +windows_files=$(find * -regex ".*windows.*.go") + + +# Loop over changed files and check if they exist in windows_files +found_windows_file=false +for file in $changed_files; do + for windows_file in $windows_files; do + if [[ $file == "$windows_file" ]]; then + found_windows_file=true + break + fi + done +done + +echo "$found_windows_file" \ No newline at end of file From e49d5b615c332bd98baf234a600f494b06c1d82e Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Mon, 16 Dec 2024 11:05:15 -0300 Subject: [PATCH 2/2] Trigger windows e2e-tests if windows file changes Signed-off-by: Arthur Silva Sens --- .github/workflows/e2e-tests-windows.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/e2e-tests-windows.yml b/.github/workflows/e2e-tests-windows.yml index 0cfee2e4788c..bcfb4f38d865 100644 --- a/.github/workflows/e2e-tests-windows.yml +++ b/.github/workflows/e2e-tests-windows.yml @@ -19,20 +19,22 @@ env: SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2 jobs: - get-changed-files: + windows-file-changed: runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' }} steps: - name: Checkout uses: actions/checkout@v4 - - name: Get changed files - id: get_changed_files - run: echo "::set-output name=files::$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})" - - name: Print changed files - run: echo "${{ steps.get_changed_files.outputs.files }}" + with: + fetch-depth: 0 + - name: Did windows files changed + run: echo "changed=$(./.github/workflows/scripts/is_changed_file_windows.sh )" >> "$GITHUB_OUTPUT" + - run: echo $(./.github/workflows/scripts/is_changed_file_windows.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }} ) collector-build: runs-on: windows-latest - if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Windows') || github.event_name == 'push' || github.event_name == 'merge_group') }} + needs: [windows-file-changed] + if: ${{ github.actor != 'dependabot[bot]' && ((contains(github.event.pull_request.labels.*.name, 'Run Windows') || github.event_name == 'push' || github.event_name == 'merge_group') || needs.windows-file-changed.outputs.changed == 'true') }} steps: - name: Checkout uses: actions/checkout@v4