Add pr-review job to pull-request workflow #389
Workflow file for this run
This file contains hidden or 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
| # Running tests with tox for releasing new version | |
| name: Pull requests fosslight_binary_scanner | |
| on: | |
| pull_request: | |
| branches: | |
| - '*' | |
| jobs: | |
| check-commit-message: | |
| uses: fosslight/.github/.github/workflows/base-check-commit-message.yml@main | |
| secrets: | |
| envPAT: ${{ secrets.GITHUB_TOKEN }} | |
| run_tox: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.12.x] | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install tox | |
| - name: Run Tox | |
| run: | | |
| tox -e release | |
| exe_windows: | |
| name: Run an executable for windows | |
| runs-on: windows-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.12.x] | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install & Run | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install . | |
| pip install pyinstaller | |
| pyinstaller cli.spec | |
| move dist\cli.exe tests\fosslight_bin_windows.exe | |
| .\tests\fosslight_bin_windows.exe | |
| reuse: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: REUSE Compliance Check | |
| uses: fsfe/reuse-action@v1 | |
| pr-review: | |
| runs-on: ubuntu-latest | |
| continue-on-error: true | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get diff | |
| id: diff | |
| run: | | |
| git diff "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" -- . > diff.txt | |
| echo "size=$(wc -c < diff.txt)" >> $GITHUB_OUTPUT | |
| - name: Skip if no code change | |
| id: skip | |
| run: | | |
| if [ "${{ steps.diff.outputs.size }}" -lt 5 ]; then | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Request review from service | |
| id: review | |
| if: steps.skip.outputs.skip != 'true' | |
| timeout-minutes: 360 | |
| env: | |
| SERVICE_URL: ${{ secrets.PR_REVIEW_SERVICE_URL }} | |
| run: | | |
| echo '{"pr_title": ${{ toJSON(github.event.pull_request.title) }}, "pr_body": ${{ toJSON(github.event.pull_request.body) }}}' > meta.json | |
| jq -n --rawfile diff diff.txt --slurpfile m meta.json '$m[0] + {diff: $diff}' > payload.json | |
| RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${SERVICE_URL}/review" \ | |
| -H "Content-Type: application/json" \ | |
| -d @payload.json) || true | |
| HTTP_BODY=$(echo "$RESPONSE" | head -n -1) | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n 1) | |
| BODY=$(echo "$HTTP_BODY" | jq -r '.body // empty' 2>/dev/null) | |
| ERR_MSG=$(echo "$HTTP_BODY" | jq -r '.error // .message // .detail // empty' 2>/dev/null) | |
| echo "## 🤖 LLM 리뷰 요약" > review_body.md | |
| echo "" >> review_body.md | |
| if [ -n "$BODY" ]; then | |
| echo "$BODY" >> review_body.md | |
| else | |
| echo "리뷰 생성에 실패했거나 응답이 비어 있습니다." >> review_body.md | |
| if [ -n "$ERR_MSG" ]; then | |
| echo "" >> review_body.md | |
| echo "**에러 메시지:** $ERR_MSG" >> review_body.md | |
| elif [ -n "$HTTP_CODE" ] && [ "$HTTP_CODE" -ge 400 ]; then | |
| echo "" >> review_body.md | |
| echo "**HTTP 상태:** $HTTP_CODE" >> review_body.md | |
| fi | |
| fi | |
| - name: Post review comment | |
| if: steps.skip.outputs.skip != 'true' && success() | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| token: ${{ secrets.TOKEN || secrets.GITHUB_TOKEN }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| body-path: review_body.md | |
| edit-mode: replace | |
| - name: Comment when no code change | |
| if: steps.skip.outputs.skip == 'true' | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| token: ${{ secrets.TOKEN || secrets.GITHUB_TOKEN }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| body: "## 🤖 LLM 리뷰 요약\n\n이 PR에는 리뷰할 코드 변경이 없습니다." | |
| edit-mode: replace |