name: Black Formatter Check on: pull_request: types: [opened, synchronize, reopened] jobs: black-check: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Get commit messages id: commits run: | messages=$(gh pr view ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --json commits --jq '.commits[].message') if echo "$messages" | grep -q "chore: format code with black"; then echo "skip=true" >> $GITHUB_OUTPUT else echo "skip=false" >> $GITHUB_OUTPUT fi env: GH_TOKEN: ${{ secrets.GH_TOKEN }} - name: Set up Python 3.x if: steps.commits.outputs.skip == 'false' uses: actions/setup-python@v4 with: python-version: '3.x' - name: Install black if: steps.commits.outputs.skip == 'false' run: pip install black - name: Run black --check if: steps.commits.outputs.skip == 'false' id: black-check run: | black . --check continue-on-error: true - name: Comment on PR (success) if: steps.commits.outputs.skip == 'false' && steps.black-check.outcome == 'success' uses: actions/github-script@v6 with: github-token: ${{ secrets.GH_TOKEN }} script: | github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body: "> [!NOTE]\n> πŸŽ‰ Black ν¬λ§€νŒ… 검사가 μ„±κ³΅μ μœΌλ‘œ μ™„λ£Œλ˜μ—ˆμ–΄μš”.\n`/review`둜 리뷰λ₯Ό μš”μ²­ν•˜μ‹€ 수 μžˆμ–΄μš”." }) - name: Comment on PR (failure) if: steps.commits.outputs.skip == 'false' && steps.black-check.outcome == 'failure' uses: actions/github-script@v6 with: github-token: ${{ secrets.GH_TOKEN }} script: | github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body: "> [!WARNING]\n> 😒 μ½”λ“œ ν¬λ§€νŒ…μ΄ ν•„μš”ν•΄μš”.\n`black .` λͺ…λ Ήμ–΄λ‘œ μ½”λ“œλ₯Ό ν¬λ§€νŒ…ν•˜κ±°λ‚˜ `/format` λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•΄ μ£Όμ„Έμš”." })