Update update_readme.yml #155
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_questions="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_questions" | |
# Update README | |
# Update question shield | |
sed -i "s/message=[0-9]*/message=$questions/" "$file_readme" | |
# Update question number | |
sed -i "s|<span id=\"domande\">*<\/span>|<span id=\"domande\">$questions<\/span>|" "$file_readme" | |
# Update date | |
date=$(curl -s "https://api.github.com/repos/mikyll/ROQuiz/commits?path=${file_questions}&page=1&per_page=1" | grep -m 1 \"date\" | xargs | cut -f2 -d' ' | cut -f1 -d'T') | |
sed -i "s|<span id=\"ultima_modifica\">*<\/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 | |