Skip to content

Determine Tests Bot #167

Determine Tests Bot

Determine Tests Bot #167

name: Determine Tests Bot
on:
workflow_run:
workflows:
- Verify Changes
types:
- requested
jobs:
add-comment-to-pr:
runs-on: ubuntu-latest
timeout-minutes: 1
permissions:
pull-requests: write
issues: write
if: ${{github.repository != github.event.workflow_run.head_repository.full_name }}
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Get Recommended Tests
run: |
{
echo 'tests_from_script<<EOF'
./.github/scripts/check-changed-tests.sh "${{ github.event.workflow_run.head_commit.id }}" "${{ github.event.workflow_run.head_repository.full_name }}"
echo EOF
} >> "$GITHUB_ENV"
- name: Add comment to PR
run: |
PR_NUMBER=$(curl -s \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls?state=all" \
| jq '.[] | select(.head.sha == "${{ github.event.workflow_run.head_commit.id }}") | .number' | head -n 1)
if [[ -n "$tests_from_script" ]]; then
response=$(curl -s -o response.json -w "%{http_code}" -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }} " \
-H "Accept: application/vnd.github.v3+json" \
--data-binary '{"body": "'"$tests_from_script"'"}' \
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments")
if [[ "$response" -lt 200 || "$response" -gt 300 ]]; then
echo "Failed to post the comment. HTTP response code: $response"
cat response.json
exit 1
fi
fi