Skip to content

Commit

Permalink
Merge pull request #27 from release-kit/feat/update-to-v2
Browse files Browse the repository at this point in the history
Update to v2
  • Loading branch information
Evgeny Zakharov authored May 28, 2023
2 parents dc798ab + d3d4e56 commit d18fd86
Show file tree
Hide file tree
Showing 14 changed files with 1,798 additions and 787 deletions.
8 changes: 5 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { configure, presets } = require('eslint-kit')

module.exports = configure({
allowDebug: process.env.NODE_ENV !== 'production',

presets: [
presets.typescript(),
presets.prettier(),
presets.imports(),
presets.node(),
presets.alias(),
presets.prettier(),
presets.typescript(),
],
})
15 changes: 1 addition & 14 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,5 @@
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"quoteProps": "consistent",
"endOfLine": "lf",
"importOrder": [
"^(child_process|crypto|events|fs|http|https|os|path)(\\/(.*))?$",
"<THIRD_PARTY_MODULES>",
"^~(\\/(.*))?$",
"^@(\\/(.*))?$",
"^@app(\\/(.*))?$",
"^[./]"
],
"experimentalBabelParserPluginsList": [
"jsx",
"typescript"
]
"quoteProps": "consistent"
}
53 changes: 30 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Navigation

- [Usage](#usage)
- [Parsing](#parsing)
- [Using a result](#using-a-result)
- [Options](#options)
- [Outputs](#outputs)
- [Contrubuting](#contributing)
Expand All @@ -9,41 +10,43 @@
- [Prerelease from](#prerelease-flow)
- [Conventions](#conventions)

## Usage

Extract and parse version:
## Parsing

```yml
steps:
# from tag (may be v-prefixed)
# 1. from workflow tag (can be v-prefixed)
# good for release workflows and pushing tags
- name: Parse version from tag
id: version
uses: release-kit/semver@v1
uses: release-kit/semver@v2

# from v-prefixed string
# 2. from manually defined v-prefixed string
- name: Parse version from string
id: version
uses: release-kit/semver@v1
uses: release-kit/semver@v2
with:
input: 'v4.5.0'
string: 'v4.5.0'

# from custom string
- name: Parse version from custom string
# 3. from a string with the custom pattern
- name: Parse version from a string with a custom pattern
id: version
uses: release-kit/semver@v1
uses: release-kit/semver@v2
with:
input: 'my-version:4.5.0'
extract: '^my-version:(.*)$' # ^v?(.*)$ by default
string: 'my-version:4.5.0'
pattern: '^my-version:(.*)$' # ^v?(.*)$ by default

# from tag with custom fallback
# 4. from a tag with the custom fallback
# the fallback is used when there is no tag found
# works only for "latest-tag" source
- name: Parse version from tag with custom fallback
id: version
uses: release-kit/semver@v1
uses: release-kit/semver@v2
with:
source: latest-tag
fallback: 'v1.0.0' # v0.1.0 by default
```
Use parsed result:
## Using a result
```yml
- name: Use parsed version
Expand All @@ -54,24 +57,28 @@ Use parsed result:
echo "${{ steps.version.outputs.prerelease }}"
echo "${{ steps.version.outputs.build }}"
echo "${{ steps.version.outputs.full }}"
echo "${{ steps.version.outputs.tag }}"
```
Check out the [Outputs](#outputs) section for the full description.
## Options
- `input` (optional, defaults to git tag) - custom string to use instead of git tag
- `fallback` (optional, defaults to `v0.1.0`) - fallback string when tag is not found
- `extract` (optional, defaults to `^v?(.*)$`) - regex to extract version from string
- `source` (optional, defaults to `workflow-tag`)
- `workflow-tag` - use tag from the workflow event (good from releases and tag pushes)
- `latest-tag` - use the latest tag from current repository (the commit doesn't matter)
- `string` - use the value from `string` input (can be omitted, automatically selected when `string` is defined)
- `string` (optional, defaults to empty) - a string to be parsed, required only when `source` is `string`
- `fallback` (optional, defaults to `v0.1.0`) - fallback string when a tag is not found
- `pattern` (optional, defaults to `^v?(.*)$`) - regex to extract a version from a string

## Outputs

- `full` - `3.4.5-alpha+1.2` in `v3.4.5-alpha+1.2`
- `major` - `3` in `v3.4.5-alpha+1.2`
- `minor` - `4` in `v3.4.5-alpha+1.2`
- `patch` - `5` in `v3.4.5-alpha+1.2`
- `prerelease` - `alpha` in `v3.4.5-alpha+1.2` (empty string if no present)
- `build` - `1.2` in `v3.4.5-alpha+1.2` (empty string if no present)
- `full` - `3.4.5-alpha+1.2` in `v3.4.5-alpha+1.2`
- `tag` - `v3.4.5-alpha+1.2` in `v3.4.5-alpha+1.2`

## Contributing

Expand Down
19 changes: 9 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ name: 'Semver Parse'
description: 'Parses a semantic version from a given string or git tag'

inputs:
input:
description: 'Raw input string containing or is a semantic version to be parsed'
source:
description: 'A source to take string from'
required: false
string:
description: 'A string to extract semver from'
required: false
fallback:
description: 'A string to use as a tag when it is not found'
required: false
default: 'v0.1.0'
extract:
description: 'Regex to extract semantic version from a input string if it is not a semver'
pattern:
description: 'Regex to extract semantic version from a input string'
required: false
default: '^v?(.*)$'

outputs:
full:
description: 'A full representation of the semver'
major:
description: 'MAJOR part of the semver'
minor:
Expand All @@ -25,10 +28,6 @@ outputs:
description: 'PRERELEASE part of the semver'
build:
description: 'BUILD part of the semver'
full:
description: 'A full representation of the semver'
tag:
description: 'A full git tag string when it is used'

runs:
using: 'node16'
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@
"dev": "yarn build --watch",
"test": "jest",
"test:watch": "yarn test --watchAll",
"lint": "eslint --ext .ts,.tsx src",
"lint:fix": "yarn lint --fix",
"lint": "eslint \"{src}/**/*.{js,ts}\"",
"lint:fix": "eslint \"{src}/**/*.{js,ts}\" --fix",
"prepare": "husky install"
},
"dependencies": {
"@actions/core": "^1.8.2",
"@actions/github": "^5.0.3",
"@actions/core": "^1.9.1",
"@actions/github": "^5.1.1",
"@rollup/plugin-node-resolve": "^13.3.0",
"execa": "5",
"semver": "^7.3.7"
"semver": "^7.3.7",
"zod": "^3.21.4"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.0",
"@types/jest": "^27.5.1",
"@types/semver": "^7.3.9",
"esbuild": "^0.14.39",
"eslint-kit": "^3.0.2",
"eslint": "^8.41.0",
"eslint-kit": "^9.0.9",
"husky": "^8.0.1",
"jest": "^28.1.0",
"jest-serializer-path": "^0.1.15",
Expand All @@ -46,6 +48,7 @@
"rollup-plugin-esbuild": "^4.9.1",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^28.0.2",
"typescript": "^4.6.4"
"typescript": "^4.6.4",
"prettier": "^2.8.8"
}
}
}
95 changes: 95 additions & 0 deletions src/__snapshots__/options.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getOptions empty inputs 1`] = `
Object {
"fallback": "v0.1.0",
"pattern": "^v?(.*)$",
"source": "workflow-tag",
}
`;

exports[`getOptions good fallback 1`] = `
Object {
"fallback": "v1.0.0",
"pattern": "^v?(.*)$",
"source": "workflow-tag",
}
`;

exports[`getOptions good pattern 1`] = `
Object {
"fallback": "v0.1.0",
"pattern": "^.*$",
"source": "workflow-tag",
}
`;

exports[`getOptions invalid fallback 1`] = `
"[
{
\\"code\\": \\"too_small\\",
\\"minimum\\": 1,
\\"type\\": \\"string\\",
\\"inclusive\\": true,
\\"exact\\": false,
\\"message\\": \\"String must contain at least 1 character(s)\\",
\\"path\\": [
\\"fallback\\"
]
}
]"
`;

exports[`getOptions invalid pattern 1`] = `
"[
{
\\"code\\": \\"custom\\",
\\"message\\": \\"Invalid input\\",
\\"path\\": [
\\"pattern\\"
]
}
]"
`;

exports[`getOptions latest tag source 1`] = `
Object {
"fallback": "v0.1.0",
"pattern": "^v?(.*)$",
"source": "latest-tag",
}
`;

exports[`getOptions only string input 1`] = `
Object {
"fallback": "v0.1.0",
"pattern": "^v?(.*)$",
"source": "string",
"string": "v1.0.0",
}
`;

exports[`getOptions string input with correct source 1`] = `
Object {
"fallback": "v0.1.0",
"pattern": "^v?(.*)$",
"source": "string",
"string": "v1.0.0",
}
`;

exports[`getOptions workflow tag source 1`] = `
Object {
"fallback": "v0.1.0",
"pattern": "^v?(.*)$",
"source": "workflow-tag",
}
`;

exports[`getOptions workflow tag source 2`] = `
Object {
"fallback": "v0.1.0",
"pattern": "^v?(.*)$",
"source": "workflow-tag",
}
`;
6 changes: 6 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare namespace NodeJS {
export interface ProcessEnv {
GITHUB_REF_NAME: string
GITHUB_REF_TYPE: string
}
}
16 changes: 0 additions & 16 deletions src/extract.ts

This file was deleted.

Loading

0 comments on commit d18fd86

Please sign in to comment.