Merge pull request #28 from Nagarian/master

feat: add skip-on-empty feature
releases/v3
Tycho Bokdam 2020-06-10 14:19:25 +02:00 committed by GitHub
commit 24dece1cca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 41 deletions

View File

@ -8,9 +8,10 @@ This action will bump version, tag commit and generate a changelog with conventi
- **Optional** `git-message`: Commit message that is used when committing the changelog. - **Optional** `git-message`: Commit message that is used when committing the changelog.
- **Optional** `preset`: Preset that is used from conventional commits. Default `angular`. - **Optional** `preset`: Preset that is used from conventional commits. Default `angular`.
- **Optional** `tag-prefix`: Prefix for the git tags. Default `v`. - **Optional** `tag-prefix`: Prefix for the git tags. Default `v`.
- **Optional** `output-file`: File to output the changelog to. Default `CHANGELOG.md`, when providing `false` no file will be generated / updated. - **Optional** `output-file`: File to output the changelog to. Default `CHANGELOG.md`, when providing `'false'` no file will be generated / updated.
- **Optional** `release-count`: Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all. - **Optional** `release-count`: Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all.
- **Optional** `package-json`: The path to the package.json to use. Default `./package.json`. - **Optional** `package-json`: The path to the package.json to use. Default `./package.json`.
- **Optional** `skip-on-empty`: Boolean to specify if you want to skip empty release (no-changelog generated). This case occured when you push `chore` commit with `angular` for example. Default `'false'`.
## Outputs ## Outputs
@ -18,10 +19,12 @@ This action will bump version, tag commit and generate a changelog with conventi
- `clean_changelog`: The generated changelog for the new version without the version name in it (Better for Github releases) - `clean_changelog`: The generated changelog for the new version without the version name in it (Better for Github releases)
- `version`: The new version. - `version`: The new version.
- `tag`: The name of the generated tag. - `tag`: The name of the generated tag.
- `skipped`: Boolean (`'true'` or `'false'`) specifying if this step have been skipped
## Example usages ## Example usages
Uses all the defaults Uses all the defaults
```yaml ```yaml
- name: Conventional Changelog Action - name: Conventional Changelog Action
uses: TriPSs/conventional-changelog-action@v2 uses: TriPSs/conventional-changelog-action@v2
@ -30,6 +33,7 @@ Uses all the defaults
``` ```
Overwrite everything Overwrite everything
```yaml ```yaml
- name: Conventional Changelog Action - name: Conventional Changelog Action
uses: TriPSs/conventional-changelog-action@v2 uses: TriPSs/conventional-changelog-action@v2
@ -41,9 +45,11 @@ Overwrite everything
output-file: 'CHANGELOG.md' output-file: 'CHANGELOG.md'
release-count: '5' release-count: '5'
package-json: './package.json' package-json: './package.json'
skip-on-empty: 'false'
``` ```
No file changelog No file changelog
```yaml ```yaml
- name: Conventional Changelog Action - name: Conventional Changelog Action
uses: TriPSs/conventional-changelog-action@v2 uses: TriPSs/conventional-changelog-action@v2
@ -53,6 +59,7 @@ No file changelog
``` ```
Github releases Github releases
```yaml ```yaml
- name: Conventional Changelog Action - name: Conventional Changelog Action
id: changelog id: changelog
@ -60,9 +67,11 @@ Github releases
with: with:
github-token: ${{ secrets.github_token }} github-token: ${{ secrets.github_token }}
output-file: 'false' output-file: 'false'
skip-on-empty: 'true'
- name: Create Release - name: Create Release
uses: actions/create-release@v1 uses: actions/create-release@v1
if: ${{ !steps.changelog.outputs.skipped }}
env: env:
GITHUB_TOKEN: ${{ secrets.github_token }} GITHUB_TOKEN: ${{ secrets.github_token }}
with: with:

View File

@ -44,6 +44,11 @@ inputs:
default: './package.json' default: './package.json'
required: false required: false
skip-on-empty:
description: 'Do nothing when the changelog from the latest release is empty'
default: 'false'
required: false
outputs: outputs:
changelog: changelog:
description: 'The generated changelog for the new version' description: 'The generated changelog for the new version'
@ -53,3 +58,5 @@ outputs:
description: 'The new version' description: 'The new version'
tag: tag:
description: 'The name of the generated tag' description: 'The name of the generated tag'
skipped:
description: 'boolean to check if this step have been skipped'

View File

@ -13,6 +13,7 @@ async function run() {
const outputFile = core.getInput('output-file') const outputFile = core.getInput('output-file')
const releaseCount = core.getInput('release-count') const releaseCount = core.getInput('release-count')
const packageJsonToUse = core.getInput('package-json') const packageJsonToUse = core.getInput('package-json')
const skipOnEmptyRelease = core.getInput('skip-on-empty').toLowerCase() === 'true'
core.info(`Using "${preset}" preset`) core.info(`Using "${preset}" preset`)
core.info(`Using "${commitMessage}" as commit message`) core.info(`Using "${commitMessage}" as commit message`)
@ -24,12 +25,14 @@ async function run() {
core.info('Pull to make sure we have the full git history') core.info('Pull to make sure we have the full git history')
await git.pull() await git.pull()
conventionalRecommendedBump({ preset, tagPrefix }, async(error, recommendation) => { conventionalRecommendedBump({ preset, tagPrefix }, async (error, recommendation) => {
if (error) { if (error) {
core.setFailed(error.message) core.setFailed(error.message)
return
}
} else {
core.info(`Recommended release type: ${recommendation.releaseType}`) core.info(`Recommended release type: ${recommendation.releaseType}`)
recommendation.reason && core.info(`because: ${recommendation.reason}`)
// Bump the version in the package.json // Bump the version in the package.json
const jsonPackage = packageJson.bump( const jsonPackage = packageJson.bump(
@ -37,6 +40,18 @@ async function run() {
recommendation.releaseType, recommendation.releaseType,
) )
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, jsonPackage, 1)
core.info('Changelog generated')
core.info(stringChangelog)
const cleanChangelog = stringChangelog.split('\n').slice(3).join('\n').trim()
if (skipOnEmptyRelease && cleanChangelog === '') {
core.info('Generated changelog is empty and skip-on-empty has been activated so we skip this step')
core.setOutput('skipped', 'true')
return
}
// Update the package.json file // Update the package.json file
packageJson.update(jsonPackage) packageJson.update(jsonPackage)
@ -48,10 +63,6 @@ async function run() {
await changelog.generateFileChangelog(tagPrefix, preset, jsonPackage, outputFile, releaseCount) await changelog.generateFileChangelog(tagPrefix, preset, jsonPackage, outputFile, releaseCount)
} }
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, jsonPackage, 1)
core.info('Changelog generated')
core.info(stringChangelog)
core.info('Push all changes') core.info('Push all changes')
// Add changed files to git // Add changed files to git
@ -63,10 +74,10 @@ async function run() {
// Set outputs so other actions (for example actions/create-release) can use it // Set outputs so other actions (for example actions/create-release) can use it
core.setOutput('changelog', stringChangelog) core.setOutput('changelog', stringChangelog)
// Removes the version number from the changelog // Removes the version number from the changelog
core.setOutput('clean_changelog', stringChangelog.split('\n').slice(3).join('\n')) core.setOutput('clean_changelog', cleanChangelog)
core.setOutput('version', jsonPackage.version) core.setOutput('version', jsonPackage.version)
core.setOutput('tag', `${tagPrefix}${jsonPackage.version}`) core.setOutput('tag', `${tagPrefix}${jsonPackage.version}`)
} core.setOutput('skipped', 'false')
}) })
} catch (error) { } catch (error) {