mirror of
https://github.com/cycjimmy/semantic-release-action.git
synced 2025-11-07 10:46:56 +00:00
feat: added ability to use the "extends" settings
This is done to be able to use shared configurations docs: Added docs for the extends feature fix: syntax error, due to rebase
This commit is contained in:
parent
62fd14bc6c
commit
32db8a49b2
7 changed files with 71 additions and 31 deletions
21
README.md
21
README.md
|
|
@ -36,6 +36,7 @@ If you are using this action for protected branches, replace `GITHUB_TOKEN` with
|
|||
| branch | false | The branch on which releases should happen.[[Details](#branch)]<br>Only support for **semantic-release older than v16**. |
|
||||
| extra_plugins | false | Extra plugins for pre-install. [[Details](#extra_plugins)] |
|
||||
| dry_run | false | Whether to run semantic release in `dry-run` mode. [[Details](#dry_run)] |
|
||||
| extends | false | Use a sharable configuration [[Details](#extends)] |
|
||||
|
||||
#### semantic_version
|
||||
> {Optional Input Parameter} Specify specifying version range for semantic-release.<br>If no version range is specified, latest version will be used by default.
|
||||
|
|
@ -173,6 +174,26 @@ steps:
|
|||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
```
|
||||
|
||||
#### extends
|
||||
The action can be used with `extends` option to extend an existing [sharable configuration](https://semantic-release.gitbook.io/semantic-release/usage/shareable-configurations) of semantic-release. Can be used in combination with `extra_plugins`.
|
||||
|
||||
_github-action_
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Semantic Release
|
||||
uses: cycjimmy/semantic-release-action@v2
|
||||
with:
|
||||
# You can specify specifying version range for the extra plugins if you prefer.
|
||||
extends: |
|
||||
@semantic-release/apm-config
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
```
|
||||
|
||||
### Outputs
|
||||
| Output Parameter | Description |
|
||||
|:-------------------------:|---|
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ inputs:
|
|||
dry_run:
|
||||
required: false
|
||||
description: 'Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file'
|
||||
extends:
|
||||
description: 'One or several sharable configurations, https://semantic-release.gitbook.io/semantic-release/usage/configuration#extends'
|
||||
outputs:
|
||||
new_release_published:
|
||||
description: 'Whether a new release was published'
|
||||
|
|
|
|||
|
|
@ -59,3 +59,17 @@ exports.handleDryRunOption = () => {
|
|||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle Extends Option
|
||||
* @returns {{}|{extends: Array}|{extends: String}}
|
||||
*/
|
||||
exports.handleExtends = () => {
|
||||
const extend = core.getInput(inputs.extends);
|
||||
|
||||
if (extend) {
|
||||
return { extends: extend };
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
15
src/index.js
15
src/index.js
|
|
@ -1,10 +1,15 @@
|
|||
const core = require('@actions/core');
|
||||
const {handleBranchesOption, handleDryRunOption} = require('./handleOptions');
|
||||
const {
|
||||
handleBranchOption,
|
||||
handleDryRunOption,
|
||||
handleExtends
|
||||
} = require('./handleOptions');
|
||||
const setUpJob = require('./setUpJob.task');
|
||||
const installSpecifyingVersionSemantic = require('./installSpecifyingVersionSemantic.task');
|
||||
const preInstallPlugins = require('./preInstallPlugins.task');
|
||||
const preInstall = require('./preInstall.task');
|
||||
const cleanupNpmrc = require('./cleanupNpmrc.task');
|
||||
const windUpJob = require('./windUpJob.task');
|
||||
const inputs = require('./inputs.json');
|
||||
|
||||
/**
|
||||
* Release main task
|
||||
|
|
@ -13,12 +18,14 @@ const windUpJob = require('./windUpJob.task');
|
|||
const release = async () => {
|
||||
await setUpJob();
|
||||
await installSpecifyingVersionSemantic();
|
||||
await preInstallPlugins();
|
||||
await preInstall(core.getInput(inputs.extra_plugins));
|
||||
await preInstall(core.getInput(inputs.extends));
|
||||
|
||||
const semanticRelease = require('semantic-release');
|
||||
const result = await semanticRelease({
|
||||
...(handleBranchesOption()),
|
||||
...(handleBranchOption()),
|
||||
...(handleDryRunOption()),
|
||||
...(handleExtends()),
|
||||
});
|
||||
|
||||
await cleanupNpmrc();
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@
|
|||
"branches": "branches",
|
||||
"branch": "branch",
|
||||
"extra_plugins": "extra_plugins",
|
||||
"dry_run": "dry_run"
|
||||
"dry_run": "dry_run",
|
||||
"extends": "extends"
|
||||
}
|
||||
|
|
|
|||
21
src/preInstall.task.js
Normal file
21
src/preInstall.task.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const path = require('path');
|
||||
const core = require('@actions/core');
|
||||
const exec = require('./_exec');
|
||||
|
||||
/**
|
||||
* Pre-install extra dependecies
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
module.exports = async extras => {
|
||||
if (!extras) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const _extras = extras.replace(/['"]/g, '').replace(/[\n\r]/g, ' ');
|
||||
|
||||
const { stdout, stderr } = await exec(`npm install ${_extras}`, {
|
||||
cwd: path.resolve(__dirname, '..')
|
||||
});
|
||||
core.debug(stdout);
|
||||
core.error(stderr);
|
||||
};
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
const path = require('path');
|
||||
const core = require('@actions/core');
|
||||
const exec = require('./_exec');
|
||||
const inputs = require('./inputs.json');
|
||||
|
||||
/**
|
||||
* Pre-install plugins
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
module.exports = async () => {
|
||||
const extraPlugins = core.getInput(inputs.extra_plugins);
|
||||
|
||||
if (!extraPlugins) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const _extraPlugins = extraPlugins
|
||||
.replace(/['"]/g, '')
|
||||
.replace(/[\n\r]/g, ' ');
|
||||
|
||||
const {stdout, stderr} = await exec(`npm install ${_extraPlugins}`, {
|
||||
cwd: path.resolve(__dirname, '..')
|
||||
});
|
||||
core.debug(stdout);
|
||||
core.error(stderr);
|
||||
};
|
||||
Loading…
Reference in a new issue