From 277b6a64acac0d310ee2123d7301308c288c3cea Mon Sep 17 00:00:00 2001 From: yashksaini-coder Date: Sun, 15 Sep 2024 14:09:53 +0530 Subject: [PATCH] Fix README.md File read error --- .github/workflows/readme.yml | 2 +- scripts/index.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml index c7359de..c25283f 100644 --- a/.github/workflows/readme.yml +++ b/.github/workflows/readme.yml @@ -32,6 +32,6 @@ jobs: run: | git config --global user.email "actions@github.com" git config --global user.name "GitHub Actions" - git add README.md + git add . git diff --quiet && git diff --staged --quiet || (git commit -m "Update README with table of contents" && git push) working-directory: ${{ github.workspace }} diff --git a/scripts/index.js b/scripts/index.js index df3f2cf..2d8449e 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -1,5 +1,10 @@ import fetch from "node-fetch"; import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); const toc = async () => { // Fetch from the GitHubAPI @@ -45,8 +50,11 @@ const toc = async () => { } solutionsTable += ""; + // Use path.join to create the correct path to README.md + const readmePath = path.join(__dirname, "..", "README.md"); + // Read the existing README content - let readmeContent = fs.readFileSync("README.md", "utf8"); + let readmeContent = fs.readFileSync(readmePath, "utf8"); // Checking whether the solutions table already exists if (readmeContent.includes("")) { @@ -69,7 +77,7 @@ const toc = async () => { } // Write the updated content back to README.md - fs.writeFileSync("README.md", readmeContent); + fs.writeFileSync(readmePath, readmeContent); console.log("README.md has been updated with the solutions table!"); };