Skip to content

Commit 5e05ac7

Browse files
committed
feat: add version file support for java .properties file format
1 parent 3e7bb68 commit 5e05ac7

7 files changed

Lines changed: 205 additions & 10 deletions

File tree

.github/workflows/test.yml

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,125 @@ jobs:
753753
EXPECTED_VERSION: "6.5.0"
754754
EXPECTED_VERSION_PATH: "package.version"
755755

756+
test-properties:
757+
runs-on: ubuntu-latest
758+
steps:
759+
- name: Checkout code
760+
uses: actions/checkout@v5
761+
with:
762+
path: "./"
763+
764+
- run: npm ci --prod
765+
- run: npm run build
766+
767+
- run: "git config --global user.email 'changelog@github.com'"
768+
- run: "git config --global user.name 'Awesome Github action'"
769+
- run: "git add . && git commit --allow-empty -m 'feat: Added fake file so version will be bumped'"
770+
771+
- name: Generate changelog
772+
id: changelog
773+
uses: ./
774+
env:
775+
ENV: "dont-use-git"
776+
EXPECTED_TAG: "v2.1.0"
777+
with:
778+
github-token: ${{ secrets.github_token }}
779+
version-file: "test-file.properties"
780+
781+
- name: Generate changelog
782+
id: changelog
783+
uses: ./
784+
env:
785+
ENV: "dont-use-git"
786+
EXPECTED_TAG: "v3.1.0"
787+
with:
788+
github-token: ${{ secrets.github_token }}
789+
version-file: "test-file.properties"
790+
version-path: "colon_version"
791+
792+
- name: Show file
793+
run: |
794+
echo "$(<test-file.properties)"
795+
796+
- name: Test output
797+
run: node ./test-output.js
798+
env:
799+
FILES: "test-file.properties"
800+
EXPECTED_VERSION: "2.1.0,3.1.0,#version = 0.4.2,!version = 0.4.3,# colon_version:0.4.4,! colon_version:0.4.5"
801+
802+
test-properties-new:
803+
runs-on: ubuntu-latest
804+
steps:
805+
- name: Checkout code
806+
uses: actions/checkout@v5
807+
with:
808+
path: "./"
809+
810+
- run: npm ci --prod
811+
- run: npm run build
812+
813+
- run: "git config --global user.email 'changelog@github.com'"
814+
- run: "git config --global user.name 'Awesome Github action'"
815+
- run: "git add . && git commit --allow-empty -m 'feat: Added fake file so version will be bumped'"
816+
817+
- name: Generate changelog
818+
id: changelog
819+
uses: ./
820+
env:
821+
ENV: "dont-use-git"
822+
EXPECTED_TAG: "v0.1.0"
823+
with:
824+
github-token: ${{ secrets.github_token }}
825+
version-file: "test-file-new.properties"
826+
827+
- name: Show file
828+
run: |
829+
echo "$(<test-file-new.properties)"
830+
831+
- name: Test output
832+
run: node ./test-output.js
833+
env:
834+
FILES: "test-file-new.properties"
835+
EXPECTED_VERSION: "0.1.0"
836+
837+
test-properties-empty:
838+
runs-on: ubuntu-latest
839+
steps:
840+
- name: Checkout code
841+
uses: actions/checkout@v5
842+
with:
843+
path: "./"
844+
845+
- run: npm ci --prod
846+
- run: npm run build
847+
848+
- run: "git config --global user.email 'changelog@github.com'"
849+
- run: "git config --global user.name 'Awesome Github action'"
850+
- run: "git add . && git commit --allow-empty -m 'feat: Added fake file so version will be bumped'"
851+
852+
- run: touch ./test-file-empty.properties
853+
854+
- name: Generate changelog
855+
id: changelog
856+
uses: ./
857+
env:
858+
ENV: "dont-use-git"
859+
EXPECTED_TAG: "v6.5.0"
860+
with:
861+
github-token: ${{ secrets.github_token }}
862+
version-file: "test-file-empty.properties"
863+
fallback-version: "6.5.0"
864+
865+
- name: Show file
866+
run: |
867+
echo "$(<test-file-empty.properties)"
868+
869+
- name: Test output
870+
run: node ./test-output.js
871+
env:
872+
FILES: "test-file-empty.properties"
873+
EXPECTED_VERSION: "6.5.0"
874+
756875
test-pre-commit:
757876
runs-on: ubuntu-latest
758877
steps:
@@ -844,7 +963,7 @@ jobs:
844963
EXPECTED_TAG: "v1.5.0"
845964
with:
846965
github-token: ${{ secrets.github_token }}
847-
version-file: "test-file.json, test-file-2.json, test-file.toml, test-file.yaml"
966+
version-file: "test-file.json, test-file-2.json, test-file.toml, test-file.yaml, test-file.properties"
848967

849968
- name: Show files
850969
run: |
@@ -856,12 +975,14 @@ jobs:
856975
echo "$(<test-file.toml)\n\n"
857976
echo "Test yaml file"
858977
echo "$(<test-file.yaml)\n\n"
978+
echo "Test properties file"
979+
echo "$(<test-file.properties)\n\n"
859980
860981
- name: Test output
861982
run: node ./test-output.js
862983
env:
863-
FILES: "test-file.json, test-file-2.json, test-file.toml, test-file.yaml"
864-
EXPECTED_VERSION: "1.5.0, 1.5.0, 1.5.0, 1.11.0"
984+
FILES: "test-file.json, test-file-2.json, test-file.toml, test-file.yaml, test-file.properties"
985+
EXPECTED_VERSION: "1.5.0, 1.5.0, 1.5.0, 1.11.0, 2.1.0"
865986

866987
test-config-file-path:
867988
runs-on: ubuntu-latest

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This action will bump version, tag commit and generate a changelog with conventi
1818
- **Optional** `input-file`: Read the changelog from this file. This will prepend the newly generated changelogs to the file's content.
1919
- **Optional** `output-file`: File to output the changelog to. Default `CHANGELOG.md`, when providing `'false'` no file will be generated / updated.
2020
- **Optional** `release-count`: Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all. This input has no effect if `input-file` is used.
21-
- **Optional** `version-file`: The path to the file that contains the version to bump (supports comma-separated list of file paths). Default `./package.json`. Other supported formats are `mix.exs`, `.toml`, `.yml`, `.yaml`, and `.json`.
21+
- **Optional** `version-file`: The path to the file that contains the version to bump (supports comma-separated list of file paths). Default `./package.json`. Other supported formats are `mix.exs`, `.toml`, `.yml`, `.yaml`, `.json` and `.properties`.
2222
- **Optional** `version-path`: The place inside the version file to bump. Default `version`.
2323
- **Optional** `skip-git-pull`: Do not pull the repo before tagging. Ensure you full cloned the repo in the first place to get tags. Default `'false'`.
2424
- **Optional** `skip-on-empty`: Boolean to specify if you want to skip empty release (no-changelog generated). This case occurred when you push `chore` commit with `angular` for example. Default `'true'`.
@@ -146,7 +146,7 @@ Overwrite everything
146146
tag-prefix: 'v'
147147
output-file: 'MY_CUSTOM_CHANGELOG.md'
148148
release-count: '10'
149-
version-file: './my_custom_version_file.json' // or .yml, .yaml, .toml, mix.exs
149+
version-file: './my_custom_version_file.json' // or .yml, .yaml, .toml, mix.exs, .properties
150150
version-path: 'path.to.version'
151151
skip-on-empty: 'false'
152152
skip-version-file: 'false'

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/version/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Git = require('./git')
33
const Yaml = require('./yaml')
44
const Toml = require('./toml')
55
const Mix = require('./mix')
6+
const Properties = require('./properties')
67

78
module.exports = (fileExtension, filePath) => {
89
switch (fileExtension.toLowerCase()) {
@@ -22,6 +23,9 @@ module.exports = (fileExtension, filePath) => {
2223
case 'exs':
2324
return new Mix()
2425

26+
case 'properties':
27+
return new Properties()
28+
2529
default:
2630
throw new Error(`File extension "${fileExtension}" from file "${filePath}" is not supported`)
2731
}

src/version/properties.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const BaseVersioning = require('./base')
2+
const bumpVersion = require('../helpers/bumpVersion')
3+
4+
module.exports = class Properties extends BaseVersioning {
5+
6+
fileContent = null
7+
8+
#getProperty(content, key) {
9+
const regex = new RegExp(`^\\s*${key}\\s*[:=]\\s*(.*)$`, "m")
10+
const match = content.match(regex)
11+
return match ? match[1].trim() : null
12+
}
13+
14+
#setProperty(content, key, value) {
15+
// https://regexr.com/8gtpa
16+
const regex = new RegExp(`^(\\s*${key}\\s*)([:=])(.*)$`, "m")
17+
18+
if (regex.test(content)) {
19+
return content.replace(regex, (_, _key, sep) => `${key.trim()}${sep.trim()}${value}`)
20+
}
21+
else {
22+
if (content.length > 0 && !content.endsWith("\n")) {
23+
return content + `\n${key}=${value}`
24+
}
25+
return content + `${key}=${value}`
26+
}
27+
}
28+
29+
/**
30+
* Reads and parses .properties file
31+
*/
32+
parseFile = () => {
33+
this.fileContent = this.readFile()
34+
this.oldVersion = this.#getProperty(this.fileContent, this.versionPath)
35+
}
36+
37+
/**
38+
* Bumps the version in .properties file
39+
*
40+
* @param {!string} releaseType - The type of release
41+
* @return {*}
42+
*/
43+
bump = async(releaseType) => {
44+
this.newVersion = await bumpVersion(releaseType, this.oldVersion)
45+
46+
this.update(
47+
this.#setProperty(this.fileContent, this.versionPath, this.newVersion)
48+
)
49+
}
50+
51+
}

test-file.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=test file for version parsing/replacing
2+
3+
#version = 0.4.2
4+
!version = 0.4.3
5+
version = 2.0.0
6+
7+
# colon_version:0.4.4
8+
! colon_version:0.4.5
9+
colon_version:3.0.0

test-output.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ FILES.split(',').map((file, index) => {
4545
parsedContent = fileContent
4646
break
4747

48+
case 'properties':
49+
parsedContent = fileContent
50+
break
51+
4852
default:
4953
assert.fail(`File extension "${fileExtension}" is not supported!`)
5054
}
@@ -57,18 +61,24 @@ FILES.split(',').map((file, index) => {
5761

5862
const expectedVersions = EXPECTED_VERSION.split(',')
5963
const expectedVersion = expectedVersions.length > 0
60-
? expectedVersions[index]
64+
? expectedVersions[index].trim()
6165
: expectedVersions
6266

6367
if (fileExtension.toLowerCase() === 'exs') {
6468
assert.strictEqual(parsedContent.includes(expectedVersion), true, 'Version does not match what is expected')
6569
return
6670
}
6771

72+
if (fileExtension.toLowerCase() === 'properties') {
73+
console.log(`"${file}" check if version matches what is expected "${expectedVersion}"`)
74+
assert.strictEqual(parsedContent.includes(expectedVersion), true, 'Version does not match what is expected')
75+
return
76+
}
77+
6878
const newVersionInFile = objectPath.get(parsedContent, EXPECTED_VERSION_PATH, null)
6979

70-
console.log(`"${file}" check if "${newVersionInFile}" matches what is expected "${expectedVersion.trim()}"`)
80+
console.log(`"${file}" check if "${newVersionInFile}" matches what is expected "${expectedVersion}"`)
7181

72-
assert.strictEqual(newVersionInFile, expectedVersion.trim(), 'Version does not match what is expected')
82+
assert.strictEqual(newVersionInFile, expectedVersion, 'Version does not match what is expected')
7383
})
7484

0 commit comments

Comments
 (0)