Skip to content

Commit

Permalink
Merge pull request #136 from kzrnm/feature/condition
Browse files Browse the repository at this point in the history
Use no `Condition` tag
  • Loading branch information
kzrnm authored Jan 2, 2025
2 parents 7f2e78e + 3a1374a commit f38c4b4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
9 changes: 9 additions & 0 deletions __tests__/testdata/version_prefix_suffix_condition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>

<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition="'$(Beta)' != 'true'">beta.1</VersionSuffix>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-action",
"version": "2.0.0",
"version": "3.0.0",
"private": true,
"description": "get .NET SDK version project from csproj/vbproj.",
"main": "lib/main.js",
Expand All @@ -26,7 +26,7 @@
"author": "kzrnm",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/core": "^1.11.1",
"@xmldom/xmldom": "^0.8.6"
},
"devDependencies": {
Expand Down
27 changes: 17 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ class DocumentWrapper {
constructor(docElement: HTMLElement) {
this.docElement = docElement
}
getLastText(tagName: string): string | null {
getAnyText(tagName: string): string | null {
const nodes = this.docElement.getElementsByTagName(tagName)
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < nodes.length; i++) {
const e = nodes[i]
if (!e.getAttribute('Condition')) {
return e.textContent
}
}
return nodes.length > 0 ? nodes[nodes.length - 1].textContent : null
}

Expand All @@ -39,16 +46,16 @@ async function run(): Promise<void> {
core.debug(`proj-path=${projPath}`)
let found = false
const doc = await DocumentWrapper.createAsync(projPath)
let versionPrefix = doc.getLastText('VersionPrefix')
let versionSuffix = doc.getLastText('VersionSuffix')
let version = doc.getLastText('Version')
let versionPrefix = doc.getAnyText('VersionPrefix')
let versionSuffix = doc.getAnyText('VersionSuffix')
let version = doc.getAnyText('Version')

if (version) {
found = true
const hyphenPos = version.indexOf('-')
if (hyphenPos >= 0) {
versionPrefix = version.substr(0, hyphenPos)
versionSuffix = version.substr(hyphenPos + 1)
versionPrefix = version.substring(0, hyphenPos)
versionSuffix = version.substring(hyphenPos + 1)
} else {
versionPrefix = version
versionSuffix = ''
Expand All @@ -69,28 +76,28 @@ async function run(): Promise<void> {
}
}

let packageVersion = doc.getLastText('PackageVersion')
let packageVersion = doc.getAnyText('PackageVersion')
if (packageVersion) {
found = true
} else {
packageVersion = version
}

let assemblyVersion = doc.getLastText('AssemblyVersion')
let assemblyVersion = doc.getAnyText('AssemblyVersion')
if (assemblyVersion) {
found = true
} else {
assemblyVersion = versionPrefix
}

let fileVersion = doc.getLastText('FileVersion')
let fileVersion = doc.getAnyText('FileVersion')
if (fileVersion) {
found = true
} else {
fileVersion = assemblyVersion
}

let informationalVersion = doc.getLastText('InformationalVersion')
let informationalVersion = doc.getAnyText('InformationalVersion')
if (informationalVersion) {
found = true
} else {
Expand Down

0 comments on commit f38c4b4

Please sign in to comment.