Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/scripts/publish_loc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curl -X POST $1 \
-H 'Content-Type: application/json; charset=utf-8' \
--data "$(cat cmd/loc/loc_report_slack.txt)"
65 changes: 65 additions & 0 deletions .github/workflows/daily_loc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Daily Lines of Code Report

on:
schedule:
# Every day at UTC midnight
- cron: "0 0 * * 1,2,3,4,5"
workflow_dispatch:

jobs:
loc:
name: Count ethrex loc and generate report
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@stable

- name: Add Rust Cache
uses: Swatinem/rust-cache@v2

- name: Restore cache
id: cache-loc-report
uses: actions/cache@v4
with:
path: cmd/loc/loc_report.json
key: loc-report-${{ github.ref_name }}
restore-keys: |
loc-report-

- name: Rename cached loc_report.json to loc_report.json.old
if: steps.cache-loc-report.outputs.cache-hit != ''
run: mv cmd/loc/loc_report.json cmd/loc/loc_report.json.old

- name: Generate the loc report
run: |
cd cmd/loc && make loc

- name: Save new loc_report.json to cache
if: success()
uses: actions/cache@v4
with:
path: cmd/loc/loc_report.json
key: loc-report-${{ github.ref_name }}

- name: Post results in summary
run: |
echo "# 'concrete' lines of code report" >> $GITHUB_STEP_SUMMARY
cat cmd/loc/loc_report_github.txt >> $GITHUB_STEP_SUMMARY

- name: Post results to Slack
env:
SLACK_WEBHOOKS: >
${{ github.event_name == 'workflow_dispatch'
&& secrets.TEST_CHANNEL_SLACK
|| format(
'{0}',
secrets.CONCRETE_SLACK_WEBHOOK
)
}}
run: |
for webhook in $SLACK_WEBHOOKS; do
sh .github/scripts/publish_loc.sh "$webhook"
done
79 changes: 79 additions & 0 deletions .github/workflows/pr_loc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: PR Lines of Code Analysis

on:
pull_request:
branches: ["**"]

permissions:
pull-requests: write

jobs:
report-loc-changes:
name: Report PR Line Changes
runs-on: ubuntu-latest
# Skip the job if the PR is from a fork since it doesn't have permissions to post comments
if: github.event.pull_request.head.repo.fork == false
steps:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2

- name: Checkout Base
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}

- name: Run Lines of Code Counter for base
run: cd cmd/loc && make loc-detailed
# This creates current_detailed_loc_report.json for the base branch

- name: Rename base report to previous_detailed_loc_report.json
run: mv cmd/loc/current_detailed_loc_report.json cmd/loc/previous_detailed_loc_report.json

- name: Checkout PR
uses: actions/checkout@v4
with:
clean: "false" # Don't clean the workspace, so we can keep the previous report
ref: ${{ github.event.pull_request.head.sha }}

- name: Run Lines of Code Counter for PR
run: cd cmd/loc && make loc-detailed
# This creates current_detailed_loc_report.json

- name: Compare Detailed Lines of Code Count
run: cd cmd/loc && make loc-compare-detailed
# This reads current_detailed_loc_report.json and previous_detailed_loc_report.json
# and outputs detailed_loc_report.txt

- name: Check if report exists
id: check_report
run: |
if [ -s cmd/loc/detailed_loc_report.txt ]; then
echo "report_exists=true" >> $GITHUB_OUTPUT
else
echo "report_exists=false" >> $GITHUB_OUTPUT
fi

- name: Find comment
if: steps.check_report.outputs.report_exists == 'true'
continue-on-error: true
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "Total lines changed"

- name: Create Comment
if: steps.check_report.outputs.report_exists == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body-path: cmd/loc/detailed_loc_report.txt
edit-mode: replace
3 changes: 3 additions & 0 deletions cmd/loc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
*.txt
*.json
Loading
Loading