Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pr comment #5703

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/parse-pr-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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="<!-- PR Tags -->"

# 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\nRunning E2E 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 }}
53 changes: 45 additions & 8 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,57 @@ 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 }}
# 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:
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
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Define the comment marker
COMMENT_MARKER="<!-- PR Tags -->"

# 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" | awk '/Running E2E tests tagged with:/{flag=1; next} /<!--/{flag=0} flag' | tr -d '`')

if [ -z "$TAGS" ]; then
echo "No tags found in comment body. Exiting."
exit 1
fi

echo "Extracted Tags: $TAGS"
echo "tags=$TAGS" >> $GITHUB_ENV

e2e-electron:
if: github.event_name == 'pull_request'
name: e2e
uses: ./.github/workflows/test-e2e-linux.yml
needs: pr-tags
Expand All @@ -29,14 +67,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



4 changes: 2 additions & 2 deletions build/secrets/.secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"filename": ".github/workflows/test-pull-request.yml",
"hashed_secret": "3e26d6750975d678acb8fa35a0f69237881576b0",
"is_verified": false,
"line_number": 29
"line_number": 62
}
],
"build/azure-pipelines/alpine/product-build-alpine.yml": [
Expand Down Expand Up @@ -1933,5 +1933,5 @@
}
]
},
"generated_at": "2024-12-10T16:17:08Z"
"generated_at": "2024-12-11T22:48:43Z"
}
11 changes: 6 additions & 5 deletions scripts/pr-tags-parse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '@'
Expand All @@ -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
Loading