diff --git a/.github/workflows/parse-pr-tags.yml b/.github/workflows/parse-pr-tags.yml new file mode 100644 index 00000000000..f653d491990 --- /dev/null +++ b/.github/workflows/parse-pr-tags.yml @@ -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="" + + # 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 }} diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 4c4226d9530..f4ab7f33634 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -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="" + + # 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} /