From 749d15bca054c28e2ec1fb415e819f5c80d34ddc Mon Sep 17 00:00:00 2001 From: SKPG-Tech <42890752+SKPG-Tech@users.noreply.github.com> Date: Sat, 30 Sep 2023 22:18:05 +0300 Subject: [PATCH] Make README regen only commit when needed --- .github/workflows/readme_check.py | 12 ++++++++++++ .github/workflows/readme_regen.yml | 4 ++++ README.md | 2 +- generate_readme.py | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/readme_check.py diff --git a/.github/workflows/readme_check.py b/.github/workflows/readme_check.py new file mode 100644 index 0000000..ab7e871 --- /dev/null +++ b/.github/workflows/readme_check.py @@ -0,0 +1,12 @@ +import sys +import os + +path = sys.argv[1] + +os.chdir(path) +diff = os.popen('git diff').readlines() + +if not diff[10].startswith('+> Report generated on') and not diff[8].startswith('-> Report generated on'): + print('true') +else: + print('false') diff --git a/.github/workflows/readme_regen.yml b/.github/workflows/readme_regen.yml index 4700dae..93b7511 100644 --- a/.github/workflows/readme_regen.yml +++ b/.github/workflows/readme_regen.yml @@ -24,7 +24,11 @@ jobs: - name: Generate new README.md run: python ${{ github.workspace }}/generate_readme.py + - name: Check if commit is needed + run: echo "COMMIT_NEEDED=$(python ${{ github.workspace }}/.github/workflows/readme_check.py ${{ github.workspace }})" >> $GITHUB_ENV + - name: Commit changes + if: ${{ env.COMMIT_NEEDED == 'true' }} run: | git config --global user.name "github-actions[bot]" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" diff --git a/README.md b/README.md index 813204e..2697aa8 100644 --- a/README.md +++ b/README.md @@ -47,4 +47,4 @@ the feasibility. * 🇷🇺 [Russian](/translations/rus.po) (100% complete! 🎉) * 🇬🇪 [Georgian](/translations/kat.po) (100% complete! 🎉) * 💻 [Code](/translations/code.po) (100% complete! 🎉) -> Report generated on Sep 30 2023 14:19:30 UTC \ No newline at end of file +> Report generated on Sep 30 2023 19:15:58 UTC \ No newline at end of file diff --git a/generate_readme.py b/generate_readme.py index 907811d..81b7236 100755 --- a/generate_readme.py +++ b/generate_readme.py @@ -69,7 +69,7 @@ # Write the README readme_file = "README.md" -with open(readme_file, 'w', encoding="utf8", newline='\n') as f: +with open(readme_file, 'w', encoding="utf8", newline='\r\n') as f: f.write(header) results = []