Update filePath functionality

Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com>
This commit is contained in:
Shakar 2023-09-19 11:30:24 +03:00
parent 495b125338
commit 2303020aad
No known key found for this signature in database
GPG Key ID: DA55A26823AE3C28

View File

@ -49,8 +49,8 @@ async function run() {
console.log(`Old version: ${version}. New version: ${newVersion}`)
// fs.writeFileSync(file, JSON.stringify(file, null, 2));
await commitChanges(core.getInput('filePath'), file);
const filePathRelatedToRoot = getProjectInfoFilePath(filePathInput, true);
await commitChanges(file, filePathRelatedToRoot);
const payload = JSON.stringify(github.context.payload, undefined, 2)
@ -62,7 +62,7 @@ async function run() {
// Region functions
async function commitChanges(filePath, file) {
async function commitChanges(file, filePath) {
const commitMessage = 'Commit message here';
const newContent = file;
const githubToken = core.getInput('githubToken');
@ -165,16 +165,16 @@ async function commitChanges(filePath, file) {
}
}
function getProjectInfoFilePath(filePath) {
function getProjectInfoFilePath(filePath, relativeToRoot = false) {
if (filePath == null || filePath == undefined || filePath == '') {
// List files inside the root directory of the repository
const files = fs.readdirSync(process.cwd());
// Return the first file that matches .csproj or package.json
const projectInfoFile = files.find(file => file.match(/\.csproj|package\.json/));
return `${process.cwd()}/${projectInfoFile}`;
return relativeToRoot ? projectInfoFile : `${process.cwd()}/${projectInfoFile}`;
}
else
return `${process.cwd()}/${filePath}`;
return relativeToRoot ? filePath : `${process.cwd()}/${filePath}`;
}
function getProjectVersion(filePath) {
const projectInfoFile = require(filePath);