# yamllint disable rule:line-length --- name: Generate weekly stats on: schedule: - cron: "0 0 * * 0" workflow_dispatch: null jobs: stats_updater: runs-on: ubuntu-20.04 steps: - name: Checkout Repo uses: actions/checkout@v3 - name: Create stats run: | echo "Starting" COUNT=0 COUNT1=0 COUNT2=0 COUNT3=0 # Make sure file exists touch Stats if ! grep -q "Date" Stats; then sed -i "1i Date" Stats fi # Add new column sed -i 's/^/- /' a # Add date sed -i "/Date/s|^-|$(date '+%Y-%m-%d')|" a # 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 if [ -f "$f"/config.json ]; then SLUG="$(jq -r '.image' "$f/config.json" | awk -F 'alexbelgium/|-{arch' '{print $2}')" if [[ "$(jq '.arch[]' "$f/config.json")" == *"armv7"* ]]; then ARCH=armv7 && COUNT="$(curl -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 -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; done COUNT1="$COUNT" echo "$COUNT $ARCH users with $SLUG" && DOWNLOADS="$(( DOWNLOADS + COUNT))" else COUNT1="-"; fi if [[ "$(jq '.arch[]' "$f/config.json")" == *"amd64"* ]]; then ARCH=amd64 && COUNT="$(curl -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 -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; done COUNT2="$COUNT" echo "$COUNT $ARCH users with $SLUG" && DOWNLOADS="$(( DOWNLOADS + COUNT))" else COUNT2="-"; fi if [[ "$(jq '.arch[]' "$f/config.json")" == *"aarch64"* ]]; then ARCH=aarch64 && COUNT="$(curl -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 -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; done COUNT3="$COUNT" echo "$COUNT $ARCH users with $SLUG" && DOWNLOADS="$(( DOWNLOADS + COUNT))" else COUNT3="-";fi echo "$SLUG $DOWNLOADS $COUNT1 $COUNT2 $COUNT3" >> Stats # Create line if not existing if ! grep -q "$SLUG" Stats; then sed -ie "\$a$SLUG" Stats for i in $(seq $(head -n 1 Stats | tr -cd ' \t' | wc -c )); do sed -i "/$slug/s|^|- |" Stats done fi # Add data sed -i "/$SLUG/s|^-|$DOWNLOADS|" a fi done # Make stats sort -k1 -r -n Stats > tmp && mv tmp Stats #sed -i "1i Name Total armv7 amd64 aarch64" Stats #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)" # Make plot #apt-get install gnuplot -y #https://www.xmodulo.com/draw-stacked-histogram-gnuplot.html - name: Commit if needed uses: EndBug/add-and-commit@v9 with: message: "GitHub bot : README updated" default_author: github_actions