-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
87 lines (83 loc) · 3.03 KB
/
action.yml
File metadata and controls
87 lines (83 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: "LOC Graph Action"
description: "Generate an SVG chart of Lines of Code over time from commit history"
author: "Maxim Oransky"
branding:
icon: 'trending-up'
color: 'green'
inputs:
output_json:
description: "Path to cached LOC history JSON"
default: ".github/loc_history.json"
required: false
theme:
description: "Theme for fallback SVG (light or dark)"
default: "light"
required: false
fallback_theme:
description: "Deprecated: use 'theme' instead"
default: ""
required: false
date_format:
description: "Date format for multi-day projects (Python strftime)"
default: "%d.%m.%Y"
required: false
time_format:
description: "Time format for same-day commits (Python strftime)"
default: "%H:%M"
required: false
exclude:
description: "Additional directories to exclude from counting (comma-separated)"
default: ""
required: false
runs:
using: "composite"
steps:
- name: Check for real commits since last LOC update
id: skip_check
shell: bash
run: |
LAST_LOC=$(git log --all --oneline --grep="Update LOC graph" -1 --format="%H" 2>/dev/null || true)
if [ -n "$LAST_LOC" ]; then
REAL=$(git log "$LAST_LOC"..HEAD --oneline --invert-grep --grep="Update LOC graph" | wc -l | tr -d ' ')
else
REAL=1
fi
echo "real_commits=$REAL" >> "$GITHUB_OUTPUT"
if [ "$REAL" = "0" ]; then
echo "No real commits since last LOC update, skipping"
else
echo "Found $REAL real commit(s), proceeding"
fi
- name: Ensure full git history
if: steps.skip_check.outputs.real_commits != '0'
shell: bash
run: |
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
git fetch --unshallow --tags
fi
- name: Install cloc
if: steps.skip_check.outputs.real_commits != '0'
shell: bash
run: |
sudo apt-get install -y cloc --no-install-recommends
- name: Run LOC graph generator
if: steps.skip_check.outputs.real_commits != '0'
id: loc_graph
shell: bash
run: |
FALLBACK_THEME="${{ inputs.theme || inputs.fallback_theme || 'light' }}" \
DATE_FORMAT="${{ inputs.date_format }}" \
TIME_FORMAT="${{ inputs.time_format }}" \
EXCLUDE="${{ inputs.exclude }}" \
python3 "${GITHUB_ACTION_PATH}/scripts/loc_graph.py" && echo "changed=true" >> $GITHUB_OUTPUT || echo "changed=false" >> $GITHUB_OUTPUT
- name: Commit artifacts if changed
if: steps.skip_check.outputs.real_commits != '0' && steps.loc_graph.outputs.changed == 'true'
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add ".github/loc-history.svg" ".github/loc-history-light.svg" ".github/loc-history-dark.svg" "${{ inputs.output_json }}" || true
if ! git diff --cached --quiet; then
git commit -m "Update LOC graph [skip ci]"
git push
fi