mirror of
https://github.com/ditkrg/project-version-check.git
synced 2026-01-22 22:06:42 +00:00
Update index js
Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com>
This commit is contained in:
parent
d4671282db
commit
0f412948e4
12
index.js
12
index.js
@ -2,6 +2,7 @@ const core = require('@actions/core')
|
||||
const github = require('@actions/github')
|
||||
const fs = require('fs')
|
||||
const axios = require('axios');
|
||||
import convert from 'xml-js';
|
||||
|
||||
run();
|
||||
async function run() {
|
||||
@ -182,10 +183,13 @@ function getProjectInfoFilePath(filePath, relativeToRoot = false) {
|
||||
function getProjectVersion(filePath) {
|
||||
const projectInfoFile = require(filePath);
|
||||
|
||||
// Update the version if the file is .csproj
|
||||
if (filePath.match(/\.csproj/))
|
||||
return projectInfoFile.Project.PropertyGroup[0].Version;
|
||||
else if (filePath.match(/package\.json/))
|
||||
if (filePath.match(/\.csproj/)) {
|
||||
|
||||
const convertedToJson = convert.xml2js(projectInfoFile);
|
||||
// elements[0] -> PropertyGroup -> Version (object) -> text (e.g. 1.2.3)
|
||||
return convertedToJson.elements[0].elements.find(el => el.name == 'PropertyGroup').elements.find(el => el.name == 'Version').elements.find(el => el.type == 'text').text;
|
||||
|
||||
} else if (filePath.match(/package\.json/))
|
||||
return projectInfoFile.version;
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user