-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: improved tags in pull-request (#5706)
### Summary Previously, re-running the `test-pull-request.yml` workflow failed to detect updated tags in the PR description because it relied on outdated data from the prior GitHub event. This issue has been resolved by using the GitHub API to fetch the latest PR information directly. In addition, a comment is now posted to the PR to confirm the detected tags and provide feedback whenever tags are updated in the PR description. ### QA Notes Confirmed I can re-run jobs after changing tags in PR description and it works as expected. **Feel free to edit/add tags and see the comment update on this PR.** @:data-explorer ### Screenshots <img width="939" alt="Screenshot 2024-12-12 at 7 08 18 AM" src="/~https://github.com/user-attachments/assets/e506da57-294e-4a80-a6a5-6707fc37e5a6" /> Note: The `?` in the comment links to the new section I added in the README. It won't work right now since that readme section is not available in `main` yet.
- Loading branch information
Showing
8 changed files
with
143 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: "PR: Comment" | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
- edited | ||
|
||
jobs: | ||
e2e-tags: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Parse Tags from PR Body | ||
id: pr-tags | ||
run: bash scripts/pr-tags-parse.sh | ||
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: bash ./scripts/pr-e2e-comment.sh "<!-- PR Tags -->" "${{ env.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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
# Script to update or create a PR comment with E2E test tags | ||
# Usage: ./update_pr_comment.sh "<comment_marker>" "<tags>" | ||
# Example: ./update_pr_comment.sh "<!-- PR Tags -->" "@critical,@quarto" | ||
|
||
set -e | ||
|
||
# Arguments | ||
COMMENT_MARKER="$1" # e.g., "<!-- PR Tags -->" | ||
TAGS="$2" # e.g., "@critical,@quarto" | ||
|
||
# Ensure required arguments are provided | ||
if [ -z "$COMMENT_MARKER" ] || [ -z "$TAGS" ]; then | ||
echo "Usage: $0 \"<comment_marker>\" \"<tags>\"" | ||
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** 🚀 <sup>[?](/~https://github.com/posit-dev/positron/blob/main/test/e2e/README.md#pull-requests-and-test-tags)</sup>\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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters