5
0
Fork 0
mirror of https://github.com/cycjimmy/semantic-release-action.git synced 2025-11-07 18:56:56 +00:00

feat(branches): support branches of semantic-release v16+

support branches of semantic-release v16+

#24 #25
This commit is contained in:
cycjimmy 2020-03-21 16:47:29 +08:00
parent c7a37752d9
commit 706c0ef960
8 changed files with 97 additions and 26 deletions

View file

@ -9,22 +9,28 @@ on:
- cron: 0 2 * * 0 - cron: 0 2 * * 0
jobs: jobs:
test: test-semantic-latest:
name: release name: test-semantic-latest
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Semantic Release - name: Semantic Release
uses: cycjimmy/semantic-release-action@v2 uses: ./
id: semantic id: semantic
with: with:
dry_run: true
branches: |
[
'master',
{name: 'beta', prerelease: true},
{name: 'alpha', prerelease: true}
]
branch: master branch: master
extra_plugins: | extra_plugins: |
@semantic-release/git @semantic-release/git
@semantic-release/changelog @semantic-release/changelog
dry_run: true
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
@ -36,5 +42,40 @@ jobs:
echo ${{ steps.semantic.outputs.new_release_major_version }} echo ${{ steps.semantic.outputs.new_release_major_version }}
echo ${{ steps.semantic.outputs.new_release_minor_version }} echo ${{ steps.semantic.outputs.new_release_minor_version }}
echo ${{ steps.semantic.outputs.new_release_patch_version }} echo ${{ steps.semantic.outputs.new_release_patch_version }}
echo ${{ steps.semantic.outputs.new_release_notes }}
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 }}
- 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 }}

View file

@ -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. #### 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: * 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. * `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. * `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. * `dry_run`: [Optional] Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file.
* outputs: * outputs:

View file

@ -5,13 +5,20 @@ branding:
icon: 'package' icon: 'package'
color: 'orange' color: 'orange'
inputs: 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: 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: extra_plugins:
required: false
description: 'Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer.' description: 'Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer.'
dry_run: dry_run:
required: false
description: 'Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file' description: 'Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file'
outputs: outputs:
new_release_published: new_release_published:

11
package-lock.json generated
View file

@ -5,9 +5,14 @@
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@actions/core": { "@actions/core": {
"version": "1.2.0", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.3.tgz",
"integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw==" "integrity": "sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w=="
},
"@cycjimmy/awesome-js-funcs": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/@cycjimmy/awesome-js-funcs/-/awesome-js-funcs-2.3.0.tgz",
"integrity": "sha512-HXJrv0S1gzjP9h2cmE57m+0XnVsGIsidPEjxUR5i50iGIxbjEe1EhL6iSh2P1LXdjjbt1U/UHj6n93yzDwt1gw=="
} }
} }
} }

View file

@ -21,6 +21,7 @@
}, },
"homepage": "https://github.com/cycjimmy/semantic-release-action#readme", "homepage": "https://github.com/cycjimmy/semantic-release-action#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.0" "@actions/core": "^1.2.3",
"@cycjimmy/awesome-js-funcs": "^2.3.0"
} }
} }

View file

@ -1,29 +1,44 @@
const core = require('@actions/core'); const core = require('@actions/core');
const stringToJson = require('@cycjimmy/awesome-js-funcs/typeConversion/stringToJson').default;
const inputs = require('./inputs.json'); const inputs = require('./inputs.json');
/** /**
* Handle Branch Option * Handle Branches Option
* @returns {{}|{branch: string}} * @returns {{}|{branch: string}}
*/ */
exports.handleBranchOption = () => { exports.handleBranchesOption = () => {
const branchOption = {}; const branchesOption = {};
const branches = core.getInput(inputs.branches);
const branch = core.getInput(inputs.branch); const branch = core.getInput(inputs.branch);
if (!branch) { core.debug(`branches input: ${branches}`);
return branchOption; core.debug(`branch input: ${branch}`);
}
const semanticVersion = require('semantic-release/package.json').version; const semanticVersion = require('semantic-release/package.json').version;
const semanticMajorVersion = Number(semanticVersion.replace(/\..+/g, '')); const semanticMajorVersion = Number(semanticVersion.replace(/\..+/g, ''));
core.debug(`semanticMajorVersion: ${semanticMajorVersion}`); core.debug(`semanticMajorVersion: ${semanticMajorVersion}`);
// older than v16
if (semanticMajorVersion < 16) { if (semanticMajorVersion < 16) {
branchOption.branch = branch; if (!branch) {
} else { return branchesOption;
branchOption.branches = [branch]; }
branchesOption.branch = branch;
return branchesOption;
} }
return branchOption; // above v16
const strNeedConvertToJson = branches || branch || '';
if (!strNeedConvertToJson) {
return branchesOption;
}
const jsonOrStr = stringToJson('' + strNeedConvertToJson);
core.debug(`Converted branches attribute: ${JSON.stringify(jsonOrStr)}`);
branchesOption.branches = jsonOrStr;
return branchesOption;
}; };
/** /**

View file

@ -1,5 +1,5 @@
const core = require('@actions/core'); const core = require('@actions/core');
const {handleBranchOption, handleDryRunOption} = require('./handleOptions'); const {handleBranchesOption, handleDryRunOption} = require('./handleOptions');
const setUpJob = require('./setUpJob.task'); const setUpJob = require('./setUpJob.task');
const installSpecifyingVersionSemantic = require('./installSpecifyingVersionSemantic.task'); const installSpecifyingVersionSemantic = require('./installSpecifyingVersionSemantic.task');
const preInstallPlugins = require('./preInstallPlugins.task'); const preInstallPlugins = require('./preInstallPlugins.task');
@ -17,7 +17,7 @@ const release = async () => {
const semanticRelease = require('semantic-release'); const semanticRelease = require('semantic-release');
const result = await semanticRelease({ const result = await semanticRelease({
...(handleBranchOption()), ...(handleBranchesOption()),
...(handleDryRunOption()), ...(handleDryRunOption()),
}); });

View file

@ -1,6 +1,7 @@
{ {
"branch": "branch",
"semantic_version": "semantic_version", "semantic_version": "semantic_version",
"branches": "branches",
"branch": "branch",
"extra_plugins": "extra_plugins", "extra_plugins": "extra_plugins",
"dry_run": "dry_run" "dry_run": "dry_run"
} }