Skip to content

Commit

Permalink
fix: respect semantic config if it exists
Browse files Browse the repository at this point in the history
Fixes #199
  • Loading branch information
codfish committed Mar 30, 2024
1 parent f6e50fb commit 37e061a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -199,7 +199,7 @@ You can pass in `semantic-release` configuration options via GitHub Action input
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
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)
defined in your repo (`.releaserc`, `release.config.js`, `release` prop in `package.json`)
Expand Down
31 changes: 21 additions & 10 deletions entrypoint.js
Expand Up @@ -3,6 +3,7 @@ import core from '@actions/core';
import semanticRelease from 'semantic-release';
import JSON5 from 'json5';
import arrify from 'arrify';
import { cosmiconfig } from 'cosmiconfig';

const parseInput = (input, defaultValue = '') => {
try {
Expand Down Expand Up @@ -73,17 +74,27 @@ const setGitConfigSafeDirectory = () => {
* @see https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#options
*/
async function run() {
const configFile = await cosmiconfig('release')
.search()
.then((result) => result?.config);
const branch = parseInput(core.getInput('branch', { required: false }));
const branches = parseInput(core.getInput('branches', { required: false }), [
'master',
'main',
'next',
'next-major',
'+([0-9])?(.{+([0-9]),x}).x',
{ name: 'beta', prerelease: true },
{ name: 'alpha', prerelease: true },
{ name: 'canary', prerelease: true },
]);
// Branches are parsed in this order:
// 1. Input from the action
// 2. Config file
// 3. Default branches set in this action = semantic-release's default branches with the addition of `main`.
const branches = parseInput(
core.getInput('branches', { required: false }),
configFile?.branches || [
'master',
'main',
'next',
'next-major',
'+([0-9])?(.{+([0-9]),x}).x',
{ name: 'beta', prerelease: true },
{ name: 'alpha', prerelease: true },
{ name: 'canary', prerelease: true },
],
);
const plugins = parseInput(core.getInput('plugins', { required: false }));
const additionalPackages =
parseInput(core.getInput('additional-packages', { required: false })) || [];
Expand Down
110 changes: 96 additions & 14 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 @@ -17,6 +17,7 @@
"@actions/core": "^1.10.1",
"@babel/runtime": "^7.23.2",
"arrify": "^3.0.0",
"cosmiconfig": "^9.0.0",
"json5": "^2.2.1",
"semantic-release": "^22.0.5"
},
Expand Down

0 comments on commit 37e061a

Please sign in to comment.