Files
hassio-addons/.github/workflows/weekly_stats.yaml
Alexandre bb1d0c6b66 ci: pin EndBug/add-and-commit to v11.0.0, the floating v11 tag is broken (#2996)
Every push to master has failed to build since 2026-08-19 05:15. The
prebuild-sanitize job dies before running a single step:

    EndBug/add-and-commit/v11/action.yml (Line: 25, Col: 18):
    Unrecognized named-value: 'github'. Located at position 1 within
    expression: github.workspace
    Failed to load EndBug/add-and-commit/v11/action.yml

Upstream's v11.1.0, published 2026-08-18 22:44 UTC, put a literal
"${{ github.workspace }}" inside the description of the `cwd` input. Action
metadata descriptions are still parsed as expressions and the `github` context
does not exist there, so the action no longer loads at all. The floating v11
tag was moved to it, which is why nothing changed in this repo and every
workflow using the action broke at once - the builder, the README and stats
refreshers, the CRLF sweep, the image compressor and the issue labeller.

v11.0.0 does not contain that line and loads normally, so pinning to it keeps
the version Dependabot moved us to in #2985 while stepping off the tag. It also
took out an unrelated add-on fix: the builder's revert-on-failure job reverted
the seerr merge (#2993) as collateral, and that is being reapplied separately.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 07:29:52 +02:00

119 lines
5.3 KiB
YAML

# yamllint disable rule:line-length
---
name: Generate weekly stats
on:
schedule:
- cron: "0 12 * * 5"
workflow_dispatch:
jobs:
stats_updater:
if: github.repository_owner == 'alexbelgium'
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v7.0.1
- name: Create stats
run: |
echo "Starting"
COUNT=0
COUNT1=0
COUNT2=0
# Make sure file exists
file=Stats
touch "$file"
rm "$file"2
if ! grep -q "Date" "$file"; then
sed -i "1i Date" "$file"
fi
# Add new column
sed -i 's/^/- /' "$file"
# Add date
sed -i "/Date/s|^-|$(date '+%Y-%m-%d')|" "$file"
# Go through all folders, add to filters if not existing
# shellcheck disable=SC2086
for f in $( find -- * -maxdepth 0 -type d | sort -r ); do
DOWNLOADS=0
COUNT1="-"
COUNT2="-"
IMAGE=""
ARCHES=""
if [ -f "$f"/config.json ] && jq -e '.image' "$f/config.json" >/dev/null; then
IMAGE="$(jq -r '.image' "$f/config.json")"
ARCHES="$(jq -r '.arch[]?' "$f/config.json")"
elif [ -f "$f/config.yaml" ]; then
IMAGE="$(ruby -ryaml -e 'conf = YAML.load_file(ARGV[0]) rescue nil; img = conf && conf["image"]; exit 1 if img.nil? || img.to_s.empty?; puts img' "$f/config.yaml" 2>/dev/null || true)"
if [ -n "$IMAGE" ]; then
ARCHES="$(ruby -ryaml -e 'conf = YAML.load_file(ARGV[0]) rescue nil; Array(conf && conf["arch"]).compact.each { |a| puts a }' "$f/config.yaml" 2>/dev/null || true)"
fi
fi
if [ -n "$IMAGE" ]; then
SLUG="$(printf '%s\n' "$IMAGE" | awk -F 'alexbelgium/|-{arch' '{print $2}')"
else
SLUG=""
fi
if [ -n "$SLUG" ]; then
if printf '%s\n' "$ARCHES" | grep -qx 'amd64'; then
ARCH=amd64 && COUNT="$(curl --connect-timeout 5 -f -s -L https://github.com/alexbelgium/hassio-addons/pkgs/container/$SLUG-$ARCH/latest | awk '/Total downloads/{getline; print}' | awk -F '<|>' '{print $3}')"
until [ -n "$COUNT" ]; do COUNT="$(curl --connect-timeout 5 -f -s -L https://github.com/alexbelgium/hassio-addons/pkgs/container/$SLUG-$ARCH/latest | awk '/Total downloads/{getline; print}' | awk -F '<|>' '{print $3}')" && sleep 5; ((c++)) && echo "repeat $c" && if [[ "$c" == 10 ]]; then COUNT=0; fi; done
COUNT="${COUNT//,/}"
COUNT1="$COUNT"
echo "$COUNT $ARCH users with $SLUG" && DOWNLOADS="$(( DOWNLOADS + COUNT))"
else COUNT1="-"; fi
if printf '%s\n' "$ARCHES" | grep -qx 'aarch64'; then
ARCH=aarch64 && COUNT="$(curl --connect-timeout 5 -f -s -L https://github.com/alexbelgium/hassio-addons/pkgs/container/$SLUG-$ARCH/latest | awk '/Total downloads/{getline; print}' | awk -F '<|>' '{print $3}')"
until [ -n "$COUNT" ]; do COUNT="$(curl --connect-timeout 5 -f -s -L https://github.com/alexbelgium/hassio-addons/pkgs/container/$SLUG-$ARCH/latest | awk '/Total downloads/{getline; print}' | awk -F '<|>' '{print $3}')" && sleep 5; ((c++)) && echo "repeat $c" && if [[ "$c" == 10 ]]; then COUNT=0; fi; done
COUNT="${COUNT//,/}"
COUNT2="$COUNT"
echo "$COUNT $ARCH users with $SLUG" && DOWNLOADS="$(( DOWNLOADS + COUNT))"
else COUNT2="-";fi
echo "$SLUG $DOWNLOADS $COUNT1 $COUNT2" >> "$file"2
# Create line if not existing
if ! grep -q "${SLUG}$" "$file"; then
sed -i "\$a$SLUG" "$file"
# shellcheck disable=SC2046
for i in $(seq $(head -n 1 $file | tr -cd ' \t' | wc -c )); do
echo "$i"
sed -i "/$SLUG/s|^|- |" "$file"
done
fi
# Add data
sed -i "/${SLUG}$/s|^-|$DOWNLOADS|" "$file"
else
continue
fi
done
# Add total
SLUG=TOTAL
if ! grep -q "$SLUG$" "$file"; then
sed -i "1a$SLUG" "$file"
# shellcheck disable=SC2046
for i in $(seq $(head -n 1 $file | tr -cd ' \t' | wc -c )); do
echo "$i"
sed -i "/$SLUG$/s|^|- |" "$file"
done
fi
DOWNLOADS="$(awk 'FNR > 2 {SUM+=$1}END{print SUM}' Stats)"
sed -i "/$SLUG$/s|^-|$DOWNLOADS|" "$file"
# Sort file
(head -n 2 "$file" && tail -n +3 "$file" | sort -k1 -r -n) > tmp && mv tmp "$file"
sed -i "1i Name Total amd64 aarch64" "$file"2
sed -i "1a ------------------------------" "$file"2
#TOTAL="$(awk '{SUM+=$2}END{print SUM}' Stats)"
#TOTAL1="$(awk '{SUM+=$2}END{print SUM}' Stats)"
#TOTAL2="$(awk '{SUM+=$2}END{print SUM}' Stats)"
#TOTAL3="$(awk '{SUM+=$2}END{print SUM}' Stats)"
- name: Commit if needed
uses: EndBug/add-and-commit@v11.0.0
with:
default_author: github_actions
message : "Github bot : stats updated"
Generate_graphs:
needs: stats_updater
uses: ./.github/workflows/helper_stats_graphs.yaml