Skip to content

Commit

Permalink
chart
Browse files Browse the repository at this point in the history
  • Loading branch information
vilaca committed Apr 7, 2024
1 parent 4550a13 commit 369c122
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/fetch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ jobs:
sort -nr score-output > data/"$today"-score
rm score-output
- name: Chart
env:
PAT: ${{ secrets.PAT }}
shell: bash
run: |
today=$(./scripts/utils/today.sh)
yesterday=$(./scripts/utils/yesterday.sh)
echo $today
echo $yesterday
./scripts/diffs.sh $today $yesterday > README.md
rm today today-nr yesterday yesterday-nr
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
Expand Down
54 changes: 54 additions & 0 deletions scripts/diffs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cat data/$1-score | sort -rn | head -30 | cut -d' ' -f2 > today
cat data/$2-score | sort -rn | head -30 | cut -d' ' -f2 > yesterday

cat -n today > today-nr
cat -n yesterday > yesterday-nr

declare -A yesterday
declare -A diffs
declare -A stars

# store yesterday position in memory
while IFS="" read -r line || [ -n "$line" ]
do
read -r position name <<< "$line"
yesterday["$name"]=$position
done < "yesterday-nr"

# read differences
while IFS="" read -r line || [ -n "$line" ]
do
read -r stars name <<< "$line"
diffs["$name"]=$stars
done < "data/$1-score"

# read totals
while IFS="" read -r line || [ -n "$line" ]
do
read -r total name <<< "$line"
stars["$name"]=$total
done < "data/$1"

echo "# Devops OSS Tools Top 30 Chart"
echo "<sup>Compiled using https://github.com/vilaca/awesome-k8s-tools</sup>"

printf '<div align="center">\n\n'

echo "|<sub>Current</sub>|<sub>Previous</sub>|<sub>Repository</sub>|<sub>Stars</sub>|"
echo "|:---:|:---:|:---|:---:|"
#draw chart
while IFS="" read -r line || [ -n "$line" ]
do
read -r position name <<< "$line"
last=${yesterday["$name"]}
star=${diffs["$name"]}
total=${stars["$name"]}
desc="$(curl -s "https://api.github.com/repos/$name" --header "Authorization: Bearer $PAT" | jq -r .description)"

echo "|$position|${last:--}|[**$name**](https://github.com/$name)<br/>$desc|$total <sup>(+$star)</sup>|"
done < "today-nr"

printf '\n\n</div>\n\n'

echo "<sub>This chart estimates the 30 most popular open-source DevOps tools by tallying the GitHub stars each repository received in the last seven days.</sub>"

5 changes: 5 additions & 0 deletions scripts/utils/yesterday.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
current_date=$(date +%s)
yesterday=$((1 * 24 * 60 * 60))
yesterday_ago=$((current_date - yesterday))
yesterday_ago_date=$(date -d "@$yesterday_ago" +%d-%m-%Y)
echo $yesterday_ago_date

0 comments on commit 369c122

Please sign in to comment.