Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag filter support #11

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
lib
test-files/*/actual-results
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run tests",
"program": "${workspaceFolder}/node_modules/ava/entrypoints/cli.mjs",
"args": [
"--serial",
"lib/test.js"
],
"outputCapture": "std",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**/*.js"
]
}
]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 vers-one
Copyright (c) 2022-2024 vers-one

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
94 changes: 65 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,67 @@ Examples:
|1.1 |`*.*.*.*` |1.1.0.0 |Sets the missing build and revision parts to zero, leaves the major and the minor parts unchanged |
|1.1 |`?.?.?.?` |1.1 |Leaves all parts unchanged |

### `tags` (optional)

Comma-separated list of version tags to process.

Allows to refine the `file` / `files` filter to exclude the unwanted version declarations found in the matching files. The values in the list are not case-sensitive, extra spaces between the values are trimmed.

**Default**: `*`

Supported tags:

|Tag |Description |
|--------------------------------------|------------------------------------------------------------------------------|
|`*` |Process all supported version declarations in all supported file types |
|`csproj.*` |Process all supported version declarations in *.csproj* files |
|`csproj.Version` |Process `<Version>...</Version>` item in *.csproj* files |
|`csproj.VersionPrefix` |Process `<VersionPrefix>...</VersionPrefix>` item in *.csproj* files |
|`csproj.AssemblyVersion` |Process `<AssemblyVersion>...</AssemblyVersion>` item in *.csproj* files |
|`csproj.FileVersion` |Process `<FileVersion>...</FileVersion>` item in *.csproj* files |
|`vbproj.*` |Process all supported version declarations in *.vbproj* files |
|`vbproj.Version` |Process `<Version>...</Version>` item in *.vbproj* files |
|`vbproj.VersionPrefix` |Process `<VersionPrefix>...</VersionPrefix>` item in *.vbproj* files |
|`vbproj.AssemblyVersion` |Process `<AssemblyVersion>...</AssemblyVersion>` item in *.vbproj* files |
|`vbproj.FileVersion` |Process `<FileVersion>...</FileVersion>` item in *.vbproj* files |
|`fsproj.*` |Process all supported version declarations in *.fsproj* files |
|`fsproj.Version` |Process `<Version>...</Version>` item in *.fsproj* files |
|`fsproj.VersionPrefix` |Process `<VersionPrefix>...</VersionPrefix>` item in *.fsproj* files |
|`fsproj.AssemblyVersion` |Process `<AssemblyVersion>...</AssemblyVersion>` item in *.fsproj* files |
|`fsproj.FileVersion` |Process `<FileVersion>...</FileVersion>` item in *.fsproj* files |
|`props.*` |Process all supported version declarations in *.props* files |
|`props.Version` |Process `<Version>...</Version>` item in *.props* files |
|`props.VersionPrefix` |Process `<VersionPrefix>...</VersionPrefix>` item in *.props* files |
|`props.AssemblyVersion` |Process `<AssemblyVersion>...</AssemblyVersion>` item in *.props* files |
|`props.FileVersion` |Process `<FileVersion>...</FileVersion>` item in *.props* files |
|`nuspec.*` |Process all supported version declarations in *.nuspec* files |
|`nuspec.Version` |Process `<Version>...</Version>` item in *.nuspec* files |
|`AssemblyInfo-cs.*` |Process all supported version declarations in *.cs* files |
|`AssemblyInfo-cs.AssemblyVersion` |Process `[assembly: AssemblyVersion("...")]` item in *.cs* files |
|`AssemblyInfo-cs.AssemblyFileVersion` |Process `[assembly: AssemblyFileVersion("...")]` item in *.cs* files |
|`AssemblyInfo-vb.*` |Process all supported version declarations in *.vb* files |
|`AssemblyInfo-vb.AssemblyVersion` |Process `<Assembly: AssemblyVersion("...")>` item in *.vb* files |
|`AssemblyInfo-vb.AssemblyFileVersion` |Process `<Assembly: AssemblyFileVersion("...")>` item in *.vb* files |
|`AssemblyInfo-fs.*` |Process all supported version declarations in *.fs* files |
|`AssemblyInfo-fs.AssemblyVersion` |Process `[<assembly: AssemblyVersion("...")>]` item in *.fs* files |
|`AssemblyInfo-fs.AssemblyFileVersion` |Process `[<assembly: AssemblyFileVersion("...")>]` item in *.fs* files |
|`AssemblyInfo-cpp.*` |Process all supported version declarations in *.cpp* files |
|`AssemblyInfo-cpp.AssemblyVersion` |Process `[assembly:AssemblyVersionAttribute(L"...")]` item in *.cpp* files |
|`AssemblyInfo-cpp.AssemblyFileVersion`|Process `[assembly:AssemblyFileVersionAttribute(L"...")]` item in *.cpp* files|
|`rc.*` |Process all supported version declarations in *.rc* files |
|`rc.FileVersion-param` |Process `FILEVERSION x,x,x,x` item in *.rc* files |
|`rc.ProductVersion-param` |Process `PRODUCTVERSION x,x,x,x` item in *.rc* files |
|`rc.FileVersion-string` |Process `VALUE "FileVersion", "..."` item in *.rc* files |
|`rc.ProductVersion-string` |Process `VALUE "ProductVersion", "..."` item in *.rc* files |

Examples:

|`tags` input |Explanation |
|-----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`AssemblyInfo-cs.AssemblyVersion` |Process only *.cs* files and only `[assembly: AssemblyVersion("...")]` items in those files |
|`csproj.Version, csproj.AssemblyVersion` |Process only *.csproj* files and only `<Version>...</Version>` and `<AssemblyVersion>...</AssemblyVersion>` items in those files |
|`csproj.Version, AssemblyInfo-cs.AssemblyVersion, nuspec.*`|Process only `<Version>...</Version>` items in *.csproj* files, `[assembly: AssemblyVersion("...")]` items in *.cs* files, and all supported version declarations in `.nuspec` files, and skip everything else|

## Outputs

### `oldVersion`
Expand Down Expand Up @@ -123,7 +184,7 @@ jobs:

- name: Set MyProject.csproj version
id: update
uses: vers-one/dotnet-project-version-updater@v1.5
uses: vers-one/dotnet-project-version-updater@v1.6
with:
file: "src/MyProject.csproj"
version: ${{ github.event.inputs.version }}
Expand Down Expand Up @@ -159,7 +220,7 @@ jobs:

- name: Set project versions
id: update
uses: vers-one/dotnet-project-version-updater@v1.5
uses: vers-one/dotnet-project-version-updater@v1.6
with:
file: |
"**/*.csproj", "**/*.nuspec", "**/AssemblyInfo.cs"
Expand Down Expand Up @@ -203,7 +264,7 @@ jobs:

- name: Bump build version
id: bump
uses: vers-one/dotnet-project-version-updater@v1.5
uses: vers-one/dotnet-project-version-updater@v1.6
with:
file: "src/MyProject.csproj"
version: bump-build
Expand All @@ -218,31 +279,6 @@ jobs:

## Additional notes

* This action searches for the following version declarations:
* for .csproj, .vbproj, .fsproj, and .props files:
* `<Version>...</Version>`;
* `<VersionPrefix>...</VersionPrefix>`;
* `<AssemblyVersion>...</AssemblyVersion>`;
* `<FileVersion>...</FileVersion>`;
* for .nuspec files:
* `<Version>...</Version>`;
* for .cs files:
* `[assembly: AssemblyVersion("...")]`;
* `[assembly: AssemblyFileVersion("...")]`;
* for .vb files:
* `<Assembly: AssemblyVersion("...")>`;
* `<Assembly: AssemblyFileVersion("...")>`;
* for .fs files:
* `[<assembly: AssemblyVersion("...")>]`;
* `[<assembly: AssemblyFileVersion("...")>]`;
* for .cpp files:
* `[assembly:AssemblyVersionAttribute(L"...")]`;
* `[assembly:AssemblyFileVersionAttribute(L"...")]`;
* for .rc files:
* `FILEVERSION x,x,x,x`;
* `PRODUCTVERSION x,x,x,x`;
* `VALUE "FileVersion", "..."`
* `VALUE "ProductVersion", "..."`.
* If you set the new version explicitly, you can use any string as a version number (e.g. `1.2.3`, `1.0.0-beta5`, `Vista`, `blah-blah`, etc). However if you use one of the bump commands or a bump pattern, the existing version must by in the following format: *major[.minor[.build[.revision]]]*.
* If you set the new version explicitly, you can use any string as a version number (e.g. `1.2.3`, `1.0.0-beta5`, `Vista`, `blah-blah`, etc). However, if you use one of the bump commands or a bump pattern, the existing version must by in the following format: *major[.minor[.build[.revision]]]*.
* Keep in mind that .NET Framework assembly versions [must be](https://docs.microsoft.com/en-us/dotnet/api/system.version#remarks) in the following format: *major.minor[.build[.revision]]*. Any other versions formats like `1.0.0-beta5` will cause a compilation failure.
* C++ resource files [require](https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource#parameters) `FILEVERSION` and `PRODUCTVERSION` resource parameters to have all four version components (*major.minor.build.revision*).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dotnet-project-version-updater",
"version": "1.5.0",
"version": "1.6.0",
"description": "A GitHub action to update or bump project versions. Supports .csproj, .props, .nuspec, and many other .NET file types.",
"main": "lib/index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ async function run(): Promise<void>
filePathPattern = Core.getInput("files");
}
const newVersion: string = Core.getInput("version");
const pluginTagFilter: string = Core.getInput("tags");
console.log(`File path pattern: ${filePathPattern}`);
console.log(`New version: ${newVersion}`);
const updaterResults: UpdaterResult[] = await Updater.update(filePathPattern, newVersion);
if (pluginTagFilter !== "")
{
console.log(`Tag filter: ${pluginTagFilter}`);
}
const updaterResults: UpdaterResult[] = await Updater.update(filePathPattern, newVersion, pluginTagFilter);
let oldVersionString: string = "";
let newVersionString: string = "";
for (const updaterResult of updaterResults)
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/assemblyinfo-cpp-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import Plugin, { PluginVersionRegex, VersionPartDelimiter } from "./plugin";
import Plugin, { PluginTag, VersionPartDelimiter } from "./plugin";

const ASSEMBLY_VERSION_ATTRIBUTE_REGEX: RegExp = /\[assembly:\s*AssemblyVersionAttribute\(\s*L"(.*)"\s*\)]/i;
const ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX: RegExp = /\[assembly:\s*AssemblyFileVersionAttribute\(\s*L"(.*)"\s*\)]/i;
const ASSEMBLY_VERSION_ATTRIBUTE_REGEX: RegExp = /^\s*\[assembly:\s*AssemblyVersionAttribute\(\s*L"(.*)"\s*\)]/;
const ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX: RegExp = /^\s*\[assembly:\s*AssemblyFileVersionAttribute\(\s*L"(.*)"\s*\)]/;

export default class AssemblyInfoCppPlugin extends Plugin
{
constructor()
{
const versionRegexes: PluginVersionRegex[] =
const tags: PluginTag[] =
[
{
tagName: "assemblyversion",
regex: ASSEMBLY_VERSION_ATTRIBUTE_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "AssemblyVersion attribute"
},
{
tagName: "assemblyfileversion",
regex: ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "AssemblyFileVersion attribute"
}
];
super(versionRegexes);
super(tags);
}

get pluginName(): string
{
return "assemblyinfo-cpp";
}

get fileTypeName(): string
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/assemblyinfo-cs-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import Plugin, { PluginVersionRegex, VersionPartDelimiter } from "./plugin";
import Plugin, { PluginTag, VersionPartDelimiter } from "./plugin";

const ASSEMBLY_VERSION_ATTRIBUTE_REGEX: RegExp = /\[assembly:\s*AssemblyVersion\(\s*"(.*)"\s*\)]/i;
const ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX: RegExp = /\[assembly:\s*AssemblyFileVersion\(\s*"(.*)"\s*\)]/i;
const ASSEMBLY_VERSION_ATTRIBUTE_REGEX: RegExp = /^\s*\[assembly:\s*AssemblyVersion\(\s*"(.*)"\s*\)]/;
const ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX: RegExp = /^\s*\[assembly:\s*AssemblyFileVersion\(\s*"(.*)"\s*\)]/;

export default class AssemblyInfoCsPlugin extends Plugin
{
constructor()
{
const versionRegexes: PluginVersionRegex[] =
const tags: PluginTag[] =
[
{
tagName: "assemblyversion",
regex: ASSEMBLY_VERSION_ATTRIBUTE_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "AssemblyVersion attribute"
},
{
tagName: "assemblyfileversion",
regex: ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "AssemblyFileVersion attribute"
}
];
super(versionRegexes);
super(tags);
}

get pluginName(): string
{
return "assemblyinfo-cs";
}

get fileTypeName(): string
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/assemblyinfo-fs-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import Plugin, { PluginVersionRegex, VersionPartDelimiter } from "./plugin";
import Plugin, { PluginTag, VersionPartDelimiter } from "./plugin";

const ASSEMBLY_VERSION_ATTRIBUTE_REGEX: RegExp = /\[<assembly:\s*AssemblyVersion\(\s*"(.*)"\s*\)>]/i;
const ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX: RegExp = /\[<assembly:\s*AssemblyFileVersion\(\s*"(.*)"\s*\)>]/i;
const ASSEMBLY_VERSION_ATTRIBUTE_REGEX: RegExp = /^\s*\[<assembly:\s*AssemblyVersion\(\s*"(.*)"\s*\)>]/;
const ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX: RegExp = /^\s*\[<assembly:\s*AssemblyFileVersion\(\s*"(.*)"\s*\)>]/;

export default class AssemblyInfoFsPlugin extends Plugin
{
constructor()
{
const versionRegexes: PluginVersionRegex[] =
const tags: PluginTag[] =
[
{
tagName: "assemblyversion",
regex: ASSEMBLY_VERSION_ATTRIBUTE_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "AssemblyVersion attribute"
},
{
tagName: "assemblyfileversion",
regex: ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "AssemblyFileVersion attribute"
}
];
super(versionRegexes);
super(tags);
}

get pluginName(): string
{
return "assemblyinfo-fs";
}

get fileTypeName(): string
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/assemblyinfo-vb-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import Plugin, { PluginVersionRegex, VersionPartDelimiter } from "./plugin";
import Plugin, { PluginTag, VersionPartDelimiter } from "./plugin";

const ASSEMBLY_VERSION_ATTRIBUTE_REGEX: RegExp = /<assembly:\s*AssemblyVersion\(\s*"(.*)"\s*\)>/i;
const ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX: RegExp = /<assembly:\s*AssemblyFileVersion\(\s*"(.*)"\s*\)>/i;
const ASSEMBLY_VERSION_ATTRIBUTE_REGEX: RegExp = /^\s*<assembly:\s*AssemblyVersion\(\s*"(.*)"\s*\)>/;
const ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX: RegExp = /^\s*<assembly:\s*AssemblyFileVersion\(\s*"(.*)"\s*\)>/;

export default class AssemblyInfoVbPlugin extends Plugin
{
constructor()
{
const versionRegexes: PluginVersionRegex[] =
const tags: PluginTag[] =
[
{
tagName: "assemblyversion",
regex: ASSEMBLY_VERSION_ATTRIBUTE_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "AssemblyVersion attribute"
},
{
tagName: "assemblyfileversion",
regex: ASSEMBLY_FILE_VERSION_ATTRIBUTE_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "AssemblyFileVersion attribute"
}
];
super(versionRegexes);
super(tags);
}

get pluginName(): string
{
return "assemblyinfo-vb";
}

get fileTypeName(): string
Expand Down
23 changes: 16 additions & 7 deletions src/plugins/csproj-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
import Plugin, { PluginVersionRegex, VersionPartDelimiter } from "./plugin";
import Plugin, { PluginTag, VersionPartDelimiter } from "./plugin";

const VERSION_TAG_REGEX: RegExp = /<Version>(.*)<\/Version>/i;
const VERSION_PREFIX_TAG_REGEX: RegExp = /<VersionPrefix>(.*)<\/VersionPrefix>/i;
const ASSEMBLY_VERSION_TAG_REGEX: RegExp = /<AssemblyVersion>(.*)<\/AssemblyVersion>/i;
const FILE_VERSION_TAG_REGEX: RegExp = /<FileVersion>(.*)<\/FileVersion>/i;
const VERSION_TAG_REGEX: RegExp = /<Version>(.*)<\/Version>/;
const VERSION_PREFIX_TAG_REGEX: RegExp = /<VersionPrefix>(.*)<\/VersionPrefix>/;
const ASSEMBLY_VERSION_TAG_REGEX: RegExp = /<AssemblyVersion>(.*)<\/AssemblyVersion>/;
const FILE_VERSION_TAG_REGEX: RegExp = /<FileVersion>(.*)<\/FileVersion>/;

export default class CsProjPlugin extends Plugin
{
constructor()
{
const versionRegexes: PluginVersionRegex[] =
const tags: PluginTag[] =
[
{
tagName: "version",
regex: VERSION_TAG_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "<Version> tag"
},
{
tagName: "versionprefix",
regex: VERSION_PREFIX_TAG_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "<VersionPrefix> tag"
},
{
tagName: "assemblyversion",
regex: ASSEMBLY_VERSION_TAG_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "<AssemblyVersion> tag"
},
{
tagName: "fileversion",
regex: FILE_VERSION_TAG_REGEX,
versionPartDelimiter: VersionPartDelimiter.DOT,
versionType: "<FileVersion> tag"
}
];
super(versionRegexes);
super(tags);
}

get pluginName(): string
{
return "csproj";
}

get fileTypeName(): string
Expand Down
Loading
Loading