Skip to content

Commit

Permalink
feat: add additional_packages input variable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
codfish committed Aug 7, 2022
1 parent 4e9fa8e commit 892c8c9
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/validate.yml
Expand Up @@ -40,8 +40,11 @@ jobs:
]
repository_url: https://github.com/codfish/semantic-release-action.git
tag_format: 'v${version}'
extends: '@semantic-release/apm-config'
additional_packages: |
['@semantic-release/apm@3.0.0', '@semantic-release/git', '@semantic-release/apm-config']
plugins: |
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/npm', '@semantic-release/github']
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/github', '@semantic-release/apm', '@semantic-release/git']
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
31 changes: 19 additions & 12 deletions README.md
Expand Up @@ -181,23 +181,28 @@ I can easily leverage it across any project.

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

It's important to note, **NONE** of these inputs are required. The action will automatically use any
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.

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
[`semantic-release` configuration](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration-file)
found in your repo (`.releaserc`, `release.config.js`, `release` prop in `package.json`)
defined in your repo (`.releaserc`, `release.config.js`, `release` prop in `package.json`)

> **Note**: Each input **will take precedence** over options configured in the configuration file
> and shareable configurations.
| Input Variable | Description |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| branches | The branches on which releases should happen. |
| plugins | Define the list of plugins to use. Plugins will run in series, in the order defined, for each steps if they implement it |
| extends | List of modules or file paths containing a shareable configuration. |
| 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. |
| repository_url | The git repository URL |
| tag_format | The Git tag format used by semantic-release to identify releases. |
| Input Variable | Type | Description |
| -------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| branches | `Array`, `String`, `Object` | The branches on which releases should happen. |
| 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 |
| extends | `Array`, `String` | List of modules or file paths containing a shareable configuration. |
| 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. |
| 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. |
| repository_url | `String` | The git repository URL |
| tag_format | `String` | The Git tag format used by semantic-release to identify releases. |

> **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.
**Note**: The `branch` input is **DEPRECATED**. Will continue to be supported for v1. Use `branches`
> **Note**: The `branch` input is **DEPRECATED**. Will continue to be supported for v1. Use `branches`
instead. Previously used in semantic-release v15 to set a single branch on which releases should
happen.

Expand Down Expand Up @@ -231,8 +236,10 @@ steps:
repository_url: https://github.com/codfish/semantic-release-action.git
tag_format: 'v${version}'
extends: '@semantic-release/apm-config'
additional_packages: |
['@semantic-release/apm@3.0.0', '@semantic-release/git', '@semantic-release/apm-config']
plugins: |
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/npm', '@semantic-release/github']
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/github', '@semantic-release/apm', '@semantic-release/git']
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
14 changes: 11 additions & 3 deletions action.yml
Expand Up @@ -12,16 +12,24 @@ inputs:
'The branches on which releases should happen.
https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches'
required: false
extends:
description:
'List of modules or file paths containing .
https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#extends'
required: false
plugins:
description:
'Define the list of plugins to use. Plugins will run in series, in the order defined, for each
steps if they implement it.
https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#plugins'
required: false
extends:
additional_packages:
description:
'List of modules or file paths containing a shareable configuration.
https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#extends'
'Define a list of additional plugins or shareable configurations (official or community) to
install. Use this if you 1) use any plugins other than commit-analyzer, release-notes-generator,
github, or npm, which are already installed along with semantic-release or 2) want to extend
from a shareable configuration.
https://semantic-release.gitbook.io/semantic-release/extending/plugins-list'
required: false
dry_run:
description:
Expand Down
27 changes: 27 additions & 0 deletions entrypoint.js
@@ -1,6 +1,8 @@
const { spawnSync } = require('child_process');
const core = require('@actions/core');
const semanticRelease = require('semantic-release');
const JSON5 = require('json5');
const arrify = require('arrify');

const parseInput = input => {
try {
Expand All @@ -10,6 +12,25 @@ const parseInput = input => {
}
};

/**
* Install npm packages.
*
* @param {string|string[]} packages - List of packages to install.
* @returns {object} - Response from `child_process.spawnSync()`.
*/
const installPackages = packages => {
try {
const packagesArr = arrify(packages);
core.debug(`Installing additional packages: ${packagesArr}`);
const result = spawnSync('npm', ['install', '--no-save', ...packagesArr]);
core.debug(`Packages installed.`);
return result;
} catch (err) {
core.debug(`Error installing additional packages: ${packages}`);
throw err;
}
};

/**
* Run semantic-release.
*
Expand All @@ -20,6 +41,7 @@ async function run() {
const branch = parseInput(core.getInput('branch', { required: false }));
const branches = parseInput(core.getInput('branches', { required: false }));
const plugins = parseInput(core.getInput('plugins', { required: false }));
const additionalPackages = parseInput(core.getInput('additional_packages', { required: false }));
const extendsInput = parseInput(core.getInput('extends', { required: false }));
let dryRun = core.getInput('dry_run', { required: false });
dryRun = dryRun !== '' ? dryRun === 'true' : '';
Expand All @@ -34,6 +56,11 @@ async function run() {
core.debug(`repository_url input: ${repositoryUrl}`);
core.debug(`tag_format input: ${tagFormat}`);

// install additional packages
if (additionalPackages) {
installPackages(additionalPackages);
}

// build options object
const branchOption = branch ? { branches: branch } : { branches };
const options = {
Expand Down
13 changes: 10 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -14,6 +14,7 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"arrify": "^2.0.1",
"json5": "^2.2.0",
"semantic-release": "^17.4.0"
},
Expand Down

0 comments on commit 892c8c9

Please sign in to comment.