Skip to content

Update update_readme.yml #151

Update update_readme.yml

Update update_readme.yml #151

Workflow file for this run

name: Update Readme
on:
push:
branches:
- main
defaults:
run:
shell: bash
jobs:
Update-Contributors:
runs-on: ubuntu-latest
steps:
- name: Aggiornamento contributors
uses: akhilmhdh/contributors-readme-action@v2.3.4
with:
use_username: true
committer_username: "mikyll"
commit_message: "update README.md"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Update-Readme:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
token: ${{ secrets.GH_TOKEN }}
- run: cd ${{ github.workspace }}
- name: Aggiornamento numero domande
run: |
file_domande="Domande.txt"
file_readme="README.md"
# Count questions
questions=0
while IFS='' read -r LINE || [ -n "${LINE}" ]
do
# Question
if [[ -n "$LINE" && ! "$LINE" == @* && ! "$LINE" =~ ^[A-E]\. && ! "$LINE" == [A-E] ]]
then
questions=$(expr $questions + 1)
fi
done < "$file_domande"
# Update README
# Update question shield
sed -i "s/message=[0-9]*/message=$questions/" "$file_readme"
# Update question number
sed -i "s|<span id=\"domande\">[0-9]*<\/span>|<span id=\"domande\">$questions<\/span>|" "$file_readme"
# Update date
date=$(curl -s "https://api.github.com/repos/mikyll/ROQuiz/commits?path=Domande.txt&page=1&per_page=1" | grep -m 1 \"date\" | xargs | cut -f2 -d' ' | cut -f1 -d'T')
sed -i "s|<span id=\"ultima_modifica\">[0-9]*<\/span>|<span id=\"ultima_modifica\">$date<\/span>|" "$file_readme"
# Check if there are changes
if [[ -n $(git status -s) ]]
then
# Commit & Push changes
git add "$file_readme"
git config --global user.email "righi.michele98@gmail.com"
git config --global user.name "mikyll"
git commit -m "Update README.md"
git push https://${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}
echo "✔️ Readme aggiornato!"
else
echo "Nessuna modifica necessaria."
fi