fix: Fixed that bumping multiple files with same extension type did only update one

releases/v3
Tycho Bokdam 2020-12-16 17:22:37 +01:00
parent 29d941434b
commit 62453ed268
No known key found for this signature in database
GPG Key ID: A0FAE77C8CDF33C7
8 changed files with 39 additions and 23 deletions

View File

@ -1,5 +1,8 @@
name: 'Test the action'
on: [pull_request]
on:
pull_request:
branches:
- master
jobs:
test-json:
@ -502,21 +505,24 @@ jobs:
EXPECTED_TAG: 'v1.5.0'
with:
github-token: ${{ secrets.github_token }}
version-file: 'test-file.json, test-file.toml, test-file.yaml'
version-file: 'test-file.json, test-file-2.json, test-file.toml, test-file.yaml'
- name: Show files
run: |
echo "$(<test-file.json)"
echo ""
echo "$(<test-file.toml)"
echo ""
echo "$(<test-file.yaml)"
echo "Test json file"
echo "$(<test-file.json)\n\n"
echo "Test json 2 file"
echo "$(<test-file-2.json)\n\n"
echo "Test toml file"
echo "$(<test-file.toml)\n\n"
echo "Test yaml file"
echo "$(<test-file.yaml)\n\n"
- name: Test output
run: node ./test-output.js
env:
FILES: 'test-file.json, test-file.toml, test-file.yaml'
EXPECTED_VERSION: '1.5.0, 1.5.0, 1.11.0'
FILES: 'test-file.json, test-file-2.json, test-file.toml, test-file.yaml'
EXPECTED_VERSION: '1.5.0, 1.5.0, 1.5.0, 1.11.0'
test-config-file-path:
runs-on: ubuntu-latest

View File

@ -4,7 +4,7 @@ const gitSemverTags = require('git-semver-tags')
const BaseVersioning = require('./base')
const bumpVersion = require('../helpers/bumpVersion')
module.exports = new (class Git extends BaseVersioning {
module.exports = class Git extends BaseVersioning {
bump = (releaseType) => {
return new Promise((resolve) => {
@ -27,5 +27,4 @@ module.exports = new (class Git extends BaseVersioning {
})
}
})
}

View File

@ -6,17 +6,17 @@ const Toml = require('./toml')
module.exports = (fileExtension) => {
switch (fileExtension.toLowerCase()) {
case 'json':
return Json
return new Json()
case 'yaml':
case 'yml':
return Yaml
return new Yaml()
case 'toml':
return Toml
return new Toml()
case 'git':
return Git
return new Git()
default:
return null

View File

@ -4,7 +4,7 @@ const objectPath = require('object-path')
const BaseVersioning = require('./base')
const bumpVersion = require('../helpers/bumpVersion')
module.exports = new (class Json extends BaseVersioning {
module.exports = class Json extends BaseVersioning {
/**
* Bumps the version in the package.json
@ -49,5 +49,5 @@ module.exports = new (class Json extends BaseVersioning {
)
}
})
}

View File

@ -5,7 +5,7 @@ const toml = require('@iarna/toml')
const BaseVersioning = require('./base')
const bumpVersion = require('../helpers/bumpVersion')
module.exports = new (class Toml extends BaseVersioning {
module.exports = class Toml extends BaseVersioning {
/**
* Bumps the version in the package.json
@ -46,5 +46,5 @@ module.exports = new (class Toml extends BaseVersioning {
}
}
})
}

View File

@ -5,7 +5,7 @@ const yaml = require('yaml')
const BaseVersioning = require('./base')
const bumpVersion = require('../helpers/bumpVersion')
module.exports = new (class Yaml extends BaseVersioning {
module.exports = class Yaml extends BaseVersioning {
/**
* Bumps the version in the package.json
@ -53,5 +53,4 @@ module.exports = new (class Yaml extends BaseVersioning {
}
}
})
}

4
test-file-2.json 100644
View File

@ -0,0 +1,4 @@
{
"name": "Test JSON file 2",
"version": "1.4.5"
}

View File

@ -18,6 +18,8 @@ assert.ok(FILES, 'Files not defined!')
* Test if all the files are updated
*/
FILES.split(',').map((file, index) => {
console.log(`Going to test file "${file}"`)
const fileContent = fs.readFileSync(file.trim(), 'utf8')
const fileExtension = file.split('.').pop()
@ -43,8 +45,12 @@ FILES.split(',').map((file, index) => {
assert.fail('File extension not supported!')
}
console.log(`"${file}" has a valid extension "${fileExtension.toLowerCase()}"`)
assert.ok(parsedContent, 'Content could not be parsed!')
console.log(`"${file}" has valid content`, parsedContent)
const newVersionInFile = objectPath.get(parsedContent, EXPECTED_VERSION_PATH, null)
const expectedVersions = EXPECTED_VERSION.split(',')
@ -52,6 +58,8 @@ FILES.split(',').map((file, index) => {
? expectedVersions[index]
: expectedVersions
console.log(`"${file}" check if "${newVersionInFile}" matches what is expected "${expectedVersion.trim()}"`)
assert.strictEqual(newVersionInFile, expectedVersion.trim(), 'Version does not match what is expected')
})