Skip to content

feat: add build info #14

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

Merged
merged 1 commit into from
Apr 23, 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
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Otherwise the version and its components are avaialbe through action outputs.
echo "v${{ steps.semver.outputs.major }}"
echo "v${{ steps.semver.outputs.minor }}"
echo "v${{ steps.semver.outputs.patch }}"
echo "v${{ steps.semver.outputs.extra }}"
echo "v${{ steps.semver.outputs.prerelease }}"
echo "v${{ steps.semver.outputs.build }}"
```

## Inputs
Expand All @@ -48,15 +49,17 @@ The following outputs are available through `steps.<id>.outputs` when the action

| Name | Type | Description | Example |
| ---- | --- | ------------ | ------- |
| `version` | `string` | The full version wihout prefixes | `2.13.34-dev` |
| `version` | `string` | The full version without prefixes | `2.13.34-dev+001` |
| `major` | `string` | The major version number | `2` |
| `minor` | `string` | The minor version number | `13` |
| `patch` | `string` | The patch version number | `34` |
| `extra` | `string` | The prerelease version or extra | `dev` |
| `prerelease` | `string` | The prerelease version | `dev` |
| `build` | `string` | The build metadata | `001` |

> [!TIP]
> The version is coerced in to a semantic version as per the [resolution strategy](#resolution-strategy), therefore all outputs will be present assuming the action succeeds.
> In all cases the `extra` output will always be an empty string (`""`) unless provided in the [prerelease version](https://semver.org/#spec-item-9).
> In all cases the `prerelease` output will always be an empty string (`""`) unless provided in the [prerelease version](https://semver.org/#spec-item-9).
> Similarly the `build` output will always be an empty string (`""`) unless provided in the [build metadata](https://semver.org/#spec-item-10).

## Resolution Strategy

Expand Down
27 changes: 11 additions & 16 deletions build/action.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2685,25 +2685,18 @@ var normaliseInputStringValue = (value) => {
// src/core/version.ts
var import_coerce = __toESM(require_coerce());
var resolveVersionFromString = (value) => {
const refless = value.replace(/^refs\/tags\//, "");
const coerced = (0, import_coerce.default)(refless);
if (coerced === null) {
const version2 = (0, import_coerce.default)(value, { includePrerelease: true });
if (version2 === null) {
return void 0;
}
let extra = "";
let version2 = coerced.format();
const prerelease = refless.indexOf("-");
if (prerelease > -1) {
extra = refless.slice(prerelease + 1);
version2 = `${version2}-${extra}`;
}
return {
version: version2,
version: version2.format(),
part: {
major: coerced.major.toString(),
minor: coerced.minor.toString(),
patch: coerced.patch.toString(),
extra
major: version2.major.toString(),
minor: version2.minor.toString(),
patch: version2.patch.toString(),
prerelease: version2.prerelease.join("."),
build: version2.build.join(".")
}
};
};
Expand All @@ -2725,7 +2718,9 @@ var action = async (action2) => {
action2.output("major", validated.part.major);
action2.output("minor", validated.part.minor);
action2.output("patch", validated.part.patch);
action2.output("extra", validated.part.extra);
action2.output("extra", validated.part.prerelease);
action2.output("prerelease", validated.part.prerelease);
action2.output("build", validated.part.build);
} catch (error) {
action2.fail(`An unexpected error occured: ${error}`);
}
Expand Down
24 changes: 17 additions & 7 deletions src/core/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ describe('action()', (): void => {
expect(input).toBeCalledTimes(1);
expect(input).toHaveBeenNthCalledWith<[string, ActionInputFunctionOptions]>(1, 'version', { required: true });

expect(output).toBeCalledTimes(5);
expect(output).toBeCalledTimes(7);
expect(output).toHaveBeenNthCalledWith<[string, string]>(1, 'version', '1.2.3');
expect(output).toHaveBeenNthCalledWith<[string, string]>(2, 'major', '1');
expect(output).toHaveBeenNthCalledWith<[string, string]>(3, 'minor', '2');
expect(output).toHaveBeenNthCalledWith<[string, string]>(4, 'patch', '3');
expect(output).toHaveBeenNthCalledWith<[string, string]>(5, 'extra', '');
expect(output).toHaveBeenNthCalledWith<[string, string]>(6, 'prerelease', '');
expect(output).toHaveBeenNthCalledWith<[string, string]>(7, 'build', '');

expect(fail).toBeCalledTimes(0);
});
Expand All @@ -34,7 +36,7 @@ describe('action()', (): void => {
const output = fn<ActionOutputFunction>();
const fail = fn<ActionFailFunction>();

input.mockReturnValueOnce('10.23.4');
input.mockReturnValueOnce('v10.23.4');

await action({
input,
Expand All @@ -45,12 +47,14 @@ describe('action()', (): void => {
expect(input).toBeCalledTimes(1);
expect(input).toHaveBeenNthCalledWith<[string, ActionInputFunctionOptions]>(1, 'version', { required: true });

expect(output).toBeCalledTimes(5);
expect(output).toBeCalledTimes(7);
expect(output).toHaveBeenNthCalledWith<[string, string]>(1, 'version', '10.23.4');
expect(output).toHaveBeenNthCalledWith<[string, string]>(2, 'major', '10');
expect(output).toHaveBeenNthCalledWith<[string, string]>(3, 'minor', '23');
expect(output).toHaveBeenNthCalledWith<[string, string]>(4, 'patch', '4');
expect(output).toHaveBeenNthCalledWith<[string, string]>(5, 'extra', '');
expect(output).toHaveBeenNthCalledWith<[string, string]>(6, 'prerelease', '');
expect(output).toHaveBeenNthCalledWith<[string, string]>(7, 'build', '');

expect(fail).toBeCalledTimes(0);
});
Expand All @@ -60,7 +64,7 @@ describe('action()', (): void => {
const output = fn<ActionOutputFunction>();
const fail = fn<ActionFailFunction>();

input.mockReturnValueOnce('2.3-alpha.2');
input.mockReturnValueOnce('2.3-alpha.2+001');

await action({
input,
Expand All @@ -71,12 +75,14 @@ describe('action()', (): void => {
expect(input).toBeCalledTimes(1);
expect(input).toHaveBeenNthCalledWith<[string, ActionInputFunctionOptions]>(1, 'version', { required: true });

expect(output).toBeCalledTimes(5);
expect(output).toBeCalledTimes(7);
expect(output).toHaveBeenNthCalledWith<[string, string]>(1, 'version', '2.3.0-alpha.2');
expect(output).toHaveBeenNthCalledWith<[string, string]>(2, 'major', '2');
expect(output).toHaveBeenNthCalledWith<[string, string]>(3, 'minor', '3');
expect(output).toHaveBeenNthCalledWith<[string, string]>(4, 'patch', '0');
expect(output).toHaveBeenNthCalledWith<[string, string]>(5, 'extra', 'alpha.2');
expect(output).toHaveBeenNthCalledWith<[string, string]>(6, 'prerelease', 'alpha.2');
expect(output).toHaveBeenNthCalledWith<[string, string]>(7, 'build', '001');

expect(fail).toBeCalledTimes(0);
});
Expand All @@ -97,12 +103,14 @@ describe('action()', (): void => {
expect(input).toBeCalledTimes(1);
expect(input).toHaveBeenNthCalledWith<[string, ActionInputFunctionOptions]>(1, 'version', { required: true });

expect(output).toBeCalledTimes(5);
expect(output).toBeCalledTimes(7);
expect(output).toHaveBeenNthCalledWith<[string, string]>(1, 'version', '4.36.14');
expect(output).toHaveBeenNthCalledWith<[string, string]>(2, 'major', '4');
expect(output).toHaveBeenNthCalledWith<[string, string]>(3, 'minor', '36');
expect(output).toHaveBeenNthCalledWith<[string, string]>(4, 'patch', '14');
expect(output).toHaveBeenNthCalledWith<[string, string]>(5, 'extra', '');
expect(output).toHaveBeenNthCalledWith<[string, string]>(6, 'prerelease', '');
expect(output).toHaveBeenNthCalledWith<[string, string]>(7, 'build', '');

expect(fail).toBeCalledTimes(0);
});
Expand All @@ -123,12 +131,14 @@ describe('action()', (): void => {
expect(input).toBeCalledTimes(1);
expect(input).toHaveBeenNthCalledWith<[string, ActionInputFunctionOptions]>(1, 'version', { required: true });

expect(output).toBeCalledTimes(5);
expect(output).toBeCalledTimes(7);
expect(output).toHaveBeenNthCalledWith<[string, string]>(1, 'version', '5.31.12-beta.1');
expect(output).toHaveBeenNthCalledWith<[string, string]>(2, 'major', '5');
expect(output).toHaveBeenNthCalledWith<[string, string]>(3, 'minor', '31');
expect(output).toHaveBeenNthCalledWith<[string, string]>(4, 'patch', '12');
expect(output).toHaveBeenNthCalledWith<[string, string]>(5, 'extra', 'beta.1');
expect(output).toHaveBeenNthCalledWith<[string, string]>(6, 'prerelease', 'beta.1');
expect(output).toHaveBeenNthCalledWith<[string, string]>(7, 'build', '');

expect(fail).toBeCalledTimes(0);
});
Expand Down
5 changes: 4 additions & 1 deletion src/core/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export const action = async (action: ActionDependencies): Promise<void> => {
action.output('major', validated.part.major);
action.output('minor', validated.part.minor);
action.output('patch', validated.part.patch);
action.output('extra', validated.part.extra);
// TODO: Remove `extra` in v3, replaced with `prerelease`
action.output('extra', validated.part.prerelease);
action.output('prerelease', validated.part.prerelease);
action.output('build', validated.part.build);
} catch (error: unknown) {
action.fail(`An unexpected error occured: ${error}`);
}
Expand Down
Loading
Loading