From bac3ca6765a8c55de02eb1fe4f2c412761af2e91 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Wed, 4 Oct 2023 13:52:26 +0300 Subject: [PATCH] Update index Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ac891b7..1c906e4 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ async function run() { // join the parts back together const newVersion = versionParts.join('.'); - updateProjectVersion(filePath, newVersion); + file = updateProjectVersion(filePath, newVersion); console.log(`Old version: ${version}. New version: ${newVersion}`) @@ -100,7 +100,7 @@ async function commitChanges(file, filePath) { const blobResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/blobs`, { - content: file, + content: newContent, encoding: 'utf-8', }, { @@ -205,13 +205,17 @@ function getProjectVersion(filePath) { } function updateProjectVersion(filePath, newVersion) { - const projectInfoFile = require(filePath); + const projectInfoFile = getFile(filePath); // Update the version if the file is .csproj if (filePath.match(/\.csproj/)) projectInfoFile.Project.PropertyGroup[0].Version = newVersion; - else if (filePath.match(/package\.json/)) + else if (filePath.match(/package\.json/)) { + projectInfoFile = JSON.parse(projectInfoFile) projectInfoFile.version = newVersion; + } + + return projectInfoFile; } function getFile(filePath) {