feat: Added versioning through GIT
parent
f4bda96138
commit
7143306125
|
@ -18,3 +18,21 @@ jobs:
|
|||
ENV: 'test'
|
||||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
|
||||
|
||||
test-git:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: "./"
|
||||
|
||||
- name: Generate changelog
|
||||
id: changelog
|
||||
uses: ./
|
||||
env:
|
||||
ENV: 'test'
|
||||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
skip-commit: 'true'
|
||||
|
|
12
README.md
12
README.md
|
@ -79,6 +79,16 @@ Tag only
|
|||
skip-commit: 'true'
|
||||
```
|
||||
|
||||
Use a custom file for versioning
|
||||
|
||||
```yaml
|
||||
- name: Conventional Changelog Action
|
||||
uses: TriPSs/conventional-changelog-action@v3
|
||||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
version-file: 'my-custom-file.yaml'
|
||||
```
|
||||
|
||||
Github releases
|
||||
|
||||
```yaml
|
||||
|
@ -103,7 +113,7 @@ Github releases
|
|||
|
||||
## Development
|
||||
If you'd like to contribute to this project, all you need to do is clone and install [act](https://github.com/nektos/act) this project and run:
|
||||
|
||||
> Make sure that `main: 'src/index.js'` is updated to `main: '../src/index.js'` inside the `action.yml`
|
||||
```shell
|
||||
$ yarn install
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"@actions/exec": "1.0.4",
|
||||
"conventional-changelog": "3.1.21",
|
||||
"conventional-recommended-bump": "6.0.9",
|
||||
"git-semver-tags": "4.0.0",
|
||||
"object-path": "^0.11.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* Bumps the given version with the given release type
|
||||
*
|
||||
* @param releaseType
|
||||
* @param version
|
||||
* @returns {string}
|
||||
*/
|
||||
module.exports = (releaseType, version) => {
|
||||
let [major, minor, patch] = version.split('.')
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return `${major}.${minor}.${patch}`
|
||||
}
|
|
@ -17,9 +17,9 @@ module.exports = new (class Git {
|
|||
const gitUserEmail = core.getInput('git-user-email')
|
||||
|
||||
if (ENV === 'test') {
|
||||
const noop = () => {console.log('skipping because of test env')}
|
||||
|
||||
this.exec = noop
|
||||
this.exec = (command) => {
|
||||
console.log(`Skipping "git ${command}" because of test env`)
|
||||
}
|
||||
}
|
||||
|
||||
// Set config
|
||||
|
|
|
@ -67,7 +67,7 @@ async function run() {
|
|||
versioning.init(path.resolve(versionFile), versionPath)
|
||||
|
||||
// Bump the version in the package.json
|
||||
versioning.bump(
|
||||
await versioning.bump(
|
||||
recommendation.releaseType,
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
const core = require('@actions/core')
|
||||
const gitSemverTags = require('git-semver-tags')
|
||||
|
||||
const bumpVersion = require('../helpers/bumpVersion')
|
||||
|
||||
module.exports = new (class Git {
|
||||
|
||||
newVersion = null
|
||||
|
||||
init = (fileLocation, versionPath) => {}
|
||||
|
||||
bump = (releaseType) => {
|
||||
return new Promise((resolve) => {
|
||||
const tagPrefix = core.getInput('tag-prefix')
|
||||
|
||||
gitSemverTags({
|
||||
tagPrefix,
|
||||
}, (err, tags) => {
|
||||
const currentVersion = tags.shift().replace(tagPrefix, '')
|
||||
|
||||
// Get the new version
|
||||
this.newVersion = bumpVersion(
|
||||
releaseType,
|
||||
currentVersion
|
||||
)
|
||||
|
||||
// We are done
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
const JSON = require('./json')
|
||||
const Git = require('./git')
|
||||
|
||||
module.exports = (fileExtension) => {
|
||||
switch (fileExtension.toLowerCase()) {
|
||||
|
@ -12,8 +13,8 @@ module.exports = (fileExtension) => {
|
|||
// case 'toml':
|
||||
// return Toml
|
||||
//
|
||||
// case 'git':
|
||||
// return Git
|
||||
case 'git':
|
||||
return Git
|
||||
|
||||
default:
|
||||
return null
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
const fs = require('fs')
|
||||
const objectPath = require('object-path')
|
||||
|
||||
const bumpVersion = require('../helpers/bumpVersion')
|
||||
|
||||
module.exports = new (class JSON {
|
||||
|
||||
fileLocation = null
|
||||
|
@ -33,26 +35,11 @@ module.exports = new (class JSON {
|
|||
// Read the JSON file
|
||||
const jsonFile = this.read()
|
||||
|
||||
let [major, minor, patch] = objectPath.get(jsonFile, this.versionPath).split('.')
|
||||
|
||||
// TODO:: Move this to a helper
|
||||
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
|
||||
}
|
||||
|
||||
this.newVersion = `${major}.${minor}.${patch}`
|
||||
// Get the new version
|
||||
this.newVersion = bumpVersion(
|
||||
releaseType,
|
||||
objectPath.get(jsonFile, this.versionPath),
|
||||
)
|
||||
|
||||
// Update the json file with the new version
|
||||
objectPath.set(jsonFile, this.versionPath, this.newVersion)
|
||||
|
|
|
@ -483,7 +483,7 @@ git-remote-origin-url@^2.0.0:
|
|||
gitconfiglocal "^1.0.0"
|
||||
pify "^2.3.0"
|
||||
|
||||
git-semver-tags@^4.0.0:
|
||||
git-semver-tags@4.0.0, git-semver-tags@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/git-semver-tags/-/git-semver-tags-4.0.0.tgz#a9dd58a0dd3561a4a9898b7e9731cf441c98fc38"
|
||||
integrity sha512-LajaAWLYVBff+1NVircURJFL8TQ3EMIcLAfHisWYX/nPoMwnTYfWAznQDmMujlLqoD12VtLmoSrF1sQ5MhimEQ==
|
||||
|
|
Loading…
Reference in New Issue