Skip to content

cloc-report

cloc-report #139

Workflow file for this run

name: cloc-report
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [main]
jobs:
cloc:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: install cloc
run: sudo apt-get update && sudo apt-get install -y cloc
- name: run cloc (json)
run: cloc --json . --exclude-dir=.git > cloc.json
- name: create summary (for PR comment)
id: make_comment
run: |
python3 - <<'PY'
import json,sys,os
j=json.load(open('cloc.json'))
s=j.get('SUM',{})
files=s.get('files',0)
code=s.get('code',0)
blank=s.get('blank',0)
comment=f"**cloc summary**\n\n- files: {files}\n- code lines: {code}\n- blank lines: {blank}\n\nFull JSON attached as artifact."
print(f"body<<EOF\n{comment}\nEOF")
PY
# the previous print is consumed by the next line to set GITHUB_OUTPUT
echo "::set-output name=body::$(python3 -c "import json; j=json.load(open('cloc.json')); s=j.get('SUM',{}); print(f'Files: {s.get('files',0)}, Code: {s.get('code',0)}, Blank: {s.get('blank',0)}')")"
- name: post or update PR comment with cloc summary
uses: peter-evans/create-or-update-comment@v3 # NOSONAR
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
**cloc summary**
$(cat cloc.json | jq '.SUM' 2>/dev/null || true)
- name: upload cloc.json
uses: actions/upload-artifact@v4
with:
name: cloc-report
path: cloc.json