Skip to content

Commit

Permalink
feat(branches): support branches of semantic-release v16+
Browse files Browse the repository at this point in the history
support branches of semantic-release v16+

#24 #25
  • Loading branch information
cycjimmy committed Mar 21, 2020
1 parent c7a3775 commit 706c0ef
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 25 deletions.
49 changes: 45 additions & 4 deletions .github/workflows/testRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,63 @@ on:
- cron: 0 2 * * 0

jobs:
test:
name: release
test-semantic-latest:
name: test-semantic-latest
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
uses: ./
id: semantic
with:
dry_run: true
branches: |
[
'master',
{name: 'beta', prerelease: true},
{name: 'alpha', prerelease: true}
]
branch: master
extra_plugins: |
@semantic-release/git
@semantic-release/changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Test Outputs
if: steps.semantic.outputs.new_release_published == 'true'
run: |
echo ${{ steps.semantic.outputs.new_release_version }}
echo ${{ steps.semantic.outputs.new_release_major_version }}
echo ${{ steps.semantic.outputs.new_release_minor_version }}
echo ${{ steps.semantic.outputs.new_release_patch_version }}
test-semantic-v15:
name: test-semantic-v15
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Semantic Release
uses: ./
id: semantic_v15
with:
semantic_version: 15
dry_run: true
branches: |
[
'master',
{name: 'beta', prerelease: true},
{name: 'alpha', prerelease: true}
]
branch: master
extra_plugins: |
@semantic-release/git@7
@semantic-release/changelog@3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -36,5 +77,5 @@ jobs:
echo ${{ steps.semantic.outputs.new_release_major_version }}
echo ${{ steps.semantic.outputs.new_release_minor_version }}
echo ${{ steps.semantic.outputs.new_release_patch_version }}
echo ${{ steps.semantic.outputs.new_release_notes }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ GitHub Action for [Semantic Release](https://github.com/semantic-release/semanti

#### Step3: Add a [Workflow File](https://help.github.com/en/articles/workflow-syntax-for-github-actions) to your repository to create custom automated processes.
* inputs:
* `branch`: [Optional] The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master.
* `semantic_version`: [Optional] Specify specifying version range for semantic-release. If no version range is specified, latest version will be used by default.
* `branches`: [Optional] The branches on which releases should happen. It will override the branches attribute in your configuration file. If the attribute is not configured on both sides, the default is `['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]`. **Support for semantic-release above v16**. See https://semantic-release.gitbook.io/semantic-release/usage/configuration#branches for more information.
* `branch`: [Optional] The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master. **Support for semantic-release older than v16**.
* `extra_plugins`: [Optional] Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer.
* `dry_run`: [Optional] Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file.
* outputs:
Expand Down
13 changes: 10 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ branding:
icon: 'package'
color: 'orange'
inputs:
branch:
description: 'The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master.'
semantic_version:
description: 'Specify specifying version range for semantic-release. If no version range is specified, semantic-release@^15 will be used by default.'
required: false
description: 'Specify specifying version range for semantic-release. If no version range is specified, latest version will be used by default'
branches:
required: false
description: 'The branches on which releases should happen. It will override the branches attribute in your configuration file. Support for semantic-release above v16. See https://semantic-release.gitbook.io/semantic-release/usage/configuration#branches for more information.'
branch:
required: false
description: 'The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master. Support for semantic-release older than v16.'
extra_plugins:
required: false
description: 'Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer.'
dry_run:
required: false
description: 'Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file'
outputs:
new_release_published:
Expand Down
11 changes: 8 additions & 3 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"homepage": "https://github.com/cycjimmy/semantic-release-action#readme",
"dependencies": {
"@actions/core": "^1.2.0"
"@actions/core": "^1.2.3",
"@cycjimmy/awesome-js-funcs": "^2.3.0"
}
}
35 changes: 25 additions & 10 deletions src/handleOptions.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
const core = require('@actions/core');
const stringToJson = require('@cycjimmy/awesome-js-funcs/typeConversion/stringToJson').default;
const inputs = require('./inputs.json');

/**
* Handle Branch Option
* Handle Branches Option
* @returns {{}|{branch: string}}
*/
exports.handleBranchOption = () => {
const branchOption = {};
exports.handleBranchesOption = () => {
const branchesOption = {};
const branches = core.getInput(inputs.branches);
const branch = core.getInput(inputs.branch);

if (!branch) {
return branchOption;
}
core.debug(`branches input: ${branches}`);
core.debug(`branch input: ${branch}`);

const semanticVersion = require('semantic-release/package.json').version;
const semanticMajorVersion = Number(semanticVersion.replace(/\..+/g, ''));
core.debug(`semanticMajorVersion: ${semanticMajorVersion}`);

// older than v16
if (semanticMajorVersion < 16) {
branchOption.branch = branch;
} else {
branchOption.branches = [branch];
if (!branch) {
return branchesOption;
}

branchesOption.branch = branch;
return branchesOption;
}

// above v16
const strNeedConvertToJson = branches || branch || '';

if (!strNeedConvertToJson) {
return branchesOption;
}

return branchOption;
const jsonOrStr = stringToJson('' + strNeedConvertToJson);
core.debug(`Converted branches attribute: ${JSON.stringify(jsonOrStr)}`);
branchesOption.branches = jsonOrStr;
return branchesOption;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const core = require('@actions/core');
const {handleBranchOption, handleDryRunOption} = require('./handleOptions');
const {handleBranchesOption, handleDryRunOption} = require('./handleOptions');
const setUpJob = require('./setUpJob.task');
const installSpecifyingVersionSemantic = require('./installSpecifyingVersionSemantic.task');
const preInstallPlugins = require('./preInstallPlugins.task');
Expand All @@ -17,7 +17,7 @@ const release = async () => {

const semanticRelease = require('semantic-release');
const result = await semanticRelease({
...(handleBranchOption()),
...(handleBranchesOption()),
...(handleDryRunOption()),
});

Expand Down
3 changes: 2 additions & 1 deletion src/inputs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"branch": "branch",
"semantic_version": "semantic_version",
"branches": "branches",
"branch": "branch",
"extra_plugins": "extra_plugins",
"dry_run": "dry_run"
}

0 comments on commit 706c0ef

Please sign in to comment.