mirror of
https://github.com/cycjimmy/semantic-release-action.git
synced 2025-11-09 19:56:55 +00:00
Merge pull request #26 from cycjimmy/feat/support-branches-of-semantic-release-v16+
Feat/support branches of semantic release v16+
This commit is contained in:
commit
f02d900782
8 changed files with 162 additions and 26 deletions
69
.github/workflows/testRelease.yml
vendored
69
.github/workflows/testRelease.yml
vendored
|
|
@ -4,27 +4,51 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- master
|
||||
- next
|
||||
- next-major
|
||||
- next-major
|
||||
- alpha
|
||||
- beta
|
||||
- 'feat/**'
|
||||
- 'fix/**'
|
||||
- 'perf/**'
|
||||
- 'refactor/**'
|
||||
|
||||
schedule:
|
||||
- cron: 0 2 * * 0
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: release
|
||||
test-semantic-latest:
|
||||
name: test-semantic-latest
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Semantic Release
|
||||
uses: cycjimmy/semantic-release-action@v2
|
||||
uses: ./
|
||||
id: semantic
|
||||
with:
|
||||
dry_run: true
|
||||
branches: |
|
||||
[
|
||||
'+([0-9])?(.{+([0-9]),x}).x',
|
||||
'master',
|
||||
'next',
|
||||
'next-major',
|
||||
{
|
||||
name: 'beta',
|
||||
prerelease: true
|
||||
},
|
||||
{
|
||||
name: 'alpha',
|
||||
prerelease: true
|
||||
}
|
||||
]
|
||||
branch: master
|
||||
extra_plugins: |
|
||||
@semantic-release/git
|
||||
@semantic-release/changelog
|
||||
dry_run: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
|
@ -36,5 +60,40 @@ jobs:
|
|||
echo ${{ steps.semantic.outputs.new_release_major_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_minor_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_patch_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_notes }}
|
||||
|
||||
test-semantic-v15:
|
||||
name: test-semantic-v15
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Semantic Release
|
||||
uses: ./
|
||||
id: semantic_v15
|
||||
with:
|
||||
semantic_version: 15
|
||||
dry_run: true
|
||||
branches: |
|
||||
[
|
||||
'master',
|
||||
{name: 'beta', prerelease: true},
|
||||
{name: 'alpha', prerelease: true}
|
||||
]
|
||||
branch: master
|
||||
extra_plugins: |
|
||||
@semantic-release/git@7
|
||||
@semantic-release/changelog@3
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Test Outputs
|
||||
if: steps.semantic.outputs.new_release_published == 'true'
|
||||
run: |
|
||||
echo ${{ steps.semantic.outputs.new_release_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_major_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_minor_version }}
|
||||
echo ${{ steps.semantic.outputs.new_release_patch_version }}
|
||||
|
||||
|
||||
|
|
|
|||
50
README.md
50
README.md
|
|
@ -17,8 +17,9 @@ GitHub Action for [Semantic Release](https://github.com/semantic-release/semanti
|
|||
|
||||
#### Step3: Add a [Workflow File](https://help.github.com/en/articles/workflow-syntax-for-github-actions) to your repository to create custom automated processes.
|
||||
* inputs:
|
||||
* `branch`: [Optional] The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master.
|
||||
* `semantic_version`: [Optional] Specify specifying version range for semantic-release. If no version range is specified, latest version will be used by default.
|
||||
* `branches`: [Optional] The branches on which releases should happen. It will override the branches attribute in your configuration file. If the attribute is not configured on both sides, the default is `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`. **Support for semantic-release above v16**. See https://semantic-release.gitbook.io/semantic-release/usage/configuration#branches for more information.
|
||||
* `branch`: [Optional] The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master. **Support for semantic-release older than v16**.
|
||||
* `extra_plugins`: [Optional] Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer.
|
||||
* `dry_run`: [Optional] Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file.
|
||||
* outputs:
|
||||
|
|
@ -44,6 +45,53 @@ steps:
|
|||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
```
|
||||
|
||||
#### Setting `semantic_version` and `branch | branches` manually
|
||||
It is recommended to specify specifying version range for semantic-release. If no version range is specified, latest version will be used by default.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Semantic Release
|
||||
uses: cycjimmy/semantic-release-action@v2
|
||||
with:
|
||||
semantic_version: 15.13.28 # It is recommended to specify specifying version range
|
||||
# for semantic-release.
|
||||
branch: master # you can set branch for semantic-release older than v16.
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
```
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Semantic Release
|
||||
uses: cycjimmy/semantic-release-action@v2
|
||||
with:
|
||||
semantic_version: 16
|
||||
# you can set branches for semantic-release above v16.
|
||||
branches: |
|
||||
[
|
||||
'+([0-9])?(.{+([0-9]),x}).x',
|
||||
'master',
|
||||
'next',
|
||||
'next-major',
|
||||
{
|
||||
name: 'beta',
|
||||
prerelease: true
|
||||
},
|
||||
{
|
||||
name: 'alpha',
|
||||
prerelease: true
|
||||
}
|
||||
]
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
```
|
||||
|
||||
#### Passing Extra Plugins with `extra_plugins`
|
||||
|
||||
The action can be used with `extra_plugins` option to specify plugins which are not in the [default list of plugins of semantic release](https://semantic-release.gitbook.io/semantic-release/usage/plugins#default-plugins). When using this option, please make sure that these plugins are also mentioned in your [semantic release config's plugins](https://semantic-release.gitbook.io/semantic-release/usage/configuration#plugins) array. For example, if you want to use `@semantic-release/git` and `@semantic-release/changelog` extra plugins, these must be added to `extra_plugins` in your actions file and `plugins` in your [release config file](https://semantic-release.gitbook.io/semantic-release/usage/configuration#configuration-file) as shown bellow:
|
||||
|
|
|
|||
13
action.yml
13
action.yml
|
|
@ -5,13 +5,20 @@ branding:
|
|||
icon: 'package'
|
||||
color: 'orange'
|
||||
inputs:
|
||||
branch:
|
||||
description: 'The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master.'
|
||||
semantic_version:
|
||||
description: 'Specify specifying version range for semantic-release. If no version range is specified, semantic-release@^15 will be used by default.'
|
||||
required: false
|
||||
description: 'Specify specifying version range for semantic-release. If no version range is specified, latest version will be used by default'
|
||||
branches:
|
||||
required: false
|
||||
description: 'The branches on which releases should happen. It will override the branches attribute in your configuration file. Support for semantic-release above v16. See https://semantic-release.gitbook.io/semantic-release/usage/configuration#branches for more information.'
|
||||
branch:
|
||||
required: false
|
||||
description: 'The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master. Support for semantic-release older than v16.'
|
||||
extra_plugins:
|
||||
required: false
|
||||
description: 'Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer.'
|
||||
dry_run:
|
||||
required: false
|
||||
description: 'Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file'
|
||||
outputs:
|
||||
new_release_published:
|
||||
|
|
|
|||
11
package-lock.json
generated
11
package-lock.json
generated
|
|
@ -5,9 +5,14 @@
|
|||
"requires": true,
|
||||
"dependencies": {
|
||||
"@actions/core": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz",
|
||||
"integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw=="
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.3.tgz",
|
||||
"integrity": "sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w=="
|
||||
},
|
||||
"@cycjimmy/awesome-js-funcs": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@cycjimmy/awesome-js-funcs/-/awesome-js-funcs-2.3.0.tgz",
|
||||
"integrity": "sha512-HXJrv0S1gzjP9h2cmE57m+0XnVsGIsidPEjxUR5i50iGIxbjEe1EhL6iSh2P1LXdjjbt1U/UHj6n93yzDwt1gw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
},
|
||||
"homepage": "https://github.com/cycjimmy/semantic-release-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.0"
|
||||
"@actions/core": "^1.2.3",
|
||||
"@cycjimmy/awesome-js-funcs": "^2.3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,44 @@
|
|||
const core = require('@actions/core');
|
||||
const stringToJson = require('@cycjimmy/awesome-js-funcs/typeConversion/stringToJson').default;
|
||||
const inputs = require('./inputs.json');
|
||||
|
||||
/**
|
||||
* Handle Branch Option
|
||||
* Handle Branches Option
|
||||
* @returns {{}|{branch: string}}
|
||||
*/
|
||||
exports.handleBranchOption = () => {
|
||||
const branchOption = {};
|
||||
exports.handleBranchesOption = () => {
|
||||
const branchesOption = {};
|
||||
const branches = core.getInput(inputs.branches);
|
||||
const branch = core.getInput(inputs.branch);
|
||||
|
||||
if (!branch) {
|
||||
return branchOption;
|
||||
}
|
||||
core.debug(`branches input: ${branches}`);
|
||||
core.debug(`branch input: ${branch}`);
|
||||
|
||||
const semanticVersion = require('semantic-release/package.json').version;
|
||||
const semanticMajorVersion = Number(semanticVersion.replace(/\..+/g, ''));
|
||||
core.debug(`semanticMajorVersion: ${semanticMajorVersion}`);
|
||||
|
||||
// older than v16
|
||||
if (semanticMajorVersion < 16) {
|
||||
branchOption.branch = branch;
|
||||
} else {
|
||||
branchOption.branches = [branch];
|
||||
if (!branch) {
|
||||
return branchesOption;
|
||||
}
|
||||
|
||||
branchesOption.branch = branch;
|
||||
return branchesOption;
|
||||
}
|
||||
|
||||
return branchOption;
|
||||
// above v16
|
||||
const strNeedConvertToJson = branches || branch || '';
|
||||
|
||||
if (!strNeedConvertToJson) {
|
||||
return branchesOption;
|
||||
}
|
||||
|
||||
const jsonOrStr = stringToJson('' + strNeedConvertToJson);
|
||||
core.debug(`Converted branches attribute: ${JSON.stringify(jsonOrStr)}`);
|
||||
branchesOption.branches = jsonOrStr;
|
||||
return branchesOption;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const core = require('@actions/core');
|
||||
const {handleBranchOption, handleDryRunOption} = require('./handleOptions');
|
||||
const {handleBranchesOption, handleDryRunOption} = require('./handleOptions');
|
||||
const setUpJob = require('./setUpJob.task');
|
||||
const installSpecifyingVersionSemantic = require('./installSpecifyingVersionSemantic.task');
|
||||
const preInstallPlugins = require('./preInstallPlugins.task');
|
||||
|
|
@ -17,7 +17,7 @@ const release = async () => {
|
|||
|
||||
const semanticRelease = require('semantic-release');
|
||||
const result = await semanticRelease({
|
||||
...(handleBranchOption()),
|
||||
...(handleBranchesOption()),
|
||||
...(handleDryRunOption()),
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"branch": "branch",
|
||||
"semantic_version": "semantic_version",
|
||||
"branches": "branches",
|
||||
"branch": "branch",
|
||||
"extra_plugins": "extra_plugins",
|
||||
"dry_run": "dry_run"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue