Skip to content

Commit 412b5fb

Browse files
Add GitHub Actions workflow for PR line counting with PR comments (#162)
* Add GitHub Action workflow for PR line counting Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com> * Improve workflow: use env variable and more robust line counting Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com> * Add explicit permissions to workflow for security Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com> * Add PR commenting and improve line counting for files without trailing newlines Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com>
1 parent 7c6174b commit 412b5fb

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: PR Line Counter
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
count-lines:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
env:
14+
TARGET_FILE: utils/matrix-logic/generate_sweep_configs.py
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Count lines in generate_sweep_configs.py
21+
id: line-count
22+
run: |
23+
if [ -f "$TARGET_FILE" ]; then
24+
LINE_COUNT=$(wc -l < "$TARGET_FILE")
25+
# If the last character is not a newline, increment the count
26+
if [ -n "$(tail -c 1 "$TARGET_FILE" | tr -d '\n')" ]; then
27+
LINE_COUNT=$((LINE_COUNT + 1))
28+
fi
29+
echo "line_count=$LINE_COUNT" >> $GITHUB_OUTPUT
30+
echo "file_exists=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "file_exists=false" >> $GITHUB_OUTPUT
33+
echo "line_count=0" >> $GITHUB_OUTPUT
34+
fi
35+
36+
- name: Generate summary
37+
run: |
38+
echo "## 📊 Line Count Report" >> $GITHUB_STEP_SUMMARY
39+
echo "" >> $GITHUB_STEP_SUMMARY
40+
41+
FILE_EXISTS="${{ steps.line-count.outputs.file_exists }}"
42+
if [ "$FILE_EXISTS" == "true" ]; then
43+
LINE_COUNT="${{ steps.line-count.outputs.line_count }}"
44+
echo "**File:** \`$TARGET_FILE\`" >> $GITHUB_STEP_SUMMARY
45+
echo "" >> $GITHUB_STEP_SUMMARY
46+
echo "**Total Lines:** $LINE_COUNT" >> $GITHUB_STEP_SUMMARY
47+
else
48+
echo "⚠️ **File not found:** \`$TARGET_FILE\`" >> $GITHUB_STEP_SUMMARY
49+
fi
50+
51+
- name: Comment on PR
52+
uses: actions/github-script@v7
53+
with:
54+
script: |
55+
const fileExists = '${{ steps.line-count.outputs.file_exists }}';
56+
const lineCount = '${{ steps.line-count.outputs.line_count }}';
57+
const targetFile = process.env.TARGET_FILE;
58+
59+
let commentBody;
60+
if (fileExists === 'true') {
61+
commentBody = `## 📊 Line Count Report\n\n**File:** \`${targetFile}\`\n\n**Total Lines:** ${lineCount}`;
62+
} else {
63+
commentBody = `## 📊 Line Count Report\n\n⚠️ **File not found:** \`${targetFile}\``;
64+
}
65+
66+
github.rest.issues.createComment({
67+
issue_number: context.issue.number,
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
body: commentBody
71+
});

0 commit comments

Comments
 (0)