# Based on: https://github.com/emibcn/badge-action/blob/master/.github/workflows/test.yml name: "Generate node comparison badge" on: push: paths: - "src/games/definitions.rs" - ".github/workflows/node-badge.yml" schedule: - cron: '0 0 * * 1' # Update once a week in case node-gamedig has changed workflow_dispatch: jobs: badge: runs-on: "ubuntu-latest" name: Create node comparison badge env: BADGE_PATH: ".github/badges/node.svg" steps: - name: Extract branch name shell: bash run: echo "branch=${GITHUB_REF#refs/heads/}" >> "${GITHUB_OUTPUT}" id: extract_branch - uses: actions/checkout@v4 - uses: actions/checkout@v4 with: repository: "gamedig/node-gamedig" sparse-checkout: "games.txt" path: "node-gamedig" - name: Calculate comparison id: comparison run: | # Find list of node games node_games=$(awk -F "|" '/^[^#]/ {if(length($1) > 0) print $1 }' ./node-gamedig/games.txt) node_games_count=$(printf "%s\n" "$node_games" | wc -l) # Calculate how many of those games we have definitions for rust_games_count=0 for game in $node_games; do if grep "\"$game\" *=>" ./src/games/definitions.rs; then rust_games_count=$(( rust_games_count + 1 )) fi done # Calculate percent percent=$(( rust_games_count * 100 / node_games_count)) echo "$rust_games_count/$node_games_count $percent%" # Output percentage echo "percent=$percent" >> "${GITHUB_OUTPUT}" - name: Generate the badge SVG image uses: emibcn/badge-action@v2.0.2 id: badge with: label: "Node game coverage" status: "${{ steps.comparison.outputs.percent }}%" color: "0f80c1" path: ${{ env.BADGE_PATH }} - name: "Commit badge" continue-on-error: true run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add "${BADGE_PATH}" git commit -m "Add/Update badge" - name: Push badge commit uses: ad-m/github-push-action@master if: ${{ success() }} with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: ${{ steps.extract_branch.outputs.branch }}