Skip to content

Commit

Permalink
add xml format support
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyLadanov committed Mar 22, 2024
1 parent 012f086 commit c7770dc
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 6 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

## Примеры использования

### Пример содержимого файла (для файлов *.h, *.hpp, *.c, *.cpp)
### Пример содержимого файла (для файлов \*.h, \*.hpp, \*.c, \*.cpp)

Файл version_examples/version.h

Expand All @@ -54,15 +54,14 @@
```
- name: Get app version
id: version_step
uses: aps-m/read_app_version_action@v2
uses: aps-m/read_app_version_action@v3
with:
ver_file: 'version_examples/version.h'
defined_version_var: 'FIRMWARE_VERSION'
```


### Пример содержимого файла (для файлов *.cs)
### Пример содержимого файла (для файлов \*.cs)

Файл version_examples/AssemblyInfo.cs

Expand All @@ -73,17 +72,33 @@

### Получение версии


```
- name: Get app version
id: version_step
uses: aps-m/read_app_version_action@v2
uses: aps-m/read_app_version_action@v3
with:
ver_file: 'version_examples/AssemblyInfo.cs'
defined_version_var: 'AssemblyFileVersion'
```

### Пример содержимого файла (для файлов \*.csproj, \*.xml )

Файл version_examples/projectname.csproj

```
<FileVersion>1.5.0.15</FileVersion>
```

### Получение версии

```
- name: Get app version
id: version_step
uses: aps-m/read_app_version_action@v3
with:
ver_file: 'version_examples/projectname.csproj'
defined_version_var: 'FileVersion'
```

### Использование результата

Expand Down
63 changes: 63 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/version_api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path'
import { GetVersion as GetVersion_C } from './c_version_reader'
import { GetVersion as GetVersion_CS } from './cs_version_reader'
import { GetVersion as GetVersion_XML } from './xml_version_reader'

export function Handle(filename: string, keyword: string): string {
let extension = path.extname(filename)
Expand All @@ -18,5 +19,9 @@ export function Handle(filename: string, keyword: string): string {
return GetVersion_CS(filename, keyword)
}

if (extension === '.csproj' || extension === '.xml') {
return GetVersion_XML(filename, keyword)
}

return ''
}
35 changes: 35 additions & 0 deletions src/xml_version_reader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as fs from 'fs'

export function GetVersion(filename: string, keyword: string): string {
let result = ''
const words = fs.readFileSync(filename, 'utf-8')

const arr = words.split(/\r?\n/)

let composite_version = ''

for (let line of arr) {
let probe: any = new RegExp(
`<${keyword}>[0-9]+.[0-9]+.[0-9]+.[0-9]+</${keyword}>`
).exec(line)

if (probe) {
probe = new RegExp(`[0-9]+.[0-9]+.[0-9]+.[0-9]+`).exec(line)

if (probe) {
const verArray = probe[0].split('.')
result = `${verArray[0]}`
result = `${result}.${verArray[1]}`
result = `${result}.${verArray[2]}`

if (Number(verArray[3]) > 0) {
result = `${result}-b${verArray[3]}`
}

return result
}
}
}

return ''
}

0 comments on commit c7770dc

Please sign in to comment.