Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68cd6ad

Browse files
committed
feat: add additional_packages input variable
Allows users to install non-standard plugins and shareable configuration packages for use in their `plugins` and `extends` without having the install those dependencies in their own applications. Closes #168
1 parent 4e9fa8e commit 68cd6ad

File tree

6 files changed

+732
-2007
lines changed

6 files changed

+732
-2007
lines changed

.github/workflows/validate.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ jobs:
4040
]
4141
repository_url: https://github.com/codfish/semantic-release-action.git
4242
tag_format: 'v${version}'
43+
extends: '@semantic-release/apm-config'
44+
additional_packages: |
45+
['@semantic-release/[email protected]', '@semantic-release/git', '@semantic-release/apm-config']
4346
plugins: |
44-
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/npm', '@semantic-release/github']
47+
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/github', '@semantic-release/apm', '@semantic-release/git']
4548
env:
4649
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4750

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,28 @@ I can easily leverage it across any project.
181181

182182
You can pass in `semantic-release` configuration options via GitHub Action inputs using `with`.
183183

184-
It's important to note, **NONE** of these inputs are required. The action will automatically use any
184+
It's important to note, **NONE** of these inputs are required. Semantic release has a default configuration that it will use if you don't provide any.
185+
186+
Also of note, if you'd like to override the default configuration and you'd rather not use the inputs here, the action will automatically use any
185187
[`semantic-release` configuration](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration-file)
186-
found in your repo (`.releaserc`, `release.config.js`, `release` prop in `package.json`)
188+
defined in your repo (`.releaserc`, `release.config.js`, `release` prop in `package.json`)
187189

188190
> **Note**: Each input **will take precedence** over options configured in the configuration file
189191
> and shareable configurations.
190192

191-
| Input Variable | Description |
192-
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
193-
| branches | The branches on which releases should happen. |
194-
| plugins | Define the list of plugins to use. Plugins will run in series, in the order defined, for each steps if they implement it |
195-
| extends | List of modules or file paths containing a shareable configuration. |
196-
| dry_run | The objective of the dry-run mode is to get a preview of the pending release. Dry-run mode skips the following steps: prepare, publish, success and fail. |
197-
| repository_url | The git repository URL |
198-
| tag_format | The Git tag format used by semantic-release to identify releases. |
193+
| Input Variable | Type | Description |
194+
| -------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
195+
| branches | `Array`, `String`, `Object` | The branches on which releases should happen. |
196+
| plugins | `Array` | Define the list of plugins to use. Plugins will run in series, in the order defined, for each steps if they implement it |
197+
| extends | `Array`, `String` | List of modules or file paths containing a shareable configuration. |
198+
| additional_packages | `Array`, `String` | Define a list of additional plugins/configurations (official or community) to install. Use this if you 1) use any plugins other than the defaults, which are already installed along with semantic-release or 2) want to extend from a shareable configuration. |
199+
| dry_run | `Boolean` | The objective of the dry-run mode is to get a preview of the pending release. Dry-run mode skips the following steps: prepare, publish, success and fail. |
200+
| repository_url | `String` | The git repository URL |
201+
| tag_format | `String` | The Git tag format used by semantic-release to identify releases. |
202+
203+
> **Note**: `additional_packages` won't get used automatically, setting this variable will just install them so you can use them. You'll need to actually list them in your `plugins` and/or `extends` configuration for **semantic-release** to use them.
199204

200-
**Note**: The `branch` input is **DEPRECATED**. Will continue to be supported for v1. Use `branches`
205+
> **Note**: The `branch` input is **DEPRECATED**. Will continue to be supported for v1. Use `branches`
201206
instead. Previously used in semantic-release v15 to set a single branch on which releases should
202207
happen.
203208

@@ -231,8 +236,10 @@ steps:
231236
repository_url: https://github.com/codfish/semantic-release-action.git
232237
tag_format: 'v${version}'
233238
extends: '@semantic-release/apm-config'
239+
additional_packages: |
240+
['@semantic-release/[email protected]', '@semantic-release/git', '@semantic-release/apm-config']
234241
plugins: |
235-
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/npm', '@semantic-release/github']
242+
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/github', '@semantic-release/apm', '@semantic-release/git']
236243
env:
237244
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
238245
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

action.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ inputs:
1212
'The branches on which releases should happen.
1313
https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches'
1414
required: false
15+
extends:
16+
description:
17+
'List of modules or file paths containing .
18+
https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#extends'
19+
required: false
1520
plugins:
1621
description:
1722
'Define the list of plugins to use. Plugins will run in series, in the order defined, for each
1823
steps if they implement it.
1924
https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#plugins'
2025
required: false
21-
extends:
26+
additional_packages:
2227
description:
23-
'List of modules or file paths containing a shareable configuration.
24-
https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#extends'
28+
'Define a list of additional plugins or shareable configurations (official or community) to
29+
install. Use this if you 1) use any plugins other than commit-analyzer, release-notes-generator,
30+
github, or npm, which are already installed along with semantic-release or 2) want to extend
31+
from a shareable configuration.
32+
https://semantic-release.gitbook.io/semantic-release/extending/plugins-list'
2533
required: false
2634
dry_run:
2735
description:

entrypoint.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
const { spawnSync } = require('child_process');
12
const core = require('@actions/core');
23
const semanticRelease = require('semantic-release');
34
const JSON5 = require('json5');
5+
const arrify = require('arrify');
46

57
const parseInput = input => {
68
try {
@@ -10,6 +12,26 @@ const parseInput = input => {
1012
}
1113
};
1214

15+
/**
16+
* Install npm packages.
17+
*
18+
* @param {string|string[]} packages - List of packages to install.
19+
* @returns {object} - Response from `child_process.spawnSync()`.
20+
*/
21+
const installPackages = packages => {
22+
try {
23+
const packagesArr = arrify(packages);
24+
core.debug(`Installing additional packages: ${packagesArr}`);
25+
const result = spawnSync('npm', ['install', '--save-dev', ...packagesArr]);
26+
core.debug(`Packages installed.`);
27+
core.debug(result);
28+
return result;
29+
} catch (err) {
30+
core.debug(`Error installing additional packages: ${packages}`);
31+
throw err;
32+
}
33+
};
34+
1335
/**
1436
* Run semantic-release.
1537
*
@@ -20,6 +42,7 @@ async function run() {
2042
const branch = parseInput(core.getInput('branch', { required: false }));
2143
const branches = parseInput(core.getInput('branches', { required: false }));
2244
const plugins = parseInput(core.getInput('plugins', { required: false }));
45+
const additionalPackages = parseInput(core.getInput('additional_packages', { required: false }));
2346
const extendsInput = parseInput(core.getInput('extends', { required: false }));
2447
let dryRun = core.getInput('dry_run', { required: false });
2548
dryRun = dryRun !== '' ? dryRun === 'true' : '';
@@ -34,6 +57,11 @@ async function run() {
3457
core.debug(`repository_url input: ${repositoryUrl}`);
3558
core.debug(`tag_format input: ${tagFormat}`);
3659

60+
// install additional packages
61+
if (additionalPackages) {
62+
installPackages(additionalPackages);
63+
}
64+
3765
// build options object
3866
const branchOption = branch ? { branches: branch } : { branches };
3967
const options = {

0 commit comments

Comments
 (0)