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

Parse Release Tag Action #40

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions parse-release-tag/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
56 changes: 56 additions & 0 deletions parse-release-tag/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"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",
"no-console": "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": "off",
"@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": ["error", "always"],
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error",
"i18n-text/no-en": "off"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
4 changes: 4 additions & 0 deletions parse-release-tag/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
lib/
node_modules/
*.yml
10 changes: 10 additions & 0 deletions parse-release-tag/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 120,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid"
}
41 changes: 41 additions & 0 deletions parse-release-tag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Parse a Release Tag

This action will take a release tag string as input and produce the following output:

1. `package-name`: the name of the package, or `realm` if not set.
2. `package-version`: the version string (10.9.8).
3. `package-version-suffix`: the prerelease suffix of the version tag
4. `prerelease`: set to `true` if a version suffix (`-<something>`) is appended to the tag.
```

For example, the tag "my-package-v42.0.0-alpha.1 would return:
```
package-name: "my-package",
package-version: "42.0.0"
package-version-suffix: "-alpha.1"
prerelease: true
```

and the tag "v42.0.0" would return:
```
package-name: "realm"
package-version: "42.0.0"
package-version-suffix: undefined
prerelease: false
```

## Usage

```yaml
- name: Parse Release Tag
id: parse-release-tag
uses: realm/ci-actions/andrew/parse-release-tag
with:
release-tag: ${{ github.workspace }}/CHANGELOG.md
- name: Print result version
run: |
echo ${{ steps.parse-release-tag.outputs.package-name }}
echo ${{ steps.update-changelog.outputs.package-version }}
echo ${{ steps.update-changelog.outputs.package-version-suffix }}
echo ${{ steps.update-changelog.outputs.prerelease }}
```
47 changes: 47 additions & 0 deletions parse-release-tag/__tests__/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { expect } from "chai";
import { parseReleaseTag } from "../src/helpers";

describe("parseReleaseTag", () => {
it("should parse a valid release tag", () => {
const releaseTag = "my-package-v1.0.0";
const parsedReleaseTag = parseReleaseTag(releaseTag);
console.log(parsedReleaseTag);
expect(parsedReleaseTag).deep.equal({
packageName: "my-package",
packageVersion: "1.0.0",
packageVersionSuffix: undefined,
prerelease: false,
});

const prereleaseReleaseTag = "my-package-v1.0.0-alpha.1";
const parsedPrereleaseReleaseTag = parseReleaseTag(prereleaseReleaseTag);
expect(parsedPrereleaseReleaseTag).deep.equal({
packageName: "my-package",
packageVersion: "1.0.0",
packageVersionSuffix: "-alpha.1",
prerelease: true,
});

const releaseTagWithoutPackage = "v1.0.0";
const parsedReleaseTagWithoutPackage = parseReleaseTag(releaseTagWithoutPackage);
expect(parsedReleaseTagWithoutPackage).deep.equal({
packageName: "realm",
packageVersion: "1.0.0",
packageVersionSuffix: undefined,
prerelease: false,
});

const releaseTagWithoutPackageWithSuffix = "v1.0.0-alpha.1";
const parsedReleaseTagWithoutPackageWithSuffix = parseReleaseTag(releaseTagWithoutPackageWithSuffix);
expect(parsedReleaseTagWithoutPackageWithSuffix).deep.equal({
packageName: "realm",
packageVersion: "1.0.0",
packageVersionSuffix: "-alpha.1",
prerelease: true,
});
});
it("should throw an error when given an invalid release tag", () => {
const releaseTag = "my-package-1.0.0";
expect(() => parseReleaseTag(releaseTag)).to.throw("Invalid release tag: my-package-1.0.0");
});
});
19 changes: 19 additions & 0 deletions parse-release-tag/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: parse-release-tag
description: Parse a release tag into its components
author: Realm
inputs:
release-tag:
required: true
description: release tag to parse of the format (<package-name>-v<x.y.z>-<suffix>)
outputs:
package-name:
description: The name of the package
package-version:
description: The complete version string of the package, including the suffix if included
package-version-suffix:
description: The version suffix
prerelease:
description: Set to `true` if the version suffix is found
runs:
using: node16
main: dist/index.js
Loading