feat!: tag released

This commit is contained in:
marcin 2023-03-28 16:34:14 +01:00
parent f9d3daa396
commit 0735972145
No known key found for this signature in database
GPG key ID: 524860A885021BCB
33 changed files with 216 additions and 42 deletions

12
.github/workflows/lint_commits.yml vendored Normal file
View file

@ -0,0 +1,12 @@
name: Lint Commit Messages
on: [pull_request]
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v5.0.2

25
.github/workflows/pr_title_lint.yml vendored Normal file
View file

@ -0,0 +1,25 @@
# https://github.com/marketplace/actions/conventional-pr-title
# This is a Github Action that ensures that your PR title matches the Conventional Commits spec.
#
# This is helpful when you're using semantic-release with the Conventional Commits preset.
# When using the Squash and merge strategy, Github will suggest to use the PR title as the commit message.
# With this action you can validate that the PR title will lead to a correct commit message.
name: PR Title Lint
on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: aslafy-z/conventional-pr-title-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

11
.github/workflows/pre_commit.yml vendored Normal file
View file

@ -0,0 +1,11 @@
name: pre-commit
on: [push]
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0

57
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,57 @@
name: Release
on:
push:
branches:
- 'master'
jobs:
create:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Calculate semantic version
id: version
uses: 3h4x/semantic-version@master
with:
tag_prefix: "v"
major_pattern: "/^(feat|refactor)!:/"
minor_pattern: "/^(feat|refactor):/"
version_format: "${major}.${minor}.${patch}"
bump_each_commit: false
search_commit_body: false
user_format_type: "json"
- name: Push tag
run: |
git tag v${{ steps.version.outputs.version }}
git push origin v${{ steps.version.outputs.version }}
- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: v${{ steps.version.outputs.version }}
- name: Create Release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
draft: false
name: v${{ steps.version.outputs.version }}
tag: v${{ steps.version.outputs.version }}
body: ${{ steps.changelog.outputs.changes }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: master
commit_message: "build(release): update CHANGELOG.md for v${{ steps.version.outputs.version }} [skip ci]"
file_pattern: CHANGELOG.md

8
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,8 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.1.1
hooks:
- id: trailing-whitespace
exclude: ^version.json

8
dist/index.js vendored
View file

@ -254,6 +254,7 @@ class DefaultTagFormatter {
this.namespace = config.namespace;
this.tagPrefix = config.tagPrefix;
this.namespaceSeperator = '-'; // maybe make configurable in the future
this.prereleaseName = config.prereleaseName;
}
Format(versionInfo) {
const result = `${this.tagPrefix}${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`;
@ -266,6 +267,9 @@ class DefaultTagFormatter {
if (!!this.namespace) {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]${this.namespaceSeperator}${this.namespace}`;
}
if (!!this.prereleaseName) {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]-${this.prereleaseName}.*[0-9]`;
}
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
}
Parse(tag) {
@ -297,6 +301,9 @@ class DefaultTagFormatter {
if (!!this.namespace) {
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+${namespaceSeperator}${namespace}$`).test(tag);
}
if (!!this.prereleaseName) {
return new RegExp(`^${this.tagPrefix}[0-9]+\.[0-9]+\.[0-9]+-${this.prereleaseName}\.[0-9]+$`).test(tag);
}
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+$`).test(tag);
}
}
@ -434,6 +441,7 @@ function run() {
searchCommitBody: core.getInput('search_commit_body') === 'true',
userFormatType: core.getInput('user_format_type'),
enablePrereleaseMode: core.getInput('enable_prerelease_mode') === 'true',
prereleaseName: core.getInput('prerelease_name'),
};
if (config.versionFormat === '' && core.getInput('format') !== '') {
core.warning(`The 'format' input is deprecated, use 'versionFormat' instead`);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -32,6 +32,8 @@ class ActionConfig {
this.userFormatType = "csv";
/** Prevents pre-v1.0.0 version from automatically incrementing the major version. If enabled, when the major version is 0, major releases will be treated as minor and minor as patch. Note that the versionType output is unchanged. */
this.enablePrereleaseMode = false;
/** Prerelease name. If set, the version will be suffixed with the prerelease name and increment. */
this.prereleaseName = "";
}
}
exports.ActionConfig = ActionConfig;

View file

@ -7,6 +7,7 @@ class DefaultTagFormatter {
this.namespace = config.namespace;
this.tagPrefix = config.tagPrefix;
this.namespaceSeperator = '-'; // maybe make configurable in the future
this.prereleaseName = config.prereleaseName;
}
Format(versionInfo) {
const result = `${this.tagPrefix}${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`;
@ -19,6 +20,9 @@ class DefaultTagFormatter {
if (!!this.namespace) {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]${this.namespaceSeperator}${this.namespace}`;
}
if (!!this.prereleaseName) {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]-${this.prereleaseName}.*[0-9]`;
}
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
}
Parse(tag) {
@ -50,6 +54,9 @@ class DefaultTagFormatter {
if (!!this.namespace) {
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+${namespaceSeperator}${namespace}$`).test(tag);
}
if (!!this.prereleaseName) {
return new RegExp(`^${this.tagPrefix}[0-9]+\.[0-9]+\.[0-9]+-${this.prereleaseName}\.[0-9]+$`).test(tag);
}
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+$`).test(tag);
}
}

View file

@ -78,6 +78,7 @@ function run() {
searchCommitBody: core.getInput('search_commit_body') === 'true',
userFormatType: core.getInput('user_format_type'),
enablePrereleaseMode: core.getInput('enable_prerelease_mode') === 'true',
prereleaseName: core.getInput('prerelease_name'),
};
if (config.versionFormat === '' && core.getInput('format') !== '') {
core.warning(`The 'format' input is deprecated, use 'versionFormat' instead`);

View file

@ -104,6 +104,9 @@ it will be given the new version if the build were to be retriggered, for exampl
# Prevents pre-v1.0.0 version from automatically incrementing the major version.
# If enabled, when the major version is 0, major releases will be treated as minor and minor as patch. Note that the version_type output is unchanged.
enable_prerelease_mode: true
# Fetches tags not from releases like v1.4.0 but from prereleases with suffix specified like v1.4.0-rc.0
# For example "rc."
prerelease_name: ""
```
## Outputs

View file

@ -28,4 +28,6 @@ export class ActionConfig {
public userFormatType: string = "csv";
/** Prevents pre-v1.0.0 version from automatically incrementing the major version. If enabled, when the major version is 0, major releases will be treated as minor and minor as patch. Note that the versionType output is unchanged. */
public enablePrereleaseMode: boolean = false;
/** Prerelease name. If set, the version will be suffixed with the prerelease name and increment. */
public prereleaseName: string = "";
}

View file

@ -8,11 +8,13 @@ export class DefaultTagFormatter implements TagFormatter {
private tagPrefix: string;
private namespace: string;
private namespaceSeperator: string;
private prereleaseName: string;
constructor(config: ActionConfig) {
this.namespace = config.namespace;
this.tagPrefix = config.tagPrefix;
this.namespaceSeperator = '-'; // maybe make configurable in the future
this.prereleaseName = config.prereleaseName;
}
public Format(versionInfo: VersionInformation): string {
@ -31,6 +33,10 @@ export class DefaultTagFormatter implements TagFormatter {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]${this.namespaceSeperator}${this.namespace}`;
}
if (!!this.prereleaseName) {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]-${this.prereleaseName}.*[0-9]`;
}
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
}
@ -71,6 +77,10 @@ export class DefaultTagFormatter implements TagFormatter {
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+${namespaceSeperator}${namespace}$`).test(tag);
}
if (!!this.prereleaseName) {
return new RegExp(`^${this.tagPrefix}[0-9]+\.[0-9]+\.[0-9]+-${this.prereleaseName}\.[0-9]+$`).test(tag);
}
return new RegExp(`^${tagPrefix}[0-9]+\.[0-9]+\.[0-9]+$`).test(tag);
}
}

View file

@ -60,6 +60,33 @@ const execute = (workingDirectory: string, command: string, env?: any) => {
}
};
test('Prerelease is detected and tagged correctly', async () => {
const repo = createTestRepo({ tagPrefix: 'v', versionFormat: "${major}.${minor}.${patch}-rc.${increment}", prereleaseName: "rc" });
repo.makeCommit('Initial Commit');
repo.exec('git tag v1.0.0-rc.0');
var result = await repo.runAction();
expect(result.formattedVersion).toBe('1.0.0-rc.0');
expect(result.isTagged).toBe(true);
repo.makeCommit('Second Commit');
result = await repo.runAction();
expect(result.formattedVersion).toBe('1.0.1-rc.0')
expect(result.isTagged).toBe(false);
repo.makeCommit('Third Commit (MINOR)');
result = await repo.runAction();
expect(result.formattedVersion).toBe('1.1.0-rc.0');
expect(result.isTagged).toBe(false);
repo.makeCommit('Fourth Commit (MINOR)');
repo.exec('git tag v1.1.0-rc.0')
result = await repo.runAction();
console.log(result.formattedVersion)
expect(result.formattedVersion).toBe('1.1.0-rc.1');
expect(result.isTagged).toBe(true);
}, timeout);
test('Empty repository version is correct', async () => {
const repo = createTestRepo(); // 0.0.0+0
var result = await repo.runAction();

View file

@ -51,6 +51,7 @@ export async function run() {
searchCommitBody: core.getInput('search_commit_body') === 'true',
userFormatType: core.getInput('user_format_type'),
enablePrereleaseMode: core.getInput('enable_prerelease_mode') === 'true',
prereleaseName: core.getInput('prerelease_name'),
};
if (config.versionFormat === '' && core.getInput('format') !== '') {