feat: Added versioning through GIT

releases/v3
Tycho Bokdam 2020-07-01 19:31:50 +02:00
parent f4bda96138
commit 7143306125
No known key found for this signature in database
GPG Key ID: A0FAE77C8CDF33C7
10 changed files with 107 additions and 28 deletions

View File

@ -18,3 +18,21 @@ jobs:
ENV: 'test' ENV: 'test'
with: with:
github-token: ${{ secrets.github_token }} 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'

View File

@ -79,6 +79,16 @@ Tag only
skip-commit: 'true' 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 Github releases
```yaml ```yaml
@ -103,7 +113,7 @@ Github releases
## Development ## 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: 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 ```shell
$ yarn install $ yarn install

View File

@ -22,6 +22,7 @@
"@actions/exec": "1.0.4", "@actions/exec": "1.0.4",
"conventional-changelog": "3.1.21", "conventional-changelog": "3.1.21",
"conventional-recommended-bump": "6.0.9", "conventional-recommended-bump": "6.0.9",
"git-semver-tags": "4.0.0",
"object-path": "^0.11.4" "object-path": "^0.11.4"
} }
} }

View File

@ -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}`
}

View File

@ -17,9 +17,9 @@ module.exports = new (class Git {
const gitUserEmail = core.getInput('git-user-email') const gitUserEmail = core.getInput('git-user-email')
if (ENV === 'test') { if (ENV === 'test') {
const noop = () => {console.log('skipping because of test env')} this.exec = (command) => {
console.log(`Skipping "git ${command}" because of test env`)
this.exec = noop }
} }
// Set config // Set config

View File

@ -67,7 +67,7 @@ async function run() {
versioning.init(path.resolve(versionFile), versionPath) versioning.init(path.resolve(versionFile), versionPath)
// Bump the version in the package.json // Bump the version in the package.json
versioning.bump( await versioning.bump(
recommendation.releaseType, recommendation.releaseType,
) )

34
src/version/git.js 100644
View File

@ -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()
})
})
}
})

View File

@ -1,4 +1,5 @@
const JSON = require('./json') const JSON = require('./json')
const Git = require('./git')
module.exports = (fileExtension) => { module.exports = (fileExtension) => {
switch (fileExtension.toLowerCase()) { switch (fileExtension.toLowerCase()) {
@ -12,8 +13,8 @@ module.exports = (fileExtension) => {
// case 'toml': // case 'toml':
// return Toml // return Toml
// //
// case 'git': case 'git':
// return Git return Git
default: default:
return null return null

View File

@ -1,6 +1,8 @@
const fs = require('fs') const fs = require('fs')
const objectPath = require('object-path') const objectPath = require('object-path')
const bumpVersion = require('../helpers/bumpVersion')
module.exports = new (class JSON { module.exports = new (class JSON {
fileLocation = null fileLocation = null
@ -33,26 +35,11 @@ module.exports = new (class JSON {
// Read the JSON file // Read the JSON file
const jsonFile = this.read() const jsonFile = this.read()
let [major, minor, patch] = objectPath.get(jsonFile, this.versionPath).split('.') // Get the new version
this.newVersion = bumpVersion(
// TODO:: Move this to a helper releaseType,
switch (releaseType) { objectPath.get(jsonFile, this.versionPath),
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}`
// Update the json file with the new version // Update the json file with the new version
objectPath.set(jsonFile, this.versionPath, this.newVersion) objectPath.set(jsonFile, this.versionPath, this.newVersion)

View File

@ -483,7 +483,7 @@ git-remote-origin-url@^2.0.0:
gitconfiglocal "^1.0.0" gitconfiglocal "^1.0.0"
pify "^2.3.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" version "4.0.0"
resolved "https://registry.yarnpkg.com/git-semver-tags/-/git-semver-tags-4.0.0.tgz#a9dd58a0dd3561a4a9898b7e9731cf441c98fc38" resolved "https://registry.yarnpkg.com/git-semver-tags/-/git-semver-tags-4.0.0.tgz#a9dd58a0dd3561a4a9898b7e9731cf441c98fc38"
integrity sha512-LajaAWLYVBff+1NVircURJFL8TQ3EMIcLAfHisWYX/nPoMwnTYfWAznQDmMujlLqoD12VtLmoSrF1sQ5MhimEQ== integrity sha512-LajaAWLYVBff+1NVircURJFL8TQ3EMIcLAfHisWYX/nPoMwnTYfWAznQDmMujlLqoD12VtLmoSrF1sQ5MhimEQ==