diff --git a/.github/actions/pin_comment/action.yml b/.github/actions/pin_comment/action.yml new file mode 100644 index 00000000..62bc660b --- /dev/null +++ b/.github/actions/pin_comment/action.yml @@ -0,0 +1,50 @@ +name: "Pin Comment" +description: "Pins a comment by hiding it with HTML comments and a unique ID" + +inputs: + message: + description: "The message to pin" + required: true + token: + description: "GitHub token" + required: true + issue_number: + description: "The issue or PR number" + required: true + comment_id: + description: "Unique identifier for this pinned comment" + required: true + +runs: + using: "composite" + steps: + - name: Pin comment + shell: bash + env: + GH_TOKEN: ${{ inputs.token }} + MESSAGE: ${{ inputs.message }} + ISSUE_NUMBER: ${{ inputs.issue_number }} + COMMENT_ID: ${{ inputs.comment_id }} + run: | + # Create comment with hidden marker and ID + COMMENT=" + ${MESSAGE}" + + # Find and delete old comment with same ID + gh api graphql -f query=' + query($owner:String!, $repo:String!, $number:Int!) { + repository(owner:$owner, name:$repo) { + issueOrPullRequest(number:$number) { + ... on Issue { comments(first:100) { nodes { id body } } } + ... on PullRequest { comments(first:100) { nodes { id body } } } + } + } + }' -f owner="${GITHUB_REPOSITORY%/*}" -f repo="${GITHUB_REPOSITORY#*/}" -f number="${ISSUE_NUMBER}" | + jq -r ".data.repository.issueOrPullRequest.comments.nodes[] | select(.body | startswith(\"\")) | .id" | + while read -r comment_id; do + gh api --method DELETE "/graphql" -f query="mutation { deleteIssueComment(input: {id: \"$comment_id\"}) { clientMutationId } }" + done + + # Create new pinned comment + gh issue comment "${ISSUE_NUMBER}" --body "${COMMENT}" + diff --git a/.github/workflows/docs-preview.yml b/.github/workflows/docs-preview.yml index f5fb400c..ea305d8c 100644 --- a/.github/workflows/docs-preview.yml +++ b/.github/workflows/docs-preview.yml @@ -20,8 +20,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Create initial PR comment - uses: marocchino/sticky-pull-request-comment@v2 + uses: ./.github/actions/pin_comment with: + token: ${{ secrets.GITHUB_TOKEN }} + issue_number: ${{ github.event.pull_request.number }} + comment_id: docs-preview message: | 📚 **Documentation Preview** @@ -81,8 +84,11 @@ jobs: python -m tools.github_readme_sync.cli upload docs "${VERSION}-${BRANCH_NAME}" - name: Update PR comment on success if: success() - uses: marocchino/sticky-pull-request-comment@v2 + uses: ./.github/actions/pin_comment with: + token: ${{ secrets.GITHUB_TOKEN }} + issue_number: ${{ github.event.pull_request.number }} + comment_id: docs-preview message: | 📚 **Documentation Preview** @@ -92,8 +98,11 @@ jobs: Last updated: ${{ env.DATE }} - name: Update PR comment on failure if: failure() - uses: marocchino/sticky-pull-request-comment@v2 + uses: ./.github/actions/pin_comment with: + token: ${{ secrets.GITHUB_TOKEN }} + issue_number: ${{ github.event.pull_request.number }} + comment_id: docs-preview message: | 📚 **Documentation Preview**