Skip to content

feat: loc report #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: feat/db
Choose a base branch
from
Draft
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/public_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 tooling/loc/loc_report_slack.txt)"
59 changes: 59 additions & 0 deletions .github/workflows/daily_loc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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 db loc and generate report
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.87.0
components: rustfmt, clippy

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

- name: Restore cache
id: cache-loc-report
uses: actions/cache@v4
with:
path: tooling/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 tooling/loc_report.json tooling/loc_report.json.old

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

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

- name: Post results in summary
run: |
echo "# EthrexDB Lines of Code Report" >> $GITHUB_STEP_SUMMARY
cat tooling/loc_report_github.txt >> $GITHUB_STEP_SUMMARY

- name: Post results to Slack
if: always()
run: |
if [ -n "${{ secrets.SLACK_WEBHOOK }}" ]; then
sh .github/scripts/publish_loc.sh "${{ secrets.SLACK_WEBHOOK }}"
fi
106 changes: 106 additions & 0 deletions .github/workflows/pr_loc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
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: Checkout PR Code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Find merge base
id: find_merge_base
env:
HEAD_REF: ${{ github.event.pull_request.head.ref }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
git fetch --depth=100000 origin $HEAD_REF
git fetch --depth=100000 origin $BASE_REF
MERGE_BASE=$(git merge-base origin/$HEAD_REF origin/$BASE_REF)
echo "merge_base=$MERGE_BASE" >> $GITHUB_OUTPUT

- name: Checkout merge base commit
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.find_merge_base.outputs.merge_base }}

- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.87.0
components: rustfmt, clippy

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

- name: Run Lines of Code Counter for base
run: cd tooling && 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 tooling/current_detailed_loc_report.json tooling/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: Rustup toolchain install
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.87.0
components: rustfmt, clippy

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

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

- name: Compare Detailed Lines of Code Count
run: cd tooling && 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 tooling/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: tooling/detailed_loc_report.txt
edit-mode: replace
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ target/

# Samply json
profile.json.gz

# LOC tooling generated files
tooling/loc_detailed_report.json
tooling/loc_report_github.txt
tooling/loc_report.json
tooling/slack_message.json
tooling/current_detailed_loc_report.json
tooling/previous_detailed_loc_report.json
tooling/detailed_loc_report.txt
tooling/loc_report_slack.txt
Loading
Loading