-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Generate Semantic Version aliases from SemVer (#1)
* feat: Generate Semantic Version aliases from SemVer * ci: Tag releases with major and minor aliases * ci: Run tests on Pull Request, not Push * docs: Brand action with 🏷️
- Loading branch information
Showing
24 changed files
with
22,762 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{js,json,ts,yml}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist/ | ||
lib/ | ||
node_modules/ | ||
jest.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"plugins": ["jest", "@typescript-eslint"], | ||
"extends": ["plugin:github/recommended"], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 9, | ||
"sourceType": "module", | ||
"project": "./tsconfig.json" | ||
}, | ||
"rules": { | ||
"eslint-comments/no-use": "off", | ||
"import/no-namespace": "off", | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": "error", | ||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}], | ||
"@typescript-eslint/no-require-imports": "error", | ||
"@typescript-eslint/array-type": "error", | ||
"@typescript-eslint/await-thenable": "error", | ||
"@typescript-eslint/ban-ts-comment": "error", | ||
"camelcase": "off", | ||
"@typescript-eslint/consistent-type-assertions": "error", | ||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}], | ||
"@typescript-eslint/func-call-spacing": ["error", "never"], | ||
"@typescript-eslint/no-array-constructor": "error", | ||
"@typescript-eslint/no-empty-interface": "error", | ||
"@typescript-eslint/no-explicit-any": "error", | ||
"@typescript-eslint/no-extraneous-class": "error", | ||
"@typescript-eslint/no-for-in-array": "error", | ||
"@typescript-eslint/no-inferrable-types": "error", | ||
"@typescript-eslint/no-misused-new": "error", | ||
"@typescript-eslint/no-namespace": "error", | ||
"@typescript-eslint/no-non-null-assertion": "warn", | ||
"@typescript-eslint/no-unnecessary-qualifier": "error", | ||
"@typescript-eslint/no-unnecessary-type-assertion": "error", | ||
"@typescript-eslint/no-useless-constructor": "error", | ||
"@typescript-eslint/no-var-requires": "error", | ||
"@typescript-eslint/prefer-for-of": "warn", | ||
"@typescript-eslint/prefer-function-type": "warn", | ||
"@typescript-eslint/prefer-includes": "error", | ||
"@typescript-eslint/prefer-string-starts-ends-with": "error", | ||
"@typescript-eslint/promise-function-async": "error", | ||
"@typescript-eslint/require-array-sort-compare": "error", | ||
"@typescript-eslint/restrict-plus-operands": "error", | ||
"semi": "off", | ||
"@typescript-eslint/semi": ["error", "never"], | ||
"@typescript-eslint/type-annotation-spacing": "error", | ||
"@typescript-eslint/unbound-method": "error" | ||
}, | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"jest/globals": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/** -diff linguist-generated=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: 'Tag With Aliases' | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
|
||
jobs: | ||
aliases: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: haya14busa/action-update-semver@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: 'tests' | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: npm install | ||
- run: npm run all | ||
assert: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- id: major | ||
uses: ./ | ||
with: | ||
version: '3.14.1' | ||
prefix: v | ||
major: true | ||
minor: false | ||
patch: false | ||
|
||
- id: minor | ||
uses: ./ | ||
with: | ||
version: '3.14.1' | ||
prefix: v | ||
major: false | ||
minor: true | ||
patch: false | ||
|
||
- id: patch | ||
uses: ./ | ||
with: | ||
version: '3.14.1' | ||
prefix: v | ||
major: false | ||
minor: false | ||
patch: true | ||
|
||
- id: all | ||
uses: ./ | ||
with: | ||
version: '3.14.1' | ||
prefix: v | ||
major: true | ||
minor: true | ||
patch: true | ||
|
||
- run: echo "${{ steps.all.outputs.list }}" | ||
|
||
- id: none | ||
uses: ./ | ||
with: | ||
version: '3.14.1' | ||
prefix: v | ||
major: false | ||
minor: false | ||
patch: false | ||
|
||
- uses: nick-invision/assert-action@v1 | ||
with: | ||
expected: 'v3' | ||
actual: ${{ steps.major.outputs.csv }} | ||
|
||
- uses: nick-invision/assert-action@v1 | ||
with: | ||
expected: 'v3.14' | ||
actual: ${{ steps.minor.outputs.csv }} | ||
|
||
- uses: nick-invision/assert-action@v1 | ||
with: | ||
expected: 'v3.14.1' | ||
actual: ${{ steps.patch.outputs.csv }} | ||
|
||
- uses: nick-invision/assert-action@v1 | ||
with: | ||
expected: 'v3,v3.14,v3.14.1' | ||
actual: ${{ steps.all.outputs.csv }} | ||
|
||
- uses: nick-invision/assert-action@v1 | ||
with: | ||
expected: | | ||
v3 | ||
v3.14 | ||
v3.14.1 | ||
actual: ${{ steps.all.outputs.list }} | ||
|
||
- uses: nick-invision/assert-action@v1 | ||
with: | ||
expected: | ||
actual: ${{ steps.none.outputs.csv }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: 'validate' | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
is-packaged: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- id: dist | ||
env: | ||
BUILD_HASH: ${{ hashFiles('dist') }} | ||
run: echo "::set-output name=hash::$BUILD_HASH" | ||
- run: npm install | ||
- run: npm run all | ||
- if: ${{ steps.dist.outputs.hash != hashFiles('dist') }} | ||
run: | | ||
echo "::error::Action must be packaged (use 'npm run package' locally)" | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/lib | ||
/node_modules | ||
npm-debug.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist/ | ||
lib/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"bracketSpacing": false, | ||
"arrowParens": "avoid" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2021 > LIMITED and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SemVer Aliases | ||
|
||
A GitHub Action for generating the major and minor aliases of a | ||
[Semantic Version][semver]: generate `v3` and `v3.14` from `v3.14.1`. | ||
|
||
``` | ||
pr-mpt/actions-semver-aliases@v1 | ||
``` | ||
|
||
## Inputs | ||
|
||
| ID | Description | Default | Examples | | ||
| ---- | ----------- | ------- | -------- | | ||
| **`version`** | **Semantic Version number** | **<kbd>required</kbd>** | **`v1.2.3` `1.2.3`** | | ||
| `prefix` | String prefixed before each alias | `v` | `v` `app-` | | ||
| `major` | Generate major version alias | `true` | | | ||
| `minor` | Generate minor version alias | `true` | | | ||
| `patch` | Generate patch version alias | `false` | | | ||
|
||
## Outputs | ||
|
||
| ID | Description | Examples | | ||
| ---- | --------- | -------- | | ||
| `list` | Newline separated string of aliases | ```v1\nv1.2``` | | ||
| `csv` | Comma-separated string of aliases | `v1,v1.2` | | ||
|
||
[semver]: https://semver.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import {generateVersionAliases, AliasOptions} from '../src/aliases' | ||
|
||
describe('alias generator', () => { | ||
test('throws error when given non-semver version', () => { | ||
const options: AliasOptions = {major: true, minor: false, patch: false} | ||
|
||
expect(() => { | ||
generateVersionAliases('invalid-version', 'prefix', options) | ||
}).toThrow(TypeError) | ||
}) | ||
|
||
test('generates version alias with prefix', async () => { | ||
const options: AliasOptions = {major: true, minor: false, patch: false} | ||
|
||
const aliases: String[] = generateVersionAliases('1.0.0', 'prefix', options) | ||
|
||
expect(aliases).toStrictEqual(['prefix1']) | ||
}) | ||
|
||
test('generates major version alias', async () => { | ||
const options: AliasOptions = {major: true, minor: false, patch: false} | ||
|
||
const aliases: String[] = generateVersionAliases('1.2.3', 'v', options) | ||
|
||
expect(aliases).toStrictEqual(['v1']) | ||
}) | ||
|
||
test('generates minor version alias', async () => { | ||
const options: AliasOptions = {major: false, minor: true, patch: false} | ||
|
||
const aliases: String[] = generateVersionAliases('1.2.3', 'v', options) | ||
|
||
expect(aliases).toStrictEqual(['v1.2']) | ||
}) | ||
|
||
test('generates major + minor version aliases', async () => { | ||
const options: AliasOptions = {major: true, minor: true, patch: false} | ||
|
||
const aliases: String[] = generateVersionAliases('1.2.3', 'v', options) | ||
|
||
expect(aliases).toStrictEqual(['v1', 'v1.2']) | ||
}) | ||
|
||
test('generates major + minor + patch version aliases', async () => { | ||
const options: AliasOptions = {major: true, minor: true, patch: true} | ||
|
||
const aliases: String[] = generateVersionAliases('1.2.3', 'v', options) | ||
|
||
expect(aliases).toStrictEqual(['v1', 'v1.2', 'v1.2.3']) | ||
}) | ||
|
||
test('generates no version aliases', async () => { | ||
const options: AliasOptions = {major: false, minor: false, patch: false} | ||
|
||
const aliases: String[] = generateVersionAliases('1.0.0', 'v', options) | ||
|
||
expect(aliases).toStrictEqual([]) | ||
}) | ||
|
||
test('generates no version aliases for prereleases', async () => { | ||
const options: AliasOptions = {major: true, minor: true, patch: true} | ||
|
||
const aliases: String[] = generateVersionAliases( | ||
'1.0.0-alpha.1', | ||
'v', | ||
options | ||
) | ||
|
||
expect(aliases).toStrictEqual([]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: 'Semantic Version (SemVer) Aliases' | ||
branding: | ||
icon: 'tag' | ||
color: 'gray-dark' | ||
description: 'Generate release aliases for a Semantic Version' | ||
author: 'Samuel Ryan <[email protected]>' | ||
inputs: | ||
version: | ||
required: true | ||
description: 'Semantic Version to generate aliases for' | ||
prefix: | ||
required: false | ||
description: 'String to prepend to front of each alias' | ||
default: 'v' | ||
major: | ||
required: false | ||
description: 'Should the major version (e.g: 1) be included in the aliases?' | ||
default: true | ||
minor: | ||
required: false | ||
description: 'Should the minor version (e.g: 1.1) be included in the aliases?' | ||
default: true | ||
patch: | ||
required: false | ||
description: 'Should the patch version (e.g: 1.1.1) be included in the aliases?' | ||
default: false | ||
outputs: | ||
list: | ||
description: 'Newline separated string of aliases' | ||
csv: | ||
description: 'Comma-separated string of aliases' | ||
runs: | ||
using: 'node12' | ||
main: 'dist/index.js' |
Oops, something went wrong.