mirror of
https://github.com/cycjimmy/semantic-release-action.git
synced 2025-11-07 10:46:56 +00:00
feat: add a new output - "new-release-published"
This commit is contained in:
parent
ddd286be06
commit
be8f403201
4 changed files with 71 additions and 3 deletions
34
.github/workflows/release.yml
vendored
34
.github/workflows/release.yml
vendored
|
|
@ -16,8 +16,35 @@ jobs:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Setup Node.js with GitHub Package Registry
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
registry-url: 'https://npm.pkg.github.com'
|
||||||
|
scope: 'cycjimmy'
|
||||||
|
always-auth: true
|
||||||
|
|
||||||
|
- name: Setup Node.js with Npm Package Registry
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
always-auth: true
|
||||||
|
|
||||||
|
- name: Set .npmrc
|
||||||
|
env:
|
||||||
|
CI: true
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
run: |
|
||||||
|
echo "//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" > /home/runner/work/_temp/.npmrc
|
||||||
|
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> /home/runner/work/_temp/.npmrc
|
||||||
|
|
||||||
- name: Semantic Release
|
- name: Semantic Release
|
||||||
uses: cycjimmy/semantic-release-action@master
|
uses: cycjimmy/semantic-release-action@master
|
||||||
|
id: semantic
|
||||||
with:
|
with:
|
||||||
branch: master
|
branch: master
|
||||||
extra_plugins: |
|
extra_plugins: |
|
||||||
|
|
@ -26,3 +53,10 @@ jobs:
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
|
- name: Publish To GitHub Package Registry
|
||||||
|
if: steps.semantic.outputs.new-release-published == 'true'
|
||||||
|
run: npm publish --@cycjimmy:registry='https://npm.pkg.github.com'
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
|
||||||
|
|
|
||||||
22
README.md
22
README.md
|
|
@ -2,17 +2,39 @@
|
||||||
GitHub Action for [Semantic Release](https://github.com/semantic-release/semantic-release).
|
GitHub Action for [Semantic Release](https://github.com/semantic-release/semantic-release).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
* inputs:
|
||||||
* `branch`: [Optional] The branch for release. Default `"master"`.
|
* `branch`: [Optional] The branch for release. Default `"master"`.
|
||||||
* `extra_plugins`: [Optional] Extra plugins for pre-install. Default `""`.
|
* `extra_plugins`: [Optional] Extra plugins for pre-install. Default `""`.
|
||||||
|
* outputs:
|
||||||
|
* `new-release-published`: Whether a new release was published. `true` or `false`
|
||||||
|
|
||||||
|
A simple example
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- name: Semantic Release
|
- name: Semantic Release
|
||||||
uses: cycjimmy/semantic-release-action@master
|
uses: cycjimmy/semantic-release-action@master
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
|
An advanced example
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- name: Semantic Release
|
||||||
|
uses: cycjimmy/semantic-release-action@master
|
||||||
|
id: semantic
|
||||||
with:
|
with:
|
||||||
branch: master
|
branch: master
|
||||||
extra_plugins: |
|
extra_plugins: |
|
||||||
@semantic-release/git
|
@semantic-release/git
|
||||||
@semantic-release/changelog
|
@semantic-release/changelog
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
|
- name: Do something when a new release published
|
||||||
|
if: steps.semantic.outputs.new-release-published == 'true'
|
||||||
|
run: ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ inputs:
|
||||||
extra_plugins:
|
extra_plugins:
|
||||||
description: 'Extra plugins for pre-install'
|
description: 'Extra plugins for pre-install'
|
||||||
default: ''
|
default: ''
|
||||||
|
outputs:
|
||||||
|
new-release-published:
|
||||||
|
description: "Whether a new release was published"
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'index.js'
|
main: 'index.js'
|
||||||
|
|
|
||||||
11
src/index.js
11
src/index.js
|
|
@ -3,10 +3,15 @@ const path = require('path');
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
const semanticRelease = require('semantic-release');
|
const semanticRelease = require('semantic-release');
|
||||||
|
|
||||||
|
const OutputKey_NewReleasePublished = 'new-release-published';
|
||||||
|
|
||||||
const release = async () => {
|
const release = async () => {
|
||||||
const branch = core.getInput('branch', {required: false}) || 'master';
|
const branch = core.getInput('branch', {required: false}) || 'master';
|
||||||
const extraPlugins = core.getInput('extra_plugins', {required: false}) || '';
|
const extraPlugins = core.getInput('extra_plugins', {required: false}) || '';
|
||||||
|
|
||||||
|
// set outputs default
|
||||||
|
core.setOutput(OutputKey_NewReleasePublished, 'false');
|
||||||
|
|
||||||
// pre-install plugins
|
// pre-install plugins
|
||||||
if (extraPlugins) {
|
if (extraPlugins) {
|
||||||
const _extraPlugins = extraPlugins
|
const _extraPlugins = extraPlugins
|
||||||
|
|
@ -15,7 +20,7 @@ const release = async () => {
|
||||||
const {stdout, stderr} = await exec(`npm install ${_extraPlugins}`, {
|
const {stdout, stderr} = await exec(`npm install ${_extraPlugins}`, {
|
||||||
cwd: path.resolve(__dirname)
|
cwd: path.resolve(__dirname)
|
||||||
});
|
});
|
||||||
console.log(stdout);
|
core.debug(stdout);
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
return Promise.reject(stderr);
|
return Promise.reject(stderr);
|
||||||
}
|
}
|
||||||
|
|
@ -39,9 +44,13 @@ const release = async () => {
|
||||||
for (const release of releases) {
|
for (const release of releases) {
|
||||||
core.debug(`The release was published with plugin "${release.pluginName}".`);
|
core.debug(`The release was published with plugin "${release.pluginName}".`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set outputs default
|
||||||
|
core.setOutput(OutputKey_NewReleasePublished, 'true');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
|
core.debug('Initialization successful');
|
||||||
release().catch(core.setFailed);
|
release().catch(core.setFailed);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue