Skip to content

Commit

Permalink
Merge pull request #3 from sfishel18/simon/entries-release-artifact
Browse files Browse the repository at this point in the history
adds workflow to generate tarball of dynamo entries
  • Loading branch information
rgraue committed Aug 26, 2024
2 parents c07c481 + de6c19f commit 7a461f2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/workflows/main-branch-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Main Branch

on:
push:
branches:
- main

jobs:
publish-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EndBug/latest-tag@latest
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
shell: bash
run: npm install
- name: Build Entries
shell: bash
run: npm run build:entries
- name: Compress Entries
shell: bash
run: tar -czvf dynamo-entries.tgz ./dynamo-entries
- uses: softprops/action-gh-release@v2
with:
tag_name: latest
files: dynamo-entries.tgz
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/index.ts"
"start": "ts-node src/index.ts",
"build:entries": "ts-node src/scripts/create-dynamo-entries.ts"
},
"keywords": [],
"author": "",
Expand Down
30 changes: 30 additions & 0 deletions src/scripts/create-dynamo-entries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fs from 'fs';
import path from 'path';
import { mapFieldNames } from '../utils/mapping.utils';

const inputDir = path.resolve(__dirname, '../constants/Home_Energy_Data');
const outputDIr = path.resolve(__dirname, '../../dynamo-entries');

(async () => {
try {
const constantsFiles = await fs.promises.readdir(inputDir);
await fs.promises.mkdir(outputDIr);
for (let file of constantsFiles) {
const filePath = `${inputDir}/${file}`
try {
const entries = JSON.parse(await fs.promises.readFile(filePath, { encoding: 'utf-8' }));
await fs.promises.writeFile(
`${outputDIr}/${file}`,
JSON.stringify(entries.map(mapFieldNames), null, 2),
{ flag: 'wx', encoding: 'utf-8' }
)
} catch(e) {
console.error(`Failed processing "${filePath}": ${e}`);
continue;
}
}
} catch (e) {
console.error(`Failed generating Dynamo entries: ${e}`)
process.exit(1);
}
})()

0 comments on commit 7a461f2

Please sign in to comment.