commit
4d61805bb7
|
@ -658,4 +658,108 @@ jobs:
|
||||||
FILES: 'test-file.json'
|
FILES: 'test-file.json'
|
||||||
EXPECTED_VERSION: '1.5.0'
|
EXPECTED_VERSION: '1.5.0'
|
||||||
|
|
||||||
|
test-pre-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "./"
|
||||||
|
|
||||||
|
- run: npm ci --prod
|
||||||
|
|
||||||
|
- run: "git config --global user.email 'changelog@github.com'"
|
||||||
|
- run: "git config --global user.name 'Awesome Github action'"
|
||||||
|
- run: "git add . && git commit --allow-empty -m 'feat: Added fake file so version will be bumped'"
|
||||||
|
|
||||||
|
- name: Generate changelog
|
||||||
|
id: changelog
|
||||||
|
uses: ./
|
||||||
|
env:
|
||||||
|
ENV: 'dont-use-git'
|
||||||
|
EXPECTED_TAG: 'v1.4.6-rc.0'
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.github_token }}
|
||||||
|
version-file: 'test-file.json'
|
||||||
|
pre-release: true
|
||||||
|
|
||||||
|
- name: Show file
|
||||||
|
run: |
|
||||||
|
echo "$(<test-file.json)"
|
||||||
|
|
||||||
|
- name: Test output
|
||||||
|
run: node ./test-output.js
|
||||||
|
env:
|
||||||
|
FILES: 'test-file.json'
|
||||||
|
EXPECTED_VERSION: '1.4.6-rc.0'
|
||||||
|
|
||||||
|
test-pre-release-identifier:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "./"
|
||||||
|
|
||||||
|
- run: npm ci --prod
|
||||||
|
|
||||||
|
- run: "git config --global user.email 'changelog@github.com'"
|
||||||
|
- run: "git config --global user.name 'Awesome Github action'"
|
||||||
|
- run: "git add . && git commit --allow-empty -m 'feat: Added fake file so version will be bumped'"
|
||||||
|
|
||||||
|
- name: Generate changelog
|
||||||
|
id: changelog
|
||||||
|
uses: ./
|
||||||
|
env:
|
||||||
|
ENV: 'dont-use-git'
|
||||||
|
EXPECTED_TAG: 'v1.4.6-alpha.0'
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.github_token }}
|
||||||
|
version-file: 'test-file.json'
|
||||||
|
pre-release: true
|
||||||
|
pre-release-identifier: 'alpha'
|
||||||
|
|
||||||
|
- name: Show file
|
||||||
|
run: |
|
||||||
|
echo "$(<test-file.json)"
|
||||||
|
|
||||||
|
- name: Test output
|
||||||
|
run: node ./test-output.js
|
||||||
|
env:
|
||||||
|
FILES: 'test-file.json'
|
||||||
|
EXPECTED_VERSION: '1.4.6-alpha.0'
|
||||||
|
|
||||||
|
test-pre-release-to-stable:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "./"
|
||||||
|
|
||||||
|
- run: npm ci --prod
|
||||||
|
|
||||||
|
- run: "git config --global user.email 'changelog@github.com'"
|
||||||
|
- run: "git config --global user.name 'Awesome Github action'"
|
||||||
|
- run: "git add . && git commit --allow-empty -m 'feat: Added fake file so version will be bumped'"
|
||||||
|
|
||||||
|
- name: Generate changelog
|
||||||
|
id: changelog
|
||||||
|
uses: ./
|
||||||
|
env:
|
||||||
|
ENV: 'dont-use-git'
|
||||||
|
EXPECTED_TAG: 'v1.5.0'
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.github_token }}
|
||||||
|
version-file: 'test-file-pre-release.json'
|
||||||
|
pre-release: false # This is the default value, but we want to be explicit
|
||||||
|
|
||||||
|
- name: Show file
|
||||||
|
run: |
|
||||||
|
echo "$(<test-file-pre-release.json)"
|
||||||
|
|
||||||
|
- name: Test output
|
||||||
|
run: node ./test-output.js
|
||||||
|
env:
|
||||||
|
FILES: 'test-file-pre-release.json'
|
||||||
|
EXPECTED_VERSION: '1.5.0'
|
||||||
|
|
|
@ -29,6 +29,8 @@ This action will bump version, tag commit and generate a changelog with conventi
|
||||||
- **Optional** `pre-changelog-generation`: Path to the pre-changelog-generation script file. No hook by default.
|
- **Optional** `pre-changelog-generation`: Path to the pre-changelog-generation script file. No hook by default.
|
||||||
- **Optional** `skip-ci`: Adds instruction to Github to not consider the push something to rebuild. Default `true`.
|
- **Optional** `skip-ci`: Adds instruction to Github to not consider the push something to rebuild. Default `true`.
|
||||||
- **Optional** `create-summary`: Adds the generated changelog as Action Summary. Default `false`.
|
- **Optional** `create-summary`: Adds the generated changelog as Action Summary. Default `false`.
|
||||||
|
- **Optional** `pre-release`: Marks the release as pre-release. Default `false`.
|
||||||
|
- **Optional** `pre-release-identifier`: The identifier to use for the pre-release. Default `rc`.
|
||||||
|
|
||||||
### Pre-Commit hook
|
### Pre-Commit hook
|
||||||
|
|
||||||
|
|
10
action.yml
10
action.yml
|
@ -133,6 +133,16 @@ inputs:
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
|
pre-release:
|
||||||
|
description: 'Marks the release as pre-release'
|
||||||
|
default: 'false'
|
||||||
|
required: false
|
||||||
|
|
||||||
|
pre-release-identifier:
|
||||||
|
description: 'The identifier to use for pre-releases'
|
||||||
|
default: 'rc'
|
||||||
|
required: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
changelog:
|
changelog:
|
||||||
description: 'The generated changelog for the new version'
|
description: 'The generated changelog for the new version'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const semverValid = require('semver').valid
|
const semver = require('semver')
|
||||||
|
|
||||||
const requireScript = require('./requireScript')
|
const requireScript = require('./requireScript')
|
||||||
|
|
||||||
|
@ -11,45 +11,28 @@ const requireScript = require('./requireScript')
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
module.exports = async (releaseType, version) => {
|
module.exports = async (releaseType, version) => {
|
||||||
let major, minor, patch
|
let newVersion
|
||||||
|
|
||||||
|
const prerelease = core.getBooleanInput('pre-release')
|
||||||
|
const identifier = core.getInput('pre-release-identifier')
|
||||||
|
|
||||||
if (version) {
|
if (version) {
|
||||||
[major, minor, patch] = version.split('.')
|
newVersion = semver.inc(version, (prerelease ? 'prerelease' : releaseType), identifier)
|
||||||
|
|
||||||
switch (releaseType) {
|
|
||||||
case 'major':
|
|
||||||
major = parseInt(major, 10) + 1
|
|
||||||
minor = 0
|
|
||||||
patch = 0
|
|
||||||
break
|
|
||||||
|
|
||||||
case 'minor':
|
|
||||||
minor = parseInt(minor, 10) + 1
|
|
||||||
patch = 0
|
|
||||||
break
|
|
||||||
|
|
||||||
default:
|
|
||||||
patch = parseInt(patch, 10) + 1
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let version = semverValid(core.getInput('fallback-version'))
|
let version = semver.valid(core.getInput('fallback-version'))
|
||||||
|
|
||||||
if (version) {
|
if (version) {
|
||||||
[major, minor, patch] = version.split('.')
|
newVersion = version
|
||||||
} else {
|
} else {
|
||||||
// default
|
// default
|
||||||
major = 0
|
newVersion = '0.1.0'
|
||||||
minor = 1
|
|
||||||
patch = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`The version could not be detected, using fallback version '${major}.${minor}.${patch}'.`)
|
core.info(`The version could not be detected, using fallback version '${newVersion}'.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const preChangelogGenerationFile = core.getInput('pre-changelog-generation')
|
const preChangelogGenerationFile = core.getInput('pre-changelog-generation')
|
||||||
|
|
||||||
let newVersion = `${major}.${minor}.${patch}`
|
|
||||||
|
|
||||||
if (preChangelogGenerationFile) {
|
if (preChangelogGenerationFile) {
|
||||||
const preChangelogGenerationScript = requireScript(preChangelogGenerationFile)
|
const preChangelogGenerationScript = requireScript(preChangelogGenerationFile)
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,15 @@ const conventionalChangelog = require('conventional-changelog')
|
||||||
* @param releaseCount
|
* @param releaseCount
|
||||||
* @param config
|
* @param config
|
||||||
* @param gitPath
|
* @param gitPath
|
||||||
|
* @param skipUnstable
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
const getChangelogStream = (tagPrefix, preset, version, releaseCount, config, gitPath) => conventionalChangelog({
|
const getChangelogStream = (tagPrefix, preset, version, releaseCount, config, gitPath, skipUnstable) => conventionalChangelog({
|
||||||
preset,
|
preset,
|
||||||
releaseCount: parseInt(releaseCount, 10),
|
releaseCount: parseInt(releaseCount, 10),
|
||||||
tagPrefix,
|
tagPrefix,
|
||||||
config
|
config,
|
||||||
|
skipUnstable
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
version,
|
version,
|
||||||
|
@ -40,10 +42,11 @@ module.exports = getChangelogStream
|
||||||
* @param releaseCount
|
* @param releaseCount
|
||||||
* @param config
|
* @param config
|
||||||
* @param gitPath
|
* @param gitPath
|
||||||
|
* @param skipUnstable
|
||||||
* @returns {Promise<string>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCount, config, gitPath) => new Promise((resolve, reject) => {
|
module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCount, config, gitPath, skipUnstable) => new Promise((resolve, reject) => {
|
||||||
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath)
|
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath, skipUnstable)
|
||||||
|
|
||||||
let changelog = ''
|
let changelog = ''
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ async function run() {
|
||||||
const gitPath = core.getInput('git-path')
|
const gitPath = core.getInput('git-path')
|
||||||
const skipCi = core.getBooleanInput('skip-ci')
|
const skipCi = core.getBooleanInput('skip-ci')
|
||||||
const createSummary = core.getBooleanInput('create-summary')
|
const createSummary = core.getBooleanInput('create-summary')
|
||||||
|
const prerelease = core.getBooleanInput('pre-release')
|
||||||
|
|
||||||
if (skipCi) {
|
if (skipCi) {
|
||||||
gitCommitMessage += ' [skip ci]'
|
gitCommitMessage += ' [skip ci]'
|
||||||
|
@ -84,7 +85,7 @@ async function run() {
|
||||||
|
|
||||||
const config = conventionalConfigFile && requireScript(conventionalConfigFile)
|
const config = conventionalConfigFile && requireScript(conventionalConfigFile)
|
||||||
|
|
||||||
conventionalRecommendedBump({ preset, tagPrefix, config }, async (error, recommendation) => {
|
conventionalRecommendedBump({ preset, tagPrefix, config, skipUnstable: !prerelease }, async (error, recommendation) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message)
|
||||||
return
|
return
|
||||||
|
@ -146,7 +147,7 @@ async function run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the string changelog
|
// Generate the string changelog
|
||||||
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config, gitPath)
|
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config, gitPath, !prerelease)
|
||||||
core.info('Changelog generated')
|
core.info('Changelog generated')
|
||||||
core.info(stringChangelog)
|
core.info(stringChangelog)
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,9 @@ module.exports = class Git extends BaseVersioning {
|
||||||
bump = (releaseType) => {
|
bump = (releaseType) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const tagPrefix = core.getInput('tag-prefix')
|
const tagPrefix = core.getInput('tag-prefix')
|
||||||
|
const prerelease = core.getBooleanInput('pre-release')
|
||||||
|
|
||||||
gitSemverTags({ tagPrefix, }, async (err, tags) => {
|
gitSemverTags({ tagPrefix, skipUnstable: !prerelease }, async (err, tags) => {
|
||||||
const currentVersion = tags.length > 0 ? tags.shift().replace(tagPrefix, '') : null
|
const currentVersion = tags.length > 0 ? tags.shift().replace(tagPrefix, '') : null
|
||||||
|
|
||||||
// Get the new version
|
// Get the new version
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"name": "Test JSON",
|
||||||
|
"version": "1.4.6-alpha.0"
|
||||||
|
}
|
Loading…
Reference in New Issue