From 2b20896a93b42e084d619df3ae4c213730ab081e Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:01:07 -0600 Subject: [PATCH 1/9] try this --- .github/workflows/test-pull-request.yml | 10 +++++++--- build/secrets/.secrets.baseline | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 4c4226d9530..1961cdd9297 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -6,9 +6,13 @@ on: branches: - main - 'prerelease/**' + pull_request_target: + types: + - edited # Run only for PR body edits jobs: pr-tags: + if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' && github.event.action == 'edited' runs-on: ubuntu-latest outputs: tags: ${{ steps.pr-tags.outputs.tags }} @@ -19,6 +23,7 @@ jobs: run: bash scripts/pr-tags-parse.sh "${{ github.event_path }}" e2e-electron: + if: github.event_name == 'pull_request' name: e2e uses: ./.github/workflows/test-e2e-linux.yml needs: pr-tags @@ -29,14 +34,13 @@ jobs: secrets: inherit unit-tests: + if: github.event_name == 'pull_request' name: test uses: ./.github/workflows/test-unit.yml secrets: inherit integration-tests: + if: github.event_name == 'pull_request' name: test uses: ./.github/workflows/test-integration.yml secrets: inherit - - - diff --git a/build/secrets/.secrets.baseline b/build/secrets/.secrets.baseline index 79e1b3af552..a5ee45d8971 100644 --- a/build/secrets/.secrets.baseline +++ b/build/secrets/.secrets.baseline @@ -157,7 +157,7 @@ "filename": ".github/workflows/test-pull-request.yml", "hashed_secret": "3e26d6750975d678acb8fa35a0f69237881576b0", "is_verified": false, - "line_number": 29 + "line_number": 34 } ], "build/azure-pipelines/alpine/product-build-alpine.yml": [ @@ -1933,5 +1933,5 @@ } ] }, - "generated_at": "2024-12-10T16:17:08Z" + "generated_at": "2024-12-11T22:01:09Z" } From bef0ebd3612da546cd57fa2a091e2d8ad879ce39 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:15:19 -0600 Subject: [PATCH 2/9] new pr workflow --- .github/workflows/parse-pr-tags.yml | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/parse-pr-tags.yml diff --git a/.github/workflows/parse-pr-tags.yml b/.github/workflows/parse-pr-tags.yml new file mode 100644 index 00000000000..ec44c987240 --- /dev/null +++ b/.github/workflows/parse-pr-tags.yml @@ -0,0 +1,49 @@ +name: "PR Tags Parsing" + +on: + pull_request: + types: + - opened + - synchronize + - edited + +jobs: + update-pr-tags-comment: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Parse Tags from PR Body + id: parse-tags + run: | + TAGS=$(bash scripts/pr-tags-parse.sh "${{ github.event_path }}") + echo "Parsed Tags: $TAGS" + echo "tags=$TAGS" >> $GITHUB_ENV + + - name: Update PR Comment with Tags + run: | + # Define the comment marker + COMMENT_MARKER="" + + # Fetch existing comments on the PR + COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments) + + # Check if a comment with the marker already exists + COMMENT_ID=$(echo "$COMMENTS" | jq -r ".[] | select(.body | contains(\"$COMMENT_MARKER\")) | .id") + + # Build the new comment body + NEW_COMMENT="$COMMENT_MARKER\n**E2E Test Tags:** ${{ env.tags }}" + + if [ -n "$COMMENT_ID" ]; then + # Update the existing comment + echo "Updating existing comment (ID: $COMMENT_ID)..." + gh api repos/${{ github.repository }}/issues/comments/$COMMENT_ID \ + -X PATCH \ + -F body="$NEW_COMMENT" + else + # Create a new comment + echo "Creating a new comment..." + gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \ + -F body="$NEW_COMMENT" + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b4ca2551186e1f3c29795e92b9ffbf5303981ace Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:18:05 -0600 Subject: [PATCH 3/9] remove echos --- scripts/pr-tags-parse.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/pr-tags-parse.sh b/scripts/pr-tags-parse.sh index 574f78bf30e..5917757ac50 100644 --- a/scripts/pr-tags-parse.sh +++ b/scripts/pr-tags-parse.sh @@ -8,14 +8,14 @@ GITHUB_EVENT_PATH="$1" # Extract the PR body from the event JSON -echo "Extracting PR body..." +# echo "Extracting PR body..." PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | tr '\n' ' ' | sed 's/"/\\"/g') -echo "Parsing tags from PR body..." +# echo "Parsing tags from PR body..." # Check if @:all is present in the PR body if echo "$PR_BODY" | grep -q "@:all"; then - echo "Found @:all tag in PR body. Setting tags to run all tests." + # echo "Found @:all tag in PR body. Setting tags to run all tests." TAGS="" # Set to an empty string to indicate all tests should run else # Parse tags starting with '@:' and convert to '@' @@ -32,11 +32,12 @@ else fi # Output the tags -echo "Extracted Tags: $TAGS" +# echo "Extracted Tags: $TAGS" # Save tags to GITHUB_OUTPUT for use in GitHub Actions if [[ -n "$GITHUB_OUTPUT" ]]; then - echo "tags=$TAGS" >> "$GITHUB_OUTPUT" + # echo "tags=$TAGS" >> "$GITHUB_OUTPUT" + echo "$TAGS" # Only output tags to stdout else echo "Warning: GITHUB_OUTPUT is not set. Tags will not be available to the workflow." fi From 23f72463c7e6ca715b07b3bb784296ccbd5a1a26 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:21:19 -0600 Subject: [PATCH 4/9] comment tweaks --- .github/workflows/parse-pr-tags.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/parse-pr-tags.yml b/.github/workflows/parse-pr-tags.yml index ec44c987240..10708a52458 100644 --- a/.github/workflows/parse-pr-tags.yml +++ b/.github/workflows/parse-pr-tags.yml @@ -30,8 +30,9 @@ jobs: # Check if a comment with the marker already exists COMMENT_ID=$(echo "$COMMENTS" | jq -r ".[] | select(.body | contains(\"$COMMENT_MARKER\")) | .id") - # Build the new comment body - NEW_COMMENT="$COMMENT_MARKER\n**E2E Test Tags:** ${{ env.tags }}" + # Build the new comment body with proper newlines and backticks + FORMATTED_TAGS=$(echo "${{ env.tags }}" | sed 's/,/`, `/g') # Format tags for readability + NEW_COMMENT="${COMMENT_MARKER}\n\n**E2E Test Tags:**\n\`\`${FORMATTED_TAGS}\`\`" if [ -n "$COMMENT_ID" ]; then # Update the existing comment From 9e6e365c507b24a8290116c60e1f227e56e706d1 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:23:31 -0600 Subject: [PATCH 5/9] try this --- .github/workflows/parse-pr-tags.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/parse-pr-tags.yml b/.github/workflows/parse-pr-tags.yml index 10708a52458..02a1031a550 100644 --- a/.github/workflows/parse-pr-tags.yml +++ b/.github/workflows/parse-pr-tags.yml @@ -30,9 +30,11 @@ jobs: # Check if a comment with the marker already exists COMMENT_ID=$(echo "$COMMENTS" | jq -r ".[] | select(.body | contains(\"$COMMENT_MARKER\")) | .id") - # Build the new comment body with proper newlines and backticks - FORMATTED_TAGS=$(echo "${{ env.tags }}" | sed 's/,/`, `/g') # Format tags for readability - NEW_COMMENT="${COMMENT_MARKER}\n\n**E2E Test Tags:**\n\`\`${FORMATTED_TAGS}\`\`" + # Format the tags with individual backticks + FORMATTED_TAGS=$(echo "${{ env.tags }}" | sed 's/,/` `/' | sed 's/^/`/' | sed 's/$/`/') + + # Build the new comment body with proper newlines + NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\n**E2E Test Tags:**\n%s" "$FORMATTED_TAGS") if [ -n "$COMMENT_ID" ]; then # Update the existing comment From 8037d958324de1423ec492f311223f0481bb2fb3 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:25:18 -0600 Subject: [PATCH 6/9] edit title --- .github/workflows/parse-pr-tags.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/parse-pr-tags.yml b/.github/workflows/parse-pr-tags.yml index 02a1031a550..f653d491990 100644 --- a/.github/workflows/parse-pr-tags.yml +++ b/.github/workflows/parse-pr-tags.yml @@ -34,7 +34,7 @@ jobs: FORMATTED_TAGS=$(echo "${{ env.tags }}" | sed 's/,/` `/' | sed 's/^/`/' | sed 's/$/`/') # Build the new comment body with proper newlines - NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\n**E2E Test Tags:**\n%s" "$FORMATTED_TAGS") + NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\nRunning E2E tests tagged with:\n%s" "$FORMATTED_TAGS") if [ -n "$COMMENT_ID" ]; then # Update the existing comment From 0d38a5d4d2a433fc40fce49ffc9191b38a1cacfe Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:45:06 -0600 Subject: [PATCH 7/9] tags from comm --- .github/workflows/test-pull-request.yml | 39 +++++++++++++++++++++---- build/secrets/.secrets.baseline | 4 +-- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 1961cdd9297..0f8adb1f359 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -11,16 +11,43 @@ on: - edited # Run only for PR body edits jobs: + # pr-tags: + # if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' && github.event.action == 'edited' + # runs-on: ubuntu-latest + # outputs: + # tags: ${{ steps.pr-tags.outputs.tags }} + # steps: + # - uses: actions/checkout@v4 + # - name: Parse Tags from PR Body + # id: pr-tags + # run: bash scripts/pr-tags-parse.sh "${{ github.event_path }}" pr-tags: - if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' && github.event.action == 'edited' runs-on: ubuntu-latest - outputs: - tags: ${{ steps.pr-tags.outputs.tags }} steps: - uses: actions/checkout@v4 - - name: Parse Tags from PR Body - id: pr-tags - run: bash scripts/pr-tags-parse.sh "${{ github.event_path }}" + + - name: Fetch Tags from PR Comment + id: fetch-tags + run: | + # Define the comment marker + COMMENT_MARKER="" + + # Fetch all comments for the PR + COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments) + + # Find the comment containing the marker + COMMENT_BODY=$(echo "$COMMENTS" | jq -r ".[] | select(.body | contains(\"$COMMENT_MARKER\")) | .body") + + if [ -z "$COMMENT_BODY" ]; then + echo "No PR Tags comment found. Exiting." + exit 1 + fi + + # Extract the tags from the comment body + TAGS=$(echo "$COMMENT_BODY" | grep -oP "(?<=Running E2E tests tagged with:\n).+" | tr -d '`') + + echo "Extracted Tags: $TAGS" + echo "tags=$TAGS" >> $GITHUB_ENV e2e-electron: if: github.event_name == 'pull_request' diff --git a/build/secrets/.secrets.baseline b/build/secrets/.secrets.baseline index a5ee45d8971..e40cce02922 100644 --- a/build/secrets/.secrets.baseline +++ b/build/secrets/.secrets.baseline @@ -157,7 +157,7 @@ "filename": ".github/workflows/test-pull-request.yml", "hashed_secret": "3e26d6750975d678acb8fa35a0f69237881576b0", "is_verified": false, - "line_number": 34 + "line_number": 61 } ], "build/azure-pipelines/alpine/product-build-alpine.yml": [ @@ -1933,5 +1933,5 @@ } ] }, - "generated_at": "2024-12-11T22:01:09Z" + "generated_at": "2024-12-11T22:45:09Z" } From a5d161cd768e6d43d376e3178c903691acbff1f3 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:48:40 -0600 Subject: [PATCH 8/9] token --- .github/workflows/test-pull-request.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 0f8adb1f359..bf4fa3aca97 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -27,7 +27,8 @@ jobs: - uses: actions/checkout@v4 - name: Fetch Tags from PR Comment - id: fetch-tags + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Define the comment marker COMMENT_MARKER="" From 888fc8765308a08e78eb61a0bcf75c31318c441b Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 16:50:45 -0600 Subject: [PATCH 9/9] tweak --- .github/workflows/test-pull-request.yml | 7 ++++++- build/secrets/.secrets.baseline | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index bf4fa3aca97..f4ab7f33634 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -45,7 +45,12 @@ jobs: fi # Extract the tags from the comment body - TAGS=$(echo "$COMMENT_BODY" | grep -oP "(?<=Running E2E tests tagged with:\n).+" | tr -d '`') + TAGS=$(echo "$COMMENT_BODY" | awk '/Running E2E tests tagged with:/{flag=1; next} /