Add actions to handle PIS merge and releases
All checks were successful
Generate Release / validate_and_release (push) Successful in 10s
All checks were successful
Generate Release / validate_and_release (push) Successful in 10s
This commit is contained in:
35
.gitea/workflows/auto_pr.yaml
Normal file
35
.gitea/workflows/auto_pr.yaml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: Generate Release
|
||||||
|
|
||||||
|
run-name: Release_Generator
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- auto-*
|
||||||
|
- workflow_update
|
||||||
|
- pis-*
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
validate_and_release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Check out Repo code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Validate YAML
|
||||||
|
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: Commit Changes
|
||||||
|
uses: https://github.com/stefanzweifel/git-auto-commit-action@v5
|
||||||
|
with:
|
||||||
|
commit_message: Sort & Merge PIS Files
|
||||||
|
commit_user_name: owlbot
|
||||||
|
commit_user_email: owlbot@owlboard.info
|
||||||
|
commit_author: Robotic Owl <owlbot@owlboard.info>
|
||||||
32
.gitea/workflows/release.yaml
Normal file
32
.gitea/workflows/release.yaml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
name: Generate Release
|
||||||
|
|
||||||
|
run-name: Release_Generator
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
validate_and_release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out Repo code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Validate YAML
|
||||||
|
uses: https://github.com/GrantBirki/json-yaml-validate@v2.6.1
|
||||||
|
|
||||||
|
- name: Get current timestamp
|
||||||
|
id: timestamp
|
||||||
|
run: echo "::set-output name=date::$(date +'%Y%m%d_%H%M%S')"
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
if: success()
|
||||||
|
uses: akkuman/gitea-release-action@v1
|
||||||
|
env:
|
||||||
|
NODE_OPTIONS: '--experimental-fetch'
|
||||||
|
with:
|
||||||
|
body: Automatic release after changes
|
||||||
|
tag_name: ${{ steps.timestamp.outputs.date }}
|
||||||
|
name: ${{ steps.timestamp.outputs.date }}
|
||||||
|
token: ${{ secrets.OWLBOT_KEY }}
|
||||||
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
69
scripts/merge-yaml.js
Normal file
69
scripts/merge-yaml.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
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
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Construct the output string, removing duplicates
|
||||||
|
let outputString = "pis:\n";
|
||||||
|
const seenCodes = new Set();
|
||||||
|
mergedData.forEach(item => {
|
||||||
|
if (!seenCodes.has(item.code) && item.stops.length > 0) {
|
||||||
|
seenCodes.add(item.code);
|
||||||
|
outputString += ` - code: "${item.code}"\n`;
|
||||||
|
outputString += ` stops: [${item.stops.map(stop => `${stop}`).join(',')}]\n`;
|
||||||
|
outputString += ` toc: "${item.toc || "gw"}"\n`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.writeFileSync('./pis/codes.yaml', outputString);
|
||||||
|
console.log("Overwritten codes.yaml")
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error writing codes.yaml", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any files created by dgp2
|
||||||
|
files.forEach(file => {
|
||||||
|
if (file.startsWith('auto-')) {
|
||||||
|
fs.unlinkSync(directoryPath + file);
|
||||||
|
console.log(`Deleted file: ${file}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch(err) {
|
||||||
|
console.error('Error merging YAML:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sortAndMergeYAMLFiles();
|
||||||
Reference in New Issue
Block a user