Skip to content

Add a badge to dynamically update no. of papers in README #2

Add a badge to dynamically update no. of papers in README

Add a badge to dynamically update no. of papers in README #2

Workflow file for this run

name: Count papers in README
on:
push:
branches:
- master # or your default branch name
jobs:
count-items:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Count papers in README
run: |
ITEM_COUNT=$(grep -oP '^\s*-\s*\*\*[^*]+\*\*\([0-9]+-[0-9]+\),\s*[^[]+\[\[pdf\]\]\([^)]+\)' README.md | wc -l)
echo "ITEM_COUNT=$ITEM_COUNT" >> $GITHUB_ENV
- name: Update badge
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const shieldsUrl = `https://img.shields.io/badge/Items-${process.env.ITEM_COUNT}-blue`;
const regex = /!\[Items count\]\([^\)]+\)/g;
const replacement = `![Items count](${shieldsUrl})`;
const readmePath = './README.md';
const readme = fs.readFileSync(readmePath, 'utf8');
const updatedReadme = readme.replace(regex, replacement);
fs.writeFileSync(readmePath, updatedReadme);
github-token: ${{ secrets.GITHUB_TOKEN }}