From 9dcf2f07ad8fe73d695283a54dee990712d690cb Mon Sep 17 00:00:00 2001 From: Md Mijanur Rahman Date: Sat, 16 Mar 2024 21:18:09 +0100 Subject: [PATCH] Update workflow to use latest version of actions/checkout and improve content extraction --- .github/workflows/update_readme.yml | 30 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/update_readme.yml b/.github/workflows/update_readme.yml index 6b308979..759cd491 100644 --- a/.github/workflows/update_readme.yml +++ b/.github/workflows/update_readme.yml @@ -9,27 +9,29 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Update to the latest version - name: Extract content from best_runs.md + id: extract_best_runs # Add an 'id' for later referencing run: | - sed -n '//, //p' results/best_runs.md > extracted_content.md - - - name: Read README.md - id: readme_content - run: | - echo "::set-output name=content::$(cat README.md)" + sed -n '//, //p' results/best_runs.md > extracted_content.md - name: Update README run: | - # Read existing content from README.md - existing_content="${{ steps.readme_content.outputs.content }}" - # Read new content from extracted_content.md new_content="$(cat extracted_content.md)" - # Replace existing content between markers with new content - updated_content="${existing_content/*/\\${new_content}\\}" + # Update content only if there were changes + if [[ -n "${new_content}" ]]; then + # Replace existing section with new content + sed -i '//,//c\\n'"${new_content}"'\n' README.md - # Write updated content back to README.md - echo "${updated_content}" > README.md + # Commit changes to README.md + git config user.name "GitHub Actions Bot" + git config user.email "github-actions-bot@users.noreply.github.com" + git add README.md + git commit -m "Automatic update: Best runs section" + git push + else + echo "No changes in best_runs.md; update skipped" + fi \ No newline at end of file