Add YAML merge script
All checks were successful
Generate Release / validate_and_release (push) Successful in 18s
All checks were successful
Generate Release / validate_and_release (push) Successful in 18s
This commit is contained in:
parent
776f4ec5f5
commit
b10df9b578
@ -16,6 +16,12 @@ jobs:
|
|||||||
- name: Validate YAML
|
- name: Validate YAML
|
||||||
uses: https://github.com/GrantBirki/json-yaml-validate@v2.6.1
|
uses: https://github.com/GrantBirki/json-yaml-validate@v2.6.1
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm i
|
||||||
|
|
||||||
|
- name: Merge to gw.yaml
|
||||||
|
run: node ./scripts/merge-yaml.js
|
||||||
|
|
||||||
- name: Create PR
|
- name: Create PR
|
||||||
uses: https://github.com/peter-evans/create-pull-request@v6
|
uses: https://github.com/peter-evans/create-pull-request@v6
|
||||||
with:
|
with:
|
||||||
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
package-lock.json
|
14
package.json
Normal file
14
package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "merge-yaml",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Contains OwlBoard provided data. Queried programatically by the OwlBoard dbmanager application to be loaded into the database.",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"yaml": "^2.4.1"
|
||||||
|
}
|
||||||
|
}
|
41
scripts/merge-yaml.js
Normal file
41
scripts/merge-yaml.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
const yaml = require('yaml')
|
||||||
|
|
||||||
|
const directoryPath = './pis/'
|
||||||
|
|
||||||
|
function sortAndMergeYAMLFiles() {
|
||||||
|
try {
|
||||||
|
const files = fs.readdirSync(directoryPath);
|
||||||
|
|
||||||
|
let mergedData = [];
|
||||||
|
|
||||||
|
files.forEach(file => {
|
||||||
|
const data = fs.readFileSync(directoryPath + file, 'utf-8');
|
||||||
|
|
||||||
|
const parsedData = yaml.parse(data)
|
||||||
|
|
||||||
|
if (parsedData && typeof parsedData === 'object' && parsedData.pis) {
|
||||||
|
mergedData.push(...parsedData.pis)
|
||||||
|
} else {
|
||||||
|
if (Array.isArray(parsedData)) {
|
||||||
|
mergedData.push(...parsedData);
|
||||||
|
} else {
|
||||||
|
console.error("Incorrect YAML")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mergedData.sort((a, b) => {
|
||||||
|
const codeA = parseInt(a.code);
|
||||||
|
const codeB = parseInt(b.code);
|
||||||
|
return codeA - codeB
|
||||||
|
})
|
||||||
|
|
||||||
|
const mergedYaml = yaml.stringify(mergedData);
|
||||||
|
console.log(mergedYaml)
|
||||||
|
} catch(err) {
|
||||||
|
console.error('Error merging YAML:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sortAndMergeYAMLFiles();
|
Loading…
Reference in New Issue
Block a user