From 369c1225713b2cbc1e2397485ec55c01206b7437 Mon Sep 17 00:00:00 2001 From: vilaca Date: Sun, 7 Apr 2024 01:34:00 +0100 Subject: [PATCH] chart --- .github/workflows/fetch.yaml | 12 ++++++++ scripts/diffs.sh | 54 ++++++++++++++++++++++++++++++++++++ scripts/utils/yesterday.sh | 5 ++++ 3 files changed, 71 insertions(+) create mode 100755 scripts/diffs.sh create mode 100755 scripts/utils/yesterday.sh diff --git a/.github/workflows/fetch.yaml b/.github/workflows/fetch.yaml index 4de3e7b..bf1dd9d 100644 --- a/.github/workflows/fetch.yaml +++ b/.github/workflows/fetch.yaml @@ -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/})" diff --git a/scripts/diffs.sh b/scripts/diffs.sh new file mode 100755 index 0000000..a141e52 --- /dev/null +++ b/scripts/diffs.sh @@ -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 "Compiled using https://github.com/vilaca/awesome-k8s-tools" + +printf '
\n\n' + +echo "|Current|Previous|Repository|Stars|" +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)
$desc|$total (+$star)|" +done < "today-nr" + +printf '\n\n
\n\n' + +echo "This chart estimates the 30 most popular open-source DevOps tools by tallying the GitHub stars each repository received in the last seven days." + diff --git a/scripts/utils/yesterday.sh b/scripts/utils/yesterday.sh new file mode 100755 index 0000000..c926d71 --- /dev/null +++ b/scripts/utils/yesterday.sh @@ -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 \ No newline at end of file