feat: Added support for yaml files
parent
7143306125
commit
bdf8ec04e6
|
@ -1,15 +1,17 @@
|
|||
name: 'Action to test the action locally with act'
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- branch-that-does-not-exist
|
||||
|
||||
jobs:
|
||||
test:
|
||||
test-json:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: "./conventional-changelog-action"
|
||||
|
||||
- run: cd conventional-changelog-action && yarn --production
|
||||
path: "./"
|
||||
|
||||
- name: Generate changelog
|
||||
id: changelog
|
||||
|
@ -19,7 +21,6 @@ jobs:
|
|||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
|
||||
|
||||
test-git:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
@ -36,3 +37,39 @@ jobs:
|
|||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
skip-commit: 'true'
|
||||
|
||||
test-yaml:
|
||||
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 }}
|
||||
version-file: 'test-file.yaml'
|
||||
version-path: 'package.version'
|
||||
|
||||
test-toml:
|
||||
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 }}
|
||||
version-file: 'test-file.toml'
|
||||
version-path: 'package.version'
|
||||
|
|
14
README.md
14
README.md
|
@ -114,11 +114,21 @@ 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`
|
||||
> Note: The image used is 18 gb!
|
||||
```shell
|
||||
$ yarn install
|
||||
|
||||
# We need the full 18 gb image because we use GIT
|
||||
$ act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=<your token>
|
||||
# To run / test json versioning
|
||||
$ act -j test-json -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=<your token>
|
||||
|
||||
# To run / test git versioning
|
||||
$ act -j test-git -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=<your token>
|
||||
|
||||
# To run / test yaml versioning
|
||||
$ act -j test-yaml -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=<your token>
|
||||
|
||||
# To run / toml git versioning
|
||||
$ act -j test-toml -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=<your token>
|
||||
```
|
||||
|
||||
## [License](./LICENSE)
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
"conventional-changelog": "3.1.21",
|
||||
"conventional-recommended-bump": "6.0.9",
|
||||
"git-semver-tags": "4.0.0",
|
||||
"object-path": "^0.11.4"
|
||||
"object-path": "^0.11.4",
|
||||
"toml": "^3.0.0",
|
||||
"yaml": "^1.10.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
const conventionalRecommendedBump = require('conventional-recommended-bump')
|
||||
|
||||
async function run() {
|
||||
conventionalRecommendedBump({ preset: 'angular', tagPrefix: 'v' }, async(error, recommendation, tag) => {
|
||||
console.log(recommendation, tag)
|
||||
})
|
||||
}
|
||||
|
||||
run()
|
|
@ -0,0 +1,52 @@
|
|||
const fs = require('fs')
|
||||
|
||||
module.exports = class BaseVersioning {
|
||||
|
||||
fileLocation = null
|
||||
|
||||
versionPath = null
|
||||
|
||||
newVersion = null
|
||||
|
||||
/**
|
||||
* Set some basic configurations
|
||||
*
|
||||
* @param {!string} fileLocation - Full location of the file
|
||||
* @param {!string} versionPath - Path inside the file where the version is located
|
||||
*/
|
||||
init = (fileLocation, versionPath) => {
|
||||
this.fileLocation = fileLocation
|
||||
this.versionPath = versionPath
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file's content
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
read = () => {
|
||||
return fs.readFileSync(this.fileLocation, 'utf8')
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic for bumping the version
|
||||
*
|
||||
* @param {!string} releaseType - The type of release
|
||||
* @return {*}
|
||||
*/
|
||||
bump = (releaseType) => {
|
||||
throw new Error('Implement bump logic in class!')
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the file
|
||||
*
|
||||
* @param {!string} newContent - New content for the file
|
||||
* @return {*}
|
||||
*/
|
||||
update = (newContent) => (
|
||||
fs.writeFileSync(this.fileLocation, newContent)
|
||||
)
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,10 @@
|
|||
const core = require('@actions/core')
|
||||
const gitSemverTags = require('git-semver-tags')
|
||||
|
||||
const BaseVersioning = require('./base')
|
||||
const bumpVersion = require('../helpers/bumpVersion')
|
||||
|
||||
module.exports = new (class Git {
|
||||
|
||||
newVersion = null
|
||||
|
||||
init = (fileLocation, versionPath) => {}
|
||||
module.exports = new (class Git extends BaseVersioning {
|
||||
|
||||
bump = (releaseType) => {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -21,7 +18,7 @@ module.exports = new (class Git {
|
|||
// Get the new version
|
||||
this.newVersion = bumpVersion(
|
||||
releaseType,
|
||||
currentVersion
|
||||
currentVersion,
|
||||
)
|
||||
|
||||
// We are done
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
const JSON = require('./json')
|
||||
const Git = require('./git')
|
||||
const Yaml = require('./yaml')
|
||||
|
||||
module.exports = (fileExtension) => {
|
||||
switch (fileExtension.toLowerCase()) {
|
||||
case 'json':
|
||||
return JSON
|
||||
case 'yaml':
|
||||
case 'yml':
|
||||
return Yaml
|
||||
|
||||
|
||||
// case 'yaml':
|
||||
// case 'yml':
|
||||
// return Yaml
|
||||
//
|
||||
// case 'toml':
|
||||
// return Toml
|
||||
//
|
||||
case 'git':
|
||||
return Git
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
const objectPath = require('object-path')
|
||||
const yaml = require('yaml')
|
||||
|
||||
const BaseVersioning = require('./base')
|
||||
const bumpVersion = require('../helpers/bumpVersion')
|
||||
|
||||
module.exports = new (class Yaml extends BaseVersioning{
|
||||
|
||||
/**
|
||||
* Bumps the version in the package.json
|
||||
*
|
||||
* @param {!string} releaseType - The type of release
|
||||
* @return {*}
|
||||
*/
|
||||
bump = (releaseType) => {
|
||||
// Read the file
|
||||
const fileContent = this.read()
|
||||
const yamlContent = yaml.parse(fileContent)
|
||||
const oldVersion = objectPath.get(yamlContent, this.versionPath)
|
||||
|
||||
// Get the new version
|
||||
this.newVersion = bumpVersion(
|
||||
releaseType,
|
||||
oldVersion,
|
||||
)
|
||||
|
||||
// Get the name of where the version is in
|
||||
const versionName = this.versionPath.split('.').pop()
|
||||
|
||||
// Update the file
|
||||
this.update(
|
||||
// We use replace instead of yaml.stringify so we can preserve white spaces and comments
|
||||
fileContent.replace(
|
||||
`${versionName}: '${oldVersion}'`,
|
||||
`${versionName}: '${this.newVersion}'`,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package:
|
||||
version: '0.1.0'
|
||||
|
||||
# Comment
|
||||
different:
|
||||
props:
|
||||
- one
|
||||
- two
|
10
yarn.lock
10
yarn.lock
|
@ -1307,6 +1307,11 @@ through@2, "through@>=2.2.7 <3":
|
|||
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
|
||||
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
|
||||
|
||||
toml@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee"
|
||||
integrity sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==
|
||||
|
||||
trim-newlines@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
|
||||
|
@ -1383,6 +1388,11 @@ xtend@~4.0.1:
|
|||
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
|
||||
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==
|
||||
|
||||
yaml@^1.10.0:
|
||||
version "1.10.0"
|
||||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"
|
||||
integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==
|
||||
|
||||
yargs-parser@^18.1.3:
|
||||
version "18.1.3"
|
||||
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0"
|
||||
|
|
Loading…
Reference in New Issue