From 7f25acd00119669f0412f4b91976f7f84dc02abb Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 18:09:22 -0600 Subject: [PATCH 01/22] action for pr body --- .github/workflows/test-pull-request.yml | 38 +++++++++++++++++++++++++ build/secrets/.secrets.baseline | 4 +-- scripts/pr-tags-parse.sh | 6 ++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 4c4226d9530..0728596d2c8 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -14,9 +14,47 @@ jobs: tags: ${{ steps.pr-tags.outputs.tags }} steps: - uses: actions/checkout@v4 + + - uses: 8BitJonny/gh-get-current-pr@3.0.0 + id: PR + + - run: echo "PR ${prNumber} ${prTitle} at ${prUrl} is ${prJSON}" + if: steps.PR.outputs.pr_found == 'true' + env: + # JSON object with the full PR object + # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. + prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} + # Direct access to common PR properties + prNumber: ${{ steps.PR.outputs.number }} + prUrl: ${{ steps.PR.outputs.pr_url }} + prTitle: ${{ steps.PR.outputs.pr_title }} + prBody: ${{ steps.PR.outputs.pr_body }} + prCreatedAt: ${{ steps.PR.outputs.pr_created_at }} + prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} + prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} + prLabel: ${{ steps.PR.outputs.pr_labels }} + + - run: echo "${prBody}" + if: steps.PR.outputs.pr_found == 'true' + env: + # JSON object with the full PR object + # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. + prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} + # Direct access to common PR properties + prNumber: ${{ steps.PR.outputs.number }} + prUrl: ${{ steps.PR.outputs.pr_url }} + prTitle: ${{ steps.PR.outputs.pr_title }} + prBody: ${{ steps.PR.outputs.pr_body }} + prCreatedAt: ${{ steps.PR.outputs.pr_created_at }} + prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} + prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} + prLabel: ${{ steps.PR.outputs.pr_labels }} + - name: Parse Tags from PR Body id: pr-tags run: bash scripts/pr-tags-parse.sh "${{ github.event_path }}" + env: + prBody: ${{ steps.PR.outputs.pr_body }} e2e-electron: name: e2e diff --git a/build/secrets/.secrets.baseline b/build/secrets/.secrets.baseline index 79e1b3af552..c09630069f8 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": 67 } ], "build/azure-pipelines/alpine/product-build-alpine.yml": [ @@ -1933,5 +1933,5 @@ } ] }, - "generated_at": "2024-12-10T16:17:08Z" + "generated_at": "2024-12-12T00:09:24Z" } diff --git a/scripts/pr-tags-parse.sh b/scripts/pr-tags-parse.sh index 574f78bf30e..10ee7a8b7a0 100644 --- a/scripts/pr-tags-parse.sh +++ b/scripts/pr-tags-parse.sh @@ -5,11 +5,13 @@ # bash parse-pr-tags.sh "/path/to/event.json" # Input: Path to the GitHub event JSON file -GITHUB_EVENT_PATH="$1" +# GITHUB_EVENT_PATH="$1" +PULL_REQUEST_BODY="$1" # Extract the PR body from the event JSON echo "Extracting PR body..." -PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | tr '\n' ' ' | sed 's/"/\\"/g') +# PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | tr '\n' ' ' | sed 's/"/\\"/g') +PR_BODY=$(echo "$PULL_REQUEST_BODY" | tr '\n' ' ' | sed 's/"/\\"/g') echo "Parsing tags from PR body..." From 59632ecbade58f49203e55288a7825384abbee8c Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 18:11:26 -0600 Subject: [PATCH 02/22] token --- .github/workflows/test-pull-request.yml | 7 +++++++ build/secrets/.secrets.baseline | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 0728596d2c8..d17ac6e1434 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -17,12 +17,17 @@ jobs: - uses: 8BitJonny/gh-get-current-pr@3.0.0 id: PR + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + sha: ${{ github.event.pull_request.head.sha }} + filterOutClosed: true - run: echo "PR ${prNumber} ${prTitle} at ${prUrl} is ${prJSON}" if: steps.PR.outputs.pr_found == 'true' env: # JSON object with the full PR object # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. + github-token: ${{ secrets.GITHUB_TOKEN }} prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} # Direct access to common PR properties prNumber: ${{ steps.PR.outputs.number }} @@ -49,12 +54,14 @@ jobs: prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} prLabel: ${{ steps.PR.outputs.pr_labels }} + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Parse Tags from PR Body id: pr-tags run: bash scripts/pr-tags-parse.sh "${{ github.event_path }}" env: prBody: ${{ steps.PR.outputs.pr_body }} + github-token: ${{ secrets.GITHUB_TOKEN }} e2e-electron: name: e2e diff --git a/build/secrets/.secrets.baseline b/build/secrets/.secrets.baseline index c09630069f8..e4c15bf1f35 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": 67 + "line_number": 72 } ], "build/azure-pipelines/alpine/product-build-alpine.yml": [ @@ -1933,5 +1933,5 @@ } ] }, - "generated_at": "2024-12-12T00:09:24Z" + "generated_at": "2024-12-12T00:20:06Z" } From 94e9f6641918b4819b1f320334e470c788356d6d Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 18:32:33 -0600 Subject: [PATCH 03/22] use body --- .github/workflows/test-pull-request.yml | 68 ++++++++++++------------- build/secrets/.secrets.baseline | 4 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index d17ac6e1434..40fd21ad92f 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -22,45 +22,45 @@ jobs: sha: ${{ github.event.pull_request.head.sha }} filterOutClosed: true - - run: echo "PR ${prNumber} ${prTitle} at ${prUrl} is ${prJSON}" - if: steps.PR.outputs.pr_found == 'true' - env: - # JSON object with the full PR object - # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. - github-token: ${{ secrets.GITHUB_TOKEN }} - prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} - # Direct access to common PR properties - prNumber: ${{ steps.PR.outputs.number }} - prUrl: ${{ steps.PR.outputs.pr_url }} - prTitle: ${{ steps.PR.outputs.pr_title }} - prBody: ${{ steps.PR.outputs.pr_body }} - prCreatedAt: ${{ steps.PR.outputs.pr_created_at }} - prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} - prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} - prLabel: ${{ steps.PR.outputs.pr_labels }} + # - run: echo "PR ${prNumber} ${prTitle} at ${prUrl} is ${prJSON}" + # if: steps.PR.outputs.pr_found == 'true' + # env: + # # JSON object with the full PR object + # # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. + # github-token: ${{ secrets.GITHUB_TOKEN }} + # prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} + # # Direct access to common PR properties + # prNumber: ${{ steps.PR.outputs.number }} + # prUrl: ${{ steps.PR.outputs.pr_url }} + # prTitle: ${{ steps.PR.outputs.pr_title }} + # prBody: ${{ steps.PR.outputs.pr_body }} + # prCreatedAt: ${{ steps.PR.outputs.pr_created_at }} + # prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} + # prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} + # prLabel: ${{ steps.PR.outputs.pr_labels }} - - run: echo "${prBody}" - if: steps.PR.outputs.pr_found == 'true' - env: - # JSON object with the full PR object - # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. - prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} - # Direct access to common PR properties - prNumber: ${{ steps.PR.outputs.number }} - prUrl: ${{ steps.PR.outputs.pr_url }} - prTitle: ${{ steps.PR.outputs.pr_title }} - prBody: ${{ steps.PR.outputs.pr_body }} - prCreatedAt: ${{ steps.PR.outputs.pr_created_at }} - prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} - prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} - prLabel: ${{ steps.PR.outputs.pr_labels }} - github-token: ${{ secrets.GITHUB_TOKEN }} + # - run: echo "${prBody}" + # if: steps.PR.outputs.pr_found == 'true' + # env: + # # JSON object with the full PR object + # # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. + # prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} + # # Direct access to common PR properties + # prNumber: ${{ steps.PR.outputs.number }} + # prUrl: ${{ steps.PR.outputs.pr_url }} + # prTitle: ${{ steps.PR.outputs.pr_title }} + # prBody: ${{ steps.PR.outputs.pr_body }} + # prCreatedAt: ${{ steps.PR.outputs.pr_created_at }} + # prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} + # prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} + # prLabel: ${{ steps.PR.outputs.pr_labels }} + # github-token: ${{ secrets.GITHUB_TOKEN }} - name: Parse Tags from PR Body id: pr-tags - run: bash scripts/pr-tags-parse.sh "${{ github.event_path }}" + run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" env: - prBody: ${{ steps.PR.outputs.pr_body }} + PR_BODY: ${{ steps.PR.outputs.pr_body }} github-token: ${{ secrets.GITHUB_TOKEN }} e2e-electron: diff --git a/build/secrets/.secrets.baseline b/build/secrets/.secrets.baseline index e4c15bf1f35..2f9aab3a977 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": 72 + "line_number": 74 } ], "build/azure-pipelines/alpine/product-build-alpine.yml": [ @@ -1933,5 +1933,5 @@ } ] }, - "generated_at": "2024-12-12T00:20:06Z" + "generated_at": "2024-12-12T00:22:54Z" } From 5320c54b80f62177a39607fdfb8ce48ad23b683c Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 18:35:57 -0600 Subject: [PATCH 04/22] cleanup --- .github/workflows/test-pull-request.yml | 36 +------------------------ build/secrets/.secrets.baseline | 4 +-- scripts/pr-tags-parse.sh | 2 -- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 40fd21ad92f..21611c875f2 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -22,46 +22,12 @@ jobs: sha: ${{ github.event.pull_request.head.sha }} filterOutClosed: true - # - run: echo "PR ${prNumber} ${prTitle} at ${prUrl} is ${prJSON}" - # if: steps.PR.outputs.pr_found == 'true' - # env: - # # JSON object with the full PR object - # # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. - # github-token: ${{ secrets.GITHUB_TOKEN }} - # prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} - # # Direct access to common PR properties - # prNumber: ${{ steps.PR.outputs.number }} - # prUrl: ${{ steps.PR.outputs.pr_url }} - # prTitle: ${{ steps.PR.outputs.pr_title }} - # prBody: ${{ steps.PR.outputs.pr_body }} - # prCreatedAt: ${{ steps.PR.outputs.pr_created_at }} - # prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} - # prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} - # prLabel: ${{ steps.PR.outputs.pr_labels }} - - # - run: echo "${prBody}" - # if: steps.PR.outputs.pr_found == 'true' - # env: - # # JSON object with the full PR object - # # toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print. - # prJSON: ${{ toJSON(fromJSON(steps.PR.outputs.pr)) }} - # # Direct access to common PR properties - # prNumber: ${{ steps.PR.outputs.number }} - # prUrl: ${{ steps.PR.outputs.pr_url }} - # prTitle: ${{ steps.PR.outputs.pr_title }} - # prBody: ${{ steps.PR.outputs.pr_body }} - # prCreatedAt: ${{ steps.PR.outputs.pr_created_at }} - # prMergedAt: ${{ steps.PR.outputs.pr_merged_at }} - # prClosedAt: ${{ steps.PR.outputs.pr_closed_at }} - # prLabel: ${{ steps.PR.outputs.pr_labels }} - # github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Parse Tags from PR Body id: pr-tags run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" env: PR_BODY: ${{ steps.PR.outputs.pr_body }} - github-token: ${{ secrets.GITHUB_TOKEN }} + # github-token: ${{ secrets.GITHUB_TOKEN }} e2e-electron: name: e2e diff --git a/build/secrets/.secrets.baseline b/build/secrets/.secrets.baseline index 2f9aab3a977..c5f7f876314 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": 74 + "line_number": 40 } ], "build/azure-pipelines/alpine/product-build-alpine.yml": [ @@ -1933,5 +1933,5 @@ } ] }, - "generated_at": "2024-12-12T00:22:54Z" + "generated_at": "2024-12-12T00:36:00Z" } diff --git a/scripts/pr-tags-parse.sh b/scripts/pr-tags-parse.sh index 10ee7a8b7a0..0c2a4244123 100644 --- a/scripts/pr-tags-parse.sh +++ b/scripts/pr-tags-parse.sh @@ -5,12 +5,10 @@ # bash parse-pr-tags.sh "/path/to/event.json" # Input: Path to the GitHub event JSON file -# GITHUB_EVENT_PATH="$1" PULL_REQUEST_BODY="$1" # Extract the PR body from the event JSON echo "Extracting PR body..." -# PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | tr '\n' ' ' | sed 's/"/\\"/g') PR_BODY=$(echo "$PULL_REQUEST_BODY" | tr '\n' ' ' | sed 's/"/\\"/g') echo "Parsing tags from PR body..." From 778676c907455f4219a04318221ccf4bb6bfdaf4 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 18:45:43 -0600 Subject: [PATCH 05/22] remove comment --- .github/workflows/test-pull-request.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 21611c875f2..505277f306a 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -27,7 +27,6 @@ jobs: run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" env: PR_BODY: ${{ steps.PR.outputs.pr_body }} - # github-token: ${{ secrets.GITHUB_TOKEN }} e2e-electron: name: e2e From 1fad0999387c3b218d27ec27a0360d7a524e1c07 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Wed, 11 Dec 2024 18:45:54 -0600 Subject: [PATCH 06/22] secrets --- build/secrets/.secrets.baseline | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/secrets/.secrets.baseline b/build/secrets/.secrets.baseline index c5f7f876314..03d175d25ef 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": 40 + "line_number": 39 } ], "build/azure-pipelines/alpine/product-build-alpine.yml": [ @@ -1933,5 +1933,5 @@ } ] }, - "generated_at": "2024-12-12T00:36:00Z" + "generated_at": "2024-12-12T00:45:45Z" } From 2d0c7001f7fb638d4ee2e55f23f3ffde58de2edc Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 05:25:00 -0600 Subject: [PATCH 07/22] add comment --- .github/workflows/e2e-tags-comment.yml | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/e2e-tags-comment.yml diff --git a/.github/workflows/e2e-tags-comment.yml b/.github/workflows/e2e-tags-comment.yml new file mode 100644 index 00000000000..86ce24d3c9f --- /dev/null +++ b/.github/workflows/e2e-tags-comment.yml @@ -0,0 +1,57 @@ +on: + pull_request: + types: + - opened + - synchronize + - edited + +jobs: + update-pr-tags-comment: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: 8BitJonny/gh-get-current-pr@3.0.0 + id: PR + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + sha: ${{ github.event.pull_request.head.sha }} + filterOutClosed: true + + - name: Parse Tags from PR Body + id: pr-tags + run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" + env: + PR_BODY: ${{ steps.PR.outputs.pr_body }} + + - 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") + + # 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\nE2E Tests πŸš€\nThis PR will run tests tagged with:\n%s" "$FORMATTED_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 9ee17426a58612ed1387bf9553569fce67ad6a9f Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 05:29:03 -0600 Subject: [PATCH 08/22] echo tags --- .../{e2e-tags-comment.yml => comment-e2e-tags.yml} | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) rename .github/workflows/{e2e-tags-comment.yml => comment-e2e-tags.yml} (89%) diff --git a/.github/workflows/e2e-tags-comment.yml b/.github/workflows/comment-e2e-tags.yml similarity index 89% rename from .github/workflows/e2e-tags-comment.yml rename to .github/workflows/comment-e2e-tags.yml index 86ce24d3c9f..c0da80f9a55 100644 --- a/.github/workflows/e2e-tags-comment.yml +++ b/.github/workflows/comment-e2e-tags.yml @@ -1,3 +1,5 @@ +name: Comment Tags + on: pull_request: types: @@ -26,6 +28,9 @@ jobs: - name: Update PR Comment with Tags run: | + # Echo tags + echo "tags=${{ needs.pr-tags.outputs.tags }}" + # Define the comment marker COMMENT_MARKER="" @@ -39,7 +44,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\nE2E Tests πŸš€\nThis PR will run tests tagged with:\n%s" "$FORMATTED_TAGS") + NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\n**E2E Tests** πŸš€\nThis PR will run tests tagged with:\n%s" "$FORMATTED_TAGS") if [ -n "$COMMENT_ID" ]; then # Update the existing comment From 11738624899e53c06b7e7e551ad296a2e7e2a550 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 05:40:01 -0600 Subject: [PATCH 09/22] add script --- .github/workflows/comment-e2e-tags.yml | 62 ----------------------- .github/workflows/pr-e2e-comment.yml | 70 ++++++++++++++++++++++++++ scripts/pr-e2e-comment.sh | 59 ++++++++++++++++++++++ 3 files changed, 129 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/comment-e2e-tags.yml create mode 100644 .github/workflows/pr-e2e-comment.yml create mode 100644 scripts/pr-e2e-comment.sh diff --git a/.github/workflows/comment-e2e-tags.yml b/.github/workflows/comment-e2e-tags.yml deleted file mode 100644 index c0da80f9a55..00000000000 --- a/.github/workflows/comment-e2e-tags.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Comment Tags - -on: - pull_request: - types: - - opened - - synchronize - - edited - -jobs: - update-pr-tags-comment: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: 8BitJonny/gh-get-current-pr@3.0.0 - id: PR - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - sha: ${{ github.event.pull_request.head.sha }} - filterOutClosed: true - - - name: Parse Tags from PR Body - id: pr-tags - run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" - env: - PR_BODY: ${{ steps.PR.outputs.pr_body }} - - - name: Update PR Comment with Tags - run: | - # Echo tags - echo "tags=${{ needs.pr-tags.outputs.tags }}" - - # 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") - - # 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 Tests** πŸš€\nThis PR will run tests tagged with:\n%s" "$FORMATTED_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 }} diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml new file mode 100644 index 00000000000..5fb9cfa48ee --- /dev/null +++ b/.github/workflows/pr-e2e-comment.yml @@ -0,0 +1,70 @@ +name: Comment Tags + +on: + pull_request: + types: + - opened + - synchronize + - edited + +jobs: + update-pr-tags-comment: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: 8BitJonny/gh-get-current-pr@3.0.0 + id: PR + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + sha: ${{ github.event.pull_request.head.sha }} + filterOutClosed: true + + - name: Parse Tags from PR Body + id: pr-tags + run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" + env: + PR_BODY: ${{ steps.PR.outputs.pr_body }} + + - name: Update PR Comment with Tags + run: | + ./pr-e2e-comment.sh "" "${{ needs.pr-tags.outputs.tags }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} + + # - name: Update PR Comment with Tags + # run: | + # # Echo tags + # echo "tags=${{ needs.pr-tags.outputs.tags }}" + + # # 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") + + # # 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 Tests** πŸš€\nThis PR will run tests tagged with:%s" "$FORMATTED_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 }} diff --git a/scripts/pr-e2e-comment.sh b/scripts/pr-e2e-comment.sh new file mode 100644 index 00000000000..b0ec404e7f6 --- /dev/null +++ b/scripts/pr-e2e-comment.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Script to update or create a PR comment with E2E test tags +# Usage: ./update_pr_comment.sh "" "" +# Example: ./update_pr_comment.sh "" "@critical,@quarto" + +set -e + +# Arguments +COMMENT_MARKER="$1" # e.g., "" +TAGS="$2" # e.g., "@critical,@quarto" + +# Ensure required arguments are provided +if [ -z "$COMMENT_MARKER" ] || [ -z "$TAGS" ]; then + echo "Usage: $0 \"\" \"\"" + exit 1 +fi + +# Fetch GitHub repository and PR number from the environment +REPO="${GITHUB_REPOSITORY}" # Automatically set by GitHub Actions +PR_NUMBER="${GITHUB_PR_NUMBER:-${GITHUB_EVENT_PULL_REQUEST_NUMBER}}" # Use the correct PR number env variable +GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub token for authentication + +if [ -z "$PR_NUMBER" ]; then + echo "Error: PR number not found in the environment. Ensure GITHUB_EVENT_PULL_REQUEST_NUMBER is set." + exit 1 +fi + +if [ -z "$GITHUB_TOKEN" ]; then + echo "Error: GITHUB_TOKEN is not set. Ensure you provide a GitHub token for authentication." + exit 1 +fi + +# Fetch existing comments on the PR +COMMENTS=$(gh api repos/${REPO}/issues/${PR_NUMBER}/comments --header "Authorization: token $GITHUB_TOKEN") + +# Check if a comment with the marker already exists +COMMENT_ID=$(echo "$COMMENTS" | jq -r ".[] | select(.body | contains(\"$COMMENT_MARKER\")) | .id") + +# Format the tags with individual backticks +FORMATTED_TAGS=$(echo "$TAGS" | sed 's/,/` `/g' | sed 's/^/`/' | sed 's/$/`/') + +# Build the new comment body with proper newlines +NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\n**E2E Tests** πŸš€\nThis PR will run tests tagged with: %s" "$FORMATTED_TAGS") + +if [ -n "$COMMENT_ID" ]; then + # Update the existing comment + echo "Updating existing comment (ID: $COMMENT_ID)..." + gh api repos/${REPO}/issues/comments/$COMMENT_ID \ + -X PATCH \ + -F body="$NEW_COMMENT" \ + --header "Authorization: token $GITHUB_TOKEN" +else + # Create a new comment + echo "Creating a new comment..." + gh api repos/${REPO}/issues/${PR_NUMBER}/comments \ + -F body="$NEW_COMMENT" \ + --header "Authorization: token $GITHUB_TOKEN" +fi From 8d51f64e19ba5f854be02c35173c6b7843955c31 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 05:41:00 -0600 Subject: [PATCH 10/22] script path --- .github/workflows/pr-e2e-comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index 5fb9cfa48ee..c1e2a543869 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -28,7 +28,7 @@ jobs: - name: Update PR Comment with Tags run: | - ./pr-e2e-comment.sh "" "${{ needs.pr-tags.outputs.tags }}" + ./scripts/pr-e2e-comment.sh "" "${{ needs.pr-tags.outputs.tags }}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ github.repository }} From a3a9046f0134dad7392aa56629da9095504d65ec Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 05:42:05 -0600 Subject: [PATCH 11/22] bash --- .github/workflows/pr-e2e-comment.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index c1e2a543869..408c1c61789 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -27,8 +27,7 @@ jobs: PR_BODY: ${{ steps.PR.outputs.pr_body }} - name: Update PR Comment with Tags - run: | - ./scripts/pr-e2e-comment.sh "" "${{ needs.pr-tags.outputs.tags }}" + run: bash ./scripts/pr-e2e-comment.sh "" "${{ needs.pr-tags.outputs.tags }}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ github.repository }} From 9e12e92fc56a9aaf2dc2ba980bbadced6696da8b Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 05:44:49 -0600 Subject: [PATCH 12/22] add tags env --- .github/workflows/pr-e2e-comment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index 408c1c61789..072af7445f5 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -29,6 +29,7 @@ jobs: - name: Update PR Comment with Tags run: bash ./scripts/pr-e2e-comment.sh "" "${{ needs.pr-tags.outputs.tags }}" env: + tags: ${{ steps.pr-tags.outputs.tags }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} From 0ab45a5063b4d198c2ba0012c77beaf1199637bd Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 05:46:05 -0600 Subject: [PATCH 13/22] really fix env --- .github/workflows/pr-e2e-comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index 072af7445f5..48ed69b6681 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -27,7 +27,7 @@ jobs: PR_BODY: ${{ steps.PR.outputs.pr_body }} - name: Update PR Comment with Tags - run: bash ./scripts/pr-e2e-comment.sh "" "${{ needs.pr-tags.outputs.tags }}" + run: bash ./scripts/pr-e2e-comment.sh "" "${{ env.tags }}" env: tags: ${{ steps.pr-tags.outputs.tags }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 4aa2a0d7ba291e0b56044bb8cee2690fb210a0b2 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 05:47:03 -0600 Subject: [PATCH 14/22] cleanup --- .github/workflows/pr-e2e-comment.yml | 36 +--------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index 48ed69b6681..42eb8c61382 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -8,7 +8,7 @@ on: - edited jobs: - update-pr-tags-comment: + pr-comment: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -34,37 +34,3 @@ jobs: GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} - # - name: Update PR Comment with Tags - # run: | - # # Echo tags - # echo "tags=${{ needs.pr-tags.outputs.tags }}" - - # # 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") - - # # 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 Tests** πŸš€\nThis PR will run tests tagged with:%s" "$FORMATTED_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 2076837ed13d7f3cd80e3c8abb493210a0983894 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 06:00:19 -0600 Subject: [PATCH 15/22] add link --- scripts/pr-e2e-comment.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pr-e2e-comment.sh b/scripts/pr-e2e-comment.sh index b0ec404e7f6..abed4e0f7d6 100644 --- a/scripts/pr-e2e-comment.sh +++ b/scripts/pr-e2e-comment.sh @@ -41,7 +41,7 @@ COMMENT_ID=$(echo "$COMMENTS" | jq -r ".[] | select(.body | contains(\"$COMMENT_ FORMATTED_TAGS=$(echo "$TAGS" | sed 's/,/` `/g' | sed 's/^/`/' | sed 's/$/`/') # Build the new comment body with proper newlines -NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\n**E2E Tests** πŸš€\nThis PR will run tests tagged with: %s" "$FORMATTED_TAGS") +NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\n**E2E Tests** πŸš€  [?](https://github.com/posit-dev/positron/blob/main/test/e2e/README.md#running-tests-in-github-actions)\nThis PR will run tests tagged with: %s" "$FORMATTED_TAGS") if [ -n "$COMMENT_ID" ]; then # Update the existing comment From 99fffe39445265165e27d19f68b8e507737f57b3 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 06:14:54 -0600 Subject: [PATCH 16/22] update readme --- .github/workflows/pr-e2e-comment.yml | 4 ++-- test/e2e/README.md | 16 +++++++++++++++- test/e2e/helpers/test-tags.ts | 7 +++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index 42eb8c61382..d308e4b3985 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -1,4 +1,4 @@ -name: Comment Tags +name: "PR: Comment" on: pull_request: @@ -8,7 +8,7 @@ on: - edited jobs: - pr-comment: + e2e-tags: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/test/e2e/README.md b/test/e2e/README.md index 15290e35762..47b0d79ea03 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -193,9 +193,23 @@ For Python, add any package requirements to the `requirements.txt` file in the r For R, add any package requirements to the "imports" section of the `DESCRIPTION` file in the root of the [QA Content Examples](https://github.com/posit-dev/qa-example-content) repo. +## Pull Requests and Test Tags + +When you create a pull request, the test runner automatically scans the PR description for test tags to determine which tests to run. + +- Always-on Tests: Tests tagged with `@critical` always run, and you can’t opt out of them. +- Custom Tags: If your changes affect a specific feature, you can include additional tags in the PR description to trigger relevant tests. + +To add a test tag: + +1. Use the format `@:tag` in your PR description (e.g., `@:help`, `@:console`). +2. Once added, a comment will appear on your PR confirming that the tag was found and parsed correctly. + +From then on, all tests associated with the specified tag(s) will run during your test workflows. See [here](https://github.com/posit-dev/positron/blob/main/test/e2e/helpers/test-tags.ts) for a complete list of tags. + ## Running Tests in Github Actions -New tests are not complete until they run successfully across operating systems (Mac, Windows, & Ubuntu) and in [Github Actions](https://github.com/posit-dev/positron/actions/workflows/positron-full-test.yml). In Github Actions we use an Ubuntu instance to run the tests, so if you are developing your tests using a Mac or on Windows, this is an opportunity to test a different operating system. Also, you can easily run your new tests against a branch to verify them before merge. Simply pick the branch after you click on "Run Workflow". Note that you can also temporarily modify the workflow itself to get your new tests executed more quickly. To do this, skip the runs of the unit and integration tests. +New tests are not complete until they run successfully across operating systems (Mac, Windows, & Ubuntu) and in [Github Actions](https://github.com/posit-dev/positron/actions/workflows/test-full-suite.yml). In Github Actions we use an Ubuntu instance to run the tests, so if you are developing your tests using a Mac or on Windows, this is an opportunity to test a different operating system. Also, you can easily run your new tests against a branch to verify them before merge. Simply pick the branch after you click on "Run Workflow". Note that you can also temporarily modify the workflow itself to get your new tests executed more quickly. To do this, skip the runs of the unit and integration tests. ### Github Actions Test Artifacts diff --git a/test/e2e/helpers/test-tags.ts b/test/e2e/helpers/test-tags.ts index 2757f1b377b..0550dae130f 100644 --- a/test/e2e/helpers/test-tags.ts +++ b/test/e2e/helpers/test-tags.ts @@ -6,12 +6,11 @@ /** * Use the tags listed below to selectively run e2e tests against your PR. * - * - To run all e2e tests, include `@:all` in your PR description. - * - Avoid using `@:web` and `@:win` tags, as these are reserved for web and Windows platform-specific tests, - * which are not currently configured to run in PR workflows. - * * Each tag corresponds to a specific feature, functionality, or area of the application. Use them * thoughtfully to ensure your tests align with the intended scope. + * + * Avoid using `@:web` and `@:win` tags, as these are reserved for web and Windows platform-specific tests, + * which are not currently configured to run in PR workflows. */ export enum TestTags { APPS = '@apps', From e43725f28d610b73bb1a0cc608e6a089a1f0752e Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 06:17:44 -0600 Subject: [PATCH 17/22] update template --- .github/pull_request_template.md | 5 ----- scripts/pr-e2e-comment.sh | 2 +- test/e2e/README.md | 4 ++-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a58c963e8d9..da9468e72d8 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -16,11 +16,6 @@ main branch by either pulling or rebasing. describe them here. --> -### Tests to Run - - -`@:critical` - ### QA Notes " "${{ env.tags }}" diff --git a/scripts/pr-e2e-comment.sh b/scripts/pr-e2e-comment.sh index 0995b29bb58..7665001386b 100644 --- a/scripts/pr-e2e-comment.sh +++ b/scripts/pr-e2e-comment.sh @@ -1,59 +1,60 @@ #!/bin/bash - -# Script to update or create a PR comment with E2E test tags -# Usage: ./update_pr_comment.sh "" "" -# Example: ./update_pr_comment.sh "" "@critical,@quarto" +# Script to parse tags from a GitHub Pull Request body +# Usage: bash parse-pr-tags.sh set -e -# Arguments -COMMENT_MARKER="$1" # e.g., "" -TAGS="$2" # e.g., "@critical,@quarto" - -# Ensure required arguments are provided -if [ -z "$COMMENT_MARKER" ] || [ -z "$TAGS" ]; then - echo "Usage: $0 \"\" \"\"" - exit 1 -fi - # Fetch GitHub repository and PR number from the environment REPO="${GITHUB_REPOSITORY}" # Automatically set by GitHub Actions PR_NUMBER="${GITHUB_PR_NUMBER:-${GITHUB_EVENT_PULL_REQUEST_NUMBER}}" # Use the correct PR number env variable GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub token for authentication -if [ -z "$PR_NUMBER" ]; then - echo "Error: PR number not found in the environment. Ensure GITHUB_EVENT_PULL_REQUEST_NUMBER is set." +# Validate required environment variables +if [[ -z "$REPO" || -z "$PR_NUMBER" || -z "$GITHUB_TOKEN" ]]; then + echo "Error: Missing required environment variables." + echo "Ensure the following are set: GITHUB_REPOSITORY, GITHUB_PR_NUMBER or GITHUB_EVENT_PULL_REQUEST_NUMBER, GITHUB_TOKEN." exit 1 fi -if [ -z "$GITHUB_TOKEN" ]; then - echo "Error: GITHUB_TOKEN is not set. Ensure you provide a GitHub token for authentication." +# Fetch the PR body using the GitHub CLI +echo "Fetching PR body for ${REPO} #${PR_NUMBER}..." +PULL_REQUEST_BODY=$(gh api repos/${REPO}/pulls/${PR_NUMBER} --header "Authorization: token $GITHUB_TOKEN" --jq '.body') + +# Handle empty PR body +if [[ -z "$PULL_REQUEST_BODY" ]]; then + echo "Error: PR body is empty or could not be fetched." exit 1 fi -# Fetch existing comments on the PR -COMMENTS=$(gh api repos/${REPO}/issues/${PR_NUMBER}/comments --header "Authorization: token $GITHUB_TOKEN") +# Sanitize the PR BODY by removing newlines and escaping double quotes +PR_BODY=$(echo "$PULL_REQUEST_BODY" | tr '\n' ' ' | sed 's/"/\\"/g') -# Check if a comment with the marker already exists -COMMENT_ID=$(echo "$COMMENTS" | jq -r ".[] | select(.body | contains(\"$COMMENT_MARKER\")) | .id") +echo "Parsing tags from PR body..." -# Format the tags with individual backticks -FORMATTED_TAGS=$(echo "$TAGS" | sed 's/,/` `/g' | sed 's/^/`/' | sed 's/$/`/') +# 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." + TAGS="" # Set to an empty string to indicate all tests should run +else + # Parse tags starting with '@:' and convert to '@' + TAGS=$(echo "$PR_BODY" | grep -o "@:[a-zA-Z0-9_-]*" | sed 's/@://g' | sed 's/^/@/' | tr '\n' ',' | sed 's/,$//') + + # Always add @critical if not already included + if [[ ! "$TAGS" =~ "@critical" ]]; then + if [[ -n "$TAGS" ]]; then + TAGS="@critical,$TAGS" + else + TAGS="@critical" + fi + fi +fi -# Build the new comment body with proper newlines -NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\n**E2E Tests** πŸš€  [?](https://github.com/posit-dev/positron/blob/main/test/e2e/README.md#pull-requests-and-test-tags)\nThis PR will run tests tagged with: %s" "$FORMATTED_TAGS") +# Output the tags +echo "Extracted Tags: $TAGS" -if [ -n "$COMMENT_ID" ]; then - # Update the existing comment - echo "Updating existing comment (ID: $COMMENT_ID)..." - gh api repos/${REPO}/issues/comments/$COMMENT_ID \ - -X PATCH \ - -F body="$NEW_COMMENT" \ - --header "Authorization: token $GITHUB_TOKEN" +# Save tags to GITHUB_OUTPUT for use in GitHub Actions +if [[ -n "$GITHUB_OUTPUT" ]]; then + echo "tags=$TAGS" >> "$GITHUB_OUTPUT" else - # Create a new comment - echo "Creating a new comment..." - gh api repos/${REPO}/issues/${PR_NUMBER}/comments \ - -F body="$NEW_COMMENT" \ - --header "Authorization: token $GITHUB_TOKEN" + echo "Warning: GITHUB_OUTPUT is not set. Tags will not be available to the workflow." fi diff --git a/scripts/pr-tags-parse.sh b/scripts/pr-tags-parse.sh index 0c2a4244123..93a8000900d 100644 --- a/scripts/pr-tags-parse.sh +++ b/scripts/pr-tags-parse.sh @@ -1,14 +1,13 @@ #!/bin/bash # Usage: -# bash parse-pr-tags.sh "" +# bash parse-pr-tags.sh "" # Example: -# bash parse-pr-tags.sh "/path/to/event.json" +# bash parse-pr-tags.sh "This is a PR..." -# Input: Path to the GitHub event JSON file +# Input: PULL_REQUEST_BODY PULL_REQUEST_BODY="$1" -# Extract the PR body from the event JSON -echo "Extracting PR body..." +# Sanitize the PR BODY by removing newlines and escaping double quotes PR_BODY=$(echo "$PULL_REQUEST_BODY" | tr '\n' ' ' | sed 's/"/\\"/g') echo "Parsing tags from PR body..." From f49a6b1672b72625bce5e695d14e555a7183ba28 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 06:46:22 -0600 Subject: [PATCH 19/22] Revert "remove custom action" This reverts commit 6fa512f0486bd1f519853536f7a7cc6f2a0c9ca8. --- .github/workflows/pr-e2e-comment.yml | 18 +++---- scripts/pr-e2e-comment.sh | 77 ++++++++++++++-------------- scripts/pr-tags-parse.sh | 9 ++-- 3 files changed, 51 insertions(+), 53 deletions(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index 8de3190e01b..d308e4b3985 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -13,20 +13,18 @@ jobs: steps: - uses: actions/checkout@v4 - # - uses: 8BitJonny/gh-get-current-pr@3.0.0 - # id: PR - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # sha: ${{ github.event.pull_request.head.sha }} - # filterOutClosed: true + - uses: 8BitJonny/gh-get-current-pr@3.0.0 + id: PR + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + sha: ${{ github.event.pull_request.head.sha }} + filterOutClosed: true - name: Parse Tags from PR Body id: pr-tags - run: bash scripts/pr-tags-parse.sh + run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_REPOSITORY: ${{ github.repository }} - GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} + PR_BODY: ${{ steps.PR.outputs.pr_body }} - name: Update PR Comment with Tags run: bash ./scripts/pr-e2e-comment.sh "" "${{ env.tags }}" diff --git a/scripts/pr-e2e-comment.sh b/scripts/pr-e2e-comment.sh index 7665001386b..0995b29bb58 100644 --- a/scripts/pr-e2e-comment.sh +++ b/scripts/pr-e2e-comment.sh @@ -1,60 +1,59 @@ #!/bin/bash -# Script to parse tags from a GitHub Pull Request body -# Usage: bash parse-pr-tags.sh + +# Script to update or create a PR comment with E2E test tags +# Usage: ./update_pr_comment.sh "" "" +# Example: ./update_pr_comment.sh "" "@critical,@quarto" set -e +# Arguments +COMMENT_MARKER="$1" # e.g., "" +TAGS="$2" # e.g., "@critical,@quarto" + +# Ensure required arguments are provided +if [ -z "$COMMENT_MARKER" ] || [ -z "$TAGS" ]; then + echo "Usage: $0 \"\" \"\"" + exit 1 +fi + # Fetch GitHub repository and PR number from the environment REPO="${GITHUB_REPOSITORY}" # Automatically set by GitHub Actions PR_NUMBER="${GITHUB_PR_NUMBER:-${GITHUB_EVENT_PULL_REQUEST_NUMBER}}" # Use the correct PR number env variable GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub token for authentication -# Validate required environment variables -if [[ -z "$REPO" || -z "$PR_NUMBER" || -z "$GITHUB_TOKEN" ]]; then - echo "Error: Missing required environment variables." - echo "Ensure the following are set: GITHUB_REPOSITORY, GITHUB_PR_NUMBER or GITHUB_EVENT_PULL_REQUEST_NUMBER, GITHUB_TOKEN." +if [ -z "$PR_NUMBER" ]; then + echo "Error: PR number not found in the environment. Ensure GITHUB_EVENT_PULL_REQUEST_NUMBER is set." exit 1 fi -# Fetch the PR body using the GitHub CLI -echo "Fetching PR body for ${REPO} #${PR_NUMBER}..." -PULL_REQUEST_BODY=$(gh api repos/${REPO}/pulls/${PR_NUMBER} --header "Authorization: token $GITHUB_TOKEN" --jq '.body') - -# Handle empty PR body -if [[ -z "$PULL_REQUEST_BODY" ]]; then - echo "Error: PR body is empty or could not be fetched." +if [ -z "$GITHUB_TOKEN" ]; then + echo "Error: GITHUB_TOKEN is not set. Ensure you provide a GitHub token for authentication." exit 1 fi -# Sanitize the PR BODY by removing newlines and escaping double quotes -PR_BODY=$(echo "$PULL_REQUEST_BODY" | tr '\n' ' ' | sed 's/"/\\"/g') +# Fetch existing comments on the PR +COMMENTS=$(gh api repos/${REPO}/issues/${PR_NUMBER}/comments --header "Authorization: token $GITHUB_TOKEN") -echo "Parsing tags from PR body..." +# Check if a comment with the marker already exists +COMMENT_ID=$(echo "$COMMENTS" | jq -r ".[] | select(.body | contains(\"$COMMENT_MARKER\")) | .id") -# 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." - TAGS="" # Set to an empty string to indicate all tests should run -else - # Parse tags starting with '@:' and convert to '@' - TAGS=$(echo "$PR_BODY" | grep -o "@:[a-zA-Z0-9_-]*" | sed 's/@://g' | sed 's/^/@/' | tr '\n' ',' | sed 's/,$//') - - # Always add @critical if not already included - if [[ ! "$TAGS" =~ "@critical" ]]; then - if [[ -n "$TAGS" ]]; then - TAGS="@critical,$TAGS" - else - TAGS="@critical" - fi - fi -fi +# Format the tags with individual backticks +FORMATTED_TAGS=$(echo "$TAGS" | sed 's/,/` `/g' | sed 's/^/`/' | sed 's/$/`/') -# Output the tags -echo "Extracted Tags: $TAGS" +# Build the new comment body with proper newlines +NEW_COMMENT=$(printf "${COMMENT_MARKER}\n\n**E2E Tests** πŸš€  [?](https://github.com/posit-dev/positron/blob/main/test/e2e/README.md#pull-requests-and-test-tags)\nThis PR will run tests tagged with: %s" "$FORMATTED_TAGS") -# Save tags to GITHUB_OUTPUT for use in GitHub Actions -if [[ -n "$GITHUB_OUTPUT" ]]; then - echo "tags=$TAGS" >> "$GITHUB_OUTPUT" +if [ -n "$COMMENT_ID" ]; then + # Update the existing comment + echo "Updating existing comment (ID: $COMMENT_ID)..." + gh api repos/${REPO}/issues/comments/$COMMENT_ID \ + -X PATCH \ + -F body="$NEW_COMMENT" \ + --header "Authorization: token $GITHUB_TOKEN" else - echo "Warning: GITHUB_OUTPUT is not set. Tags will not be available to the workflow." + # Create a new comment + echo "Creating a new comment..." + gh api repos/${REPO}/issues/${PR_NUMBER}/comments \ + -F body="$NEW_COMMENT" \ + --header "Authorization: token $GITHUB_TOKEN" fi diff --git a/scripts/pr-tags-parse.sh b/scripts/pr-tags-parse.sh index 93a8000900d..0c2a4244123 100644 --- a/scripts/pr-tags-parse.sh +++ b/scripts/pr-tags-parse.sh @@ -1,13 +1,14 @@ #!/bin/bash # Usage: -# bash parse-pr-tags.sh "" +# bash parse-pr-tags.sh "" # Example: -# bash parse-pr-tags.sh "This is a PR..." +# bash parse-pr-tags.sh "/path/to/event.json" -# Input: PULL_REQUEST_BODY +# Input: Path to the GitHub event JSON file PULL_REQUEST_BODY="$1" -# Sanitize the PR BODY by removing newlines and escaping double quotes +# Extract the PR body from the event JSON +echo "Extracting PR body..." PR_BODY=$(echo "$PULL_REQUEST_BODY" | tr '\n' ' ' | sed 's/"/\\"/g') echo "Parsing tags from PR body..." From 4ca197554f752a0c5d5a465e73d324d405877164 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 06:49:04 -0600 Subject: [PATCH 20/22] use gh api --- .github/workflows/pr-e2e-comment.yml | 18 ++++++------- .github/workflows/test-pull-request.yml | 18 ++++++------- scripts/pr-tags-parse.sh | 34 +++++++++++++++++++------ 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index d308e4b3985..6f10460cd79 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -13,18 +13,18 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: 8BitJonny/gh-get-current-pr@3.0.0 - id: PR - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - sha: ${{ github.event.pull_request.head.sha }} - filterOutClosed: true + # - uses: 8BitJonny/gh-get-current-pr@3.0.0 + # id: PR + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # sha: ${{ github.event.pull_request.head.sha }} + # filterOutClosed: true - name: Parse Tags from PR Body id: pr-tags - run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" - env: - PR_BODY: ${{ steps.PR.outputs.pr_body }} + run: bash scripts/pr-tags-parse.sh + # env: + # PR_BODY: ${{ steps.PR.outputs.pr_body }} - name: Update PR Comment with Tags run: bash ./scripts/pr-e2e-comment.sh "" "${{ env.tags }}" diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 505277f306a..d60fa90b42d 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -15,18 +15,18 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: 8BitJonny/gh-get-current-pr@3.0.0 - id: PR - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - sha: ${{ github.event.pull_request.head.sha }} - filterOutClosed: true + # - uses: 8BitJonny/gh-get-current-pr@3.0.0 + # id: PR + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # sha: ${{ github.event.pull_request.head.sha }} + # filterOutClosed: true - name: Parse Tags from PR Body id: pr-tags - run: bash scripts/pr-tags-parse.sh "${{ env.PR_BODY }}" - env: - PR_BODY: ${{ steps.PR.outputs.pr_body }} + run: bash scripts/pr-tags-parse.sh + # env: + # PR_BODY: ${{ steps.PR.outputs.pr_body }} e2e-electron: name: e2e diff --git a/scripts/pr-tags-parse.sh b/scripts/pr-tags-parse.sh index 0c2a4244123..7665001386b 100644 --- a/scripts/pr-tags-parse.sh +++ b/scripts/pr-tags-parse.sh @@ -1,14 +1,32 @@ #!/bin/bash -# Usage: -# bash parse-pr-tags.sh "" -# Example: -# bash parse-pr-tags.sh "/path/to/event.json" +# Script to parse tags from a GitHub Pull Request body +# Usage: bash parse-pr-tags.sh -# Input: Path to the GitHub event JSON file -PULL_REQUEST_BODY="$1" +set -e -# Extract the PR body from the event JSON -echo "Extracting PR body..." +# Fetch GitHub repository and PR number from the environment +REPO="${GITHUB_REPOSITORY}" # Automatically set by GitHub Actions +PR_NUMBER="${GITHUB_PR_NUMBER:-${GITHUB_EVENT_PULL_REQUEST_NUMBER}}" # Use the correct PR number env variable +GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub token for authentication + +# Validate required environment variables +if [[ -z "$REPO" || -z "$PR_NUMBER" || -z "$GITHUB_TOKEN" ]]; then + echo "Error: Missing required environment variables." + echo "Ensure the following are set: GITHUB_REPOSITORY, GITHUB_PR_NUMBER or GITHUB_EVENT_PULL_REQUEST_NUMBER, GITHUB_TOKEN." + exit 1 +fi + +# Fetch the PR body using the GitHub CLI +echo "Fetching PR body for ${REPO} #${PR_NUMBER}..." +PULL_REQUEST_BODY=$(gh api repos/${REPO}/pulls/${PR_NUMBER} --header "Authorization: token $GITHUB_TOKEN" --jq '.body') + +# Handle empty PR body +if [[ -z "$PULL_REQUEST_BODY" ]]; then + echo "Error: PR body is empty or could not be fetched." + exit 1 +fi + +# Sanitize the PR BODY by removing newlines and escaping double quotes PR_BODY=$(echo "$PULL_REQUEST_BODY" | tr '\n' ' ' | sed 's/"/\\"/g') echo "Parsing tags from PR body..." From b6a2bd47fcabf1ff354a3806981b104e36cd4e4d Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 06:52:54 -0600 Subject: [PATCH 21/22] missing env --- .github/workflows/pr-e2e-comment.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index 6f10460cd79..c73af8e34d1 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -23,7 +23,10 @@ jobs: - name: Parse Tags from PR Body id: pr-tags run: bash scripts/pr-tags-parse.sh - # env: + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} # PR_BODY: ${{ steps.PR.outputs.pr_body }} - name: Update PR Comment with Tags From 22d9ff90c1fdc9c28d2047d1ba1a57201d454fbf Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Thu, 12 Dec 2024 06:56:31 -0600 Subject: [PATCH 22/22] remove comments --- .github/workflows/pr-e2e-comment.yml | 8 -------- .github/workflows/test-pull-request.yml | 13 ++++--------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.github/workflows/pr-e2e-comment.yml b/.github/workflows/pr-e2e-comment.yml index c73af8e34d1..43b030e3b5f 100644 --- a/.github/workflows/pr-e2e-comment.yml +++ b/.github/workflows/pr-e2e-comment.yml @@ -13,13 +13,6 @@ jobs: steps: - uses: actions/checkout@v4 - # - uses: 8BitJonny/gh-get-current-pr@3.0.0 - # id: PR - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # sha: ${{ github.event.pull_request.head.sha }} - # filterOutClosed: true - - name: Parse Tags from PR Body id: pr-tags run: bash scripts/pr-tags-parse.sh @@ -27,7 +20,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} - # PR_BODY: ${{ steps.PR.outputs.pr_body }} - name: Update PR Comment with Tags run: bash ./scripts/pr-e2e-comment.sh "" "${{ env.tags }}" diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index d60fa90b42d..2de5cdf9898 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -15,18 +15,13 @@ jobs: steps: - uses: actions/checkout@v4 - # - uses: 8BitJonny/gh-get-current-pr@3.0.0 - # id: PR - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # sha: ${{ github.event.pull_request.head.sha }} - # filterOutClosed: true - - name: Parse Tags from PR Body id: pr-tags run: bash scripts/pr-tags-parse.sh - # env: - # PR_BODY: ${{ steps.PR.outputs.pr_body }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} e2e-electron: name: e2e