Skip to content

Commit

Permalink
fix: Fixed that bumping multiple files with same extension type did o…
Browse files Browse the repository at this point in the history
…nly update one
  • Loading branch information
TriPSs committed Dec 16, 2020
1 parent 29d9414 commit 62453ed
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Test the action'
on: [pull_request]
on:
pull_request:
branches:
- master

jobs:
test-json:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/version/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -27,5 +27,4 @@ module.exports = new (class Git extends BaseVersioning {
})
}

})

}
8 changes: 4 additions & 4 deletions src/version/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/version/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,5 +49,5 @@ module.exports = new (class Json extends BaseVersioning {
)
}

})
}

4 changes: 2 additions & 2 deletions src/version/toml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,5 +46,5 @@ module.exports = new (class Toml extends BaseVersioning {
}
}

})
}

5 changes: 2 additions & 3 deletions src/version/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,5 +53,4 @@ module.exports = new (class Yaml extends BaseVersioning {
}
}

})

}
4 changes: 4 additions & 0 deletions test-file-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Test JSON file 2",
"version": "1.4.5"
}
8 changes: 8 additions & 0 deletions test-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -43,15 +45,21 @@ 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(',')
const expectedVersion = expectedVersions.length > 0
? 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')
})

0 comments on commit 62453ed

Please sign in to comment.