diff --git a/.github/workflows/badge.yml b/.github/workflows/badge.yml new file mode 100644 index 0000000..2aad3c2 --- /dev/null +++ b/.github/workflows/badge.yml @@ -0,0 +1,26 @@ +name: Badges + +on: + push: + branches: + - master + +jobs: + update-badges: + name: Update Badges + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Get the Numbers + run: | + echo "dep_counts=$(./scripts/count-dependencies.sh)" >> $GITHUB_ENV + - name: Create Dependency-Count-Badge + uses: schneegans/dynamic-badges-action@v1.0.0 + with: + auth: ${{ secrets.GIST_SECRET }} + gistID: a2128afe12bf05d85a0d68346236a4f5 + filename: sailfish-dep-counts.json + label: Dependencies + message: ${{ env.dep_counts }} + color: blueviolet diff --git a/README.md b/README.md index ba2929f..befb725 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Simple, small, and extremely fast template engine for Rust [![Tests](https://github.com/Kogia-sima/sailfish/workflows/Tests/badge.svg)](https://github.com/Kogia-sima/sailfish/actions?query=workflow%3ATests) [![Version](https://img.shields.io/crates/v/sailfish)](https://crates.io/crates/sailfish) +![Dependency counts](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/Kogia-sima/a2128afe12bf05d85a0d68346236a4f5/raw/sailfish-dep-counts.json) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Kogia-sima/sailfish/blob/master/LICENSE) [User Guide](https://sailfish.netlify.app/en/) | [API Docs](https://docs.rs/sailfish) | [Examples](./examples) diff --git a/scripts/count-dependencies.sh b/scripts/count-dependencies.sh new file mode 100755 index 0000000..9160404 --- /dev/null +++ b/scripts/count-dependencies.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +IFS=$'\n' +PACKAGES=("sailfish" "sailfish-macros" "sailfish-compiler") + +git-root () { + if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then + cd `git rev-parse --show-toplevel`; + fi +} + +get_dependencies() { + cargo tree -p "$1" | while read line; do + dev_dependencies_re="\[dev-dependencies\]" + crate_re="[a-zA-Z0-9_-]+ v[^ ]+" + + if [[ "$line" =~ $crate_re ]]; then + echo ${BASH_REMATCH[0]} + continue + fi + + if [[ "$line" =~ $dev_dependencies_re ]]; then + break + fi + done +} + +remove_packages() { + local found + + for dep in $@; do + found=0 + for pkg in ${PACKAGES[@]}; do + pat="$pkg v[^ ]" + if [[ "$dep" =~ $pat ]]; then + found=1 + break + fi + done + + if [[ $found == 0 ]]; then + echo $dep + fi + done +} + +# go to root directory +cd `git rev-parse --show-toplevel` + +deps=() + +for pkg in ${PACKAGES[@]}; do + deps+=( `get_dependencies $pkg` ) +done + +deps=( $(printf "%s\n" "${deps[@]}" | sort -u) ) + +remove_packages ${deps[*]} |wc -l