chkfung / android-version-actions

MIT License
32 stars 24 forks source link

Regex matches versionCode in comments #4

Open tibbe opened 2 years ago

tibbe commented 2 years ago

I was scratching my head why this action wasn't working for me. After some debugging I realized that it had managed to replace versionCode in a comment (e.g. // Here's a sentence with versionCode in it). The replacement mechanism needs to be a bit more robust. At the very least a regex that doesn't match on a comment line.

tibbe commented 2 years ago

The version code should be an integer so you can at least use \d+ to get somewhat better matching.

tibbe commented 2 years ago

One idea would be to make sure the line start with whitespace:

const versionCodeRegexPattern = /^(\s*versionCode(?:\s|=)\s*)(\d+.*)/;

This doesn't match (single line) comments and only integer versionCodes (which they should be according to the docs).

This assume there is actually a code in build.gradle but so did the previous version.