Skip to content

Commit

Permalink
feat(outputs): Add outputs related to new release version
Browse files Browse the repository at this point in the history
Add outputs related to new release version
- `new-release-version`: Version of the new release
- `new-release-major-version`: Major version of the new release
- `new-release-minor-version`: Minor version of the new release
- `new-release-patch-version`: Patch version of the new release
  • Loading branch information
cycjimmy committed Oct 21, 2019
1 parent 150d050 commit 12a1a39
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Push updates to branch v1
- name: Push updates to branch for major version
if: steps.semantic.outputs.new-release-published == 'true'
run: "git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:refs/heads/v1"
run: "git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:refs/heads/${steps.semantic.outputs.new-release-major-version}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ GitHub Action for [Semantic Release](https://github.com/semantic-release/semanti
* `dry_run`: [Optional] Whether to run semantic release in "dry-run" mode. It will override the dryRun attribute in your configuration file. Default `""`.
* outputs:
* `new-release-published`: Whether a new release was published. `true` or `false`
* `new-release-version`: Version of the new release
* `new-release-major-version`: Major version of the new release
* `new-release-minor-version`: Minor version of the new release
* `new-release-patch-version`: Patch version of the new release

A simple example
```yaml
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ inputs:
outputs:
new-release-published:
description: 'Whether a new release was published'
new-release-version:
description: "Version of the new release"
new-release-major-version:
description: "Major version of the new release"
new-release-minor-version:
description: "Minor version of the new release"
new-release-patch-version:
description: "Patch version of the new release"
runs:
using: 'node12'
main: 'index.js'
21 changes: 17 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ const path = require('path');
const core = require('@actions/core');
const semanticRelease = require('semantic-release');

const OutputKey_NewReleasePublished = 'new-release-published';
const OutputKeys = {
newReleasePublished: 'new-release-published',
newReleaseVersion: 'new-release-version',
newReleaseMajor: 'new-release-major-version',
newReleaseMinor: 'new-release-minor-version',
newReleasePatch: 'new-release-patch-version',
};

/**
* handleDryRunOption
Expand Down Expand Up @@ -33,7 +39,7 @@ const release = async () => {
const extraPlugins = core.getInput('extra_plugins', {required: false}) || '';

// set outputs default
core.setOutput(OutputKey_NewReleasePublished, 'false');
core.setOutput(OutputKeys.newReleasePublished, 'false');

// pre-install plugins
if (extraPlugins) {
Expand Down Expand Up @@ -71,8 +77,15 @@ const release = async () => {
core.debug(`The release was published with plugin "${release.pluginName}".`);
}

// set outputs default
core.setOutput(OutputKey_NewReleasePublished, 'true');
const {version} = nextRelease;
const [major, minor, patch] = version.split('.');

// set outputs
core.setOutput(OutputKeys.newReleasePublished, 'true');
core.setOutput(OutputKeys.newReleaseVersion, version);
core.setOutput(OutputKeys.newReleaseMajor, major);
core.setOutput(OutputKeys.newReleaseMinor, minor);
core.setOutput(OutputKeys.newReleasePatch, patch);
};


Expand Down

0 comments on commit 12a1a39

Please sign in to comment.