Skip to content

Commit

Permalink
feat: added ability to use the "extends" settings
Browse files Browse the repository at this point in the history
This is done to be able to use shared configurations

docs: Added docs for the extends feature

fix: syntax error, due to rebase
  • Loading branch information
FlippAre committed Apr 29, 2020
1 parent 62fd14b commit 32db8a4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 31 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
|:-------------------------:|---|
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 14 additions & 0 deletions src/handleOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 11 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/inputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"branches": "branches",
"branch": "branch",
"extra_plugins": "extra_plugins",
"dry_run": "dry_run"
"dry_run": "dry_run",
"extends": "extends"
}
21 changes: 21 additions & 0 deletions src/preInstall.task.js
Original file line number Diff line number Diff line change
@@ -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);
};
26 changes: 0 additions & 26 deletions src/preInstallPlugins.task.js

This file was deleted.

0 comments on commit 32db8a4

Please sign in to comment.