Update workflows
This commit is contained in:
parent
17321aa580
commit
4d337197fc
3 changed files with 122 additions and 11 deletions
82
.github/clocgen.py
vendored
Normal file
82
.github/clocgen.py
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
import matplotlib.pyplot as plt
|
||||
from matplotlib.lines import Line2D
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
def best_fit(X, Y):
|
||||
|
||||
xbar = sum(X)/len(X)
|
||||
ybar = sum(Y)/len(Y)
|
||||
n = len(X) # or len(Y)
|
||||
|
||||
numer = sum([xi*yi for xi,yi in zip(X, Y)]) - n * xbar * ybar
|
||||
denum = sum([xi**2 for xi in X]) - n * xbar**2
|
||||
|
||||
b = numer / denum
|
||||
a = ybar - b * xbar
|
||||
|
||||
return a, b
|
||||
|
||||
with open(sys.argv[1], errors="ignore") as f:
|
||||
cloc_results = json.loads(f.read())
|
||||
|
||||
python_by_day = {}
|
||||
go_by_day = {}
|
||||
|
||||
for file in cloc_results["files"]:
|
||||
if file["language"].lower() == "python":
|
||||
target_dict = python_by_day
|
||||
elif file["language"].lower() == "go":
|
||||
target_dict = go_by_day
|
||||
else:
|
||||
continue
|
||||
|
||||
split_name = file["name"].split(os.path.sep)
|
||||
if split_name[-1].lower() not in ["__main__.py", "main.go"]:
|
||||
try:
|
||||
day_num = int(split_name[0].split("-")[0])
|
||||
except ValueError:
|
||||
continue
|
||||
if day_num not in target_dict:
|
||||
target_dict[day_num] = file["code"]
|
||||
else:
|
||||
target_dict[day_num] += file["code"]
|
||||
|
||||
print(python_by_day)
|
||||
print(go_by_day)
|
||||
|
||||
days_array = [i + 1 for i in range(max(len(python_by_day), len(go_by_day)))]
|
||||
|
||||
# Add Python
|
||||
python_colour = "#3572a5"
|
||||
|
||||
keys = list(sorted(python_by_day))
|
||||
plt.plot(keys, [python_by_day[key] for key in keys], color=python_colour)
|
||||
|
||||
a, b = best_fit(keys, [python_by_day[key] for key in keys])
|
||||
yfit = [a + b * xi for xi in days_array]
|
||||
plt.plot(days_array, yfit, color=python_colour, linestyle=":")
|
||||
|
||||
# Add Go
|
||||
golang_colour = "#00add8"
|
||||
|
||||
keys = list(sorted(go_by_day))
|
||||
plt.plot(keys, [go_by_day[key] for key in keys], color=golang_colour)
|
||||
|
||||
a, b = best_fit(keys, [go_by_day[key] for key in keys])
|
||||
yfit = [a + b * xi for xi in days_array]
|
||||
plt.plot(days_array, yfit, color=golang_colour, linestyle=":")
|
||||
|
||||
custom_lines = [Line2D([0], [0], color=python_colour, lw=2),
|
||||
Line2D([0], [0], color=golang_colour, lw=2)]
|
||||
|
||||
plt.legend(custom_lines, ["Python", "Golang"])
|
||||
|
||||
plt.title("Lines of code by day")
|
||||
|
||||
plt.xticks(days_array)
|
||||
plt.xlabel("Day")
|
||||
plt.ylabel("Lines of code")
|
||||
|
||||
plt.savefig(sys.argv[2])
|
5
.github/tablegen.py
vendored
5
.github/tablegen.py
vendored
|
@ -1,9 +1,10 @@
|
|||
from datetime import datetime
|
||||
import re
|
||||
import sys
|
||||
|
||||
today_day = datetime.now().day
|
||||
|
||||
readme_text = open(".github/README.md").read().strip().split("\n")
|
||||
readme_text = open(sys.argv[1]).read().strip().split("\n")
|
||||
|
||||
start_flag = "<!-- PARSE START -->"
|
||||
end_flag = "<!-- PARSE END -->"
|
||||
|
@ -38,4 +39,4 @@ for i, line in enumerate(readme_text):
|
|||
elif line == start_flag:
|
||||
in_table = True
|
||||
|
||||
open(".github/README.md", "w").write("\n".join(readme_text))
|
||||
open(sys.argv[1], "w").write("\n".join(readme_text))
|
||||
|
|
46
.github/workflows/updatetable.yml
vendored
46
.github/workflows/updatetable.yml
vendored
|
@ -6,7 +6,7 @@ on:
|
|||
- cron: "1 5 * 12 *"
|
||||
|
||||
jobs:
|
||||
run:
|
||||
table:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
|
@ -21,7 +21,7 @@ jobs:
|
|||
python-version: '3.x'
|
||||
|
||||
- name: Run script
|
||||
run: python .github/tablegen.py
|
||||
run: python .github/tablegen.py .github/README.md
|
||||
|
||||
- name: Prettify markdown
|
||||
uses: creyD/prettier_action@v3.1
|
||||
|
@ -30,10 +30,38 @@ jobs:
|
|||
# dry: True
|
||||
commit_message: "Update table"
|
||||
|
||||
#- name: Git commit and push
|
||||
# run: |
|
||||
# git config user.email 'actions@github.com'
|
||||
# git config user.name 'github-actions'
|
||||
# git add .github/README.md
|
||||
# git commit -m 'Update table'
|
||||
# git push origin HEAD:${{ github.ref }}
|
||||
graph:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Login GitHub Registry
|
||||
run: docker login docker.pkg.github.com -u owner -p ${{ secrets.GH_TKN }}
|
||||
|
||||
- name: Run gocloc
|
||||
run: docker run --rm -v "${PWD}":/workdir docker.pkg.github.com/hhatto/gocloc/gocloc:latest --by-file --output-type=json --not-match-d="(template|.github|.vscode)" --exclude-ext=txt . > cloc.json
|
||||
|
||||
- run: cat cloc.json
|
||||
|
||||
- name: Install Matplotlib
|
||||
run: pip install matplotlib
|
||||
|
||||
- name: Run script
|
||||
run: python .github/clocgen.py cloc.json .github/clocgraph.png
|
||||
|
||||
- name: Git commit and push
|
||||
run: |
|
||||
git config user.email 'actions@github.com'
|
||||
git config user.name 'github-actions'
|
||||
git add .github/clocgraph.png
|
||||
git commit -m 'Update CLOC graph'
|
||||
git push origin HEAD:${{ github.ref }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue