Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

version: allow basic regex replacement in version #122

Merged
merged 1 commit into from
Jun 15, 2021
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
28 changes: 27 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
//import * as process from 'process';
//import * as cp from 'child_process';
//import * as path from 'path';
import { Version } from '../src/version';

test('always true', async () => {});
test('version format specifiers', async () => {
const version = new Version('2.30.0.abc.8.9');

const expected =
'The full version is 2.30.0.abc.8.9.\n' +
'The major version is 2.\n' +
'The major.minor version is 2.30.\n' +
'The major.minor.patch version is 2.30.0.\n' +
'Simple substitution is 2.30.0.xyz.8.9.\n' +
'Regex substitution 1 is 2-30-0-8-9_abc.\n' +
'Regex substitution 2 is 2.30.\n' +
'Empty substitution is 2.30.0.8.9.';

const actual = version.format(
'The full version is {{version}}.\n' +
'The major version is {{version.major}}.\n' +
'The major.minor version is {{version.major_minor}}.\n' +
'The major.minor.patch version is {{version.major_minor_patch}}.\n' +
'Simple substitution is {{version:s/abc/xyz/}}.\n' +
'Regex substitution 1 is {{version:s/(\\d+)\\.(\\d+)\\.(\\d+)\\.(.+)\\.(\\d+)\\.(\\d+)/$1-$2-$3-$5-$6_$4/}}.\n' +
'Regex substitution 2 is {{version:s/^(\\d+)\\.(\\d+).*/$1.$2/}}.\n' +
'Empty substitution is {{version:s/\\.abc//}}.'
);

expect(actual).toBe(expected);
});
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ inputs:
{{version.major}} => major version (x)
{{version.major_minor}} => major and minor version (x.y)
{{version.major_minor_patch}} => major, minor and patch version (x.y.z)
{{version:s/search/replace/}} => apply regular expression replacement to the full version string
example: version = 1.2.3, {{version:s/\./-/}} => 1-2-3
required: true
releaseRepo:
description: |
Expand All @@ -43,6 +45,8 @@ inputs:
{{version.major}} => major version (x)
{{version.major_minor}} => major and minor version (x.y)
{{version.major_minor_patch}} => major, minor and patch version (x.y.z)
{{version:s/search/replace/}} => apply regular expression replacement to the full version string
example: version = 1.2.3, {{version:s/\./-/}} => 1-2-3
required: false
sha256:
description: Download asset SHA-256 hash. If omitted the hash will be calculated.
Expand All @@ -68,6 +72,8 @@ inputs:
{{version.major}} => major version (x)
{{version.major_minor}} => major and minor version (x.y)
{{version.major_minor_patch}} => major, minor and patch version (x.y.z)
{{version:s/search/replace/}} => apply regular expression replacement to the full version string
example: version = 1.2.3, {{version:s/\./-/}} => 1-2-3
required: false
default: |
{{id}}: update to {{version}}
Expand Down
Loading