Skip to content

Commit

Permalink
Merge pull request #96 from LDannijs/partner-portal
Browse files Browse the repository at this point in the history
Upload CSV to partner portal
  • Loading branch information
KrishnaIyer authored Jun 17, 2024
2 parents 7571851 + eae0d37 commit 6882f08
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/upload-airtable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Upload to Airtable

on:
push:
branches:
- master

jobs:
csv:
name: Upload CSV to Airtable
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Node.js dependencies
run: npm ci
- name: Create templates.csv
run: node bin/csv.js
- name: Upload to Airtable
run: |
curl POST ${{ secrets.AIRTABLE_WEBHOOKS_API_ENDPOINT }} \
-H "Authorization: Bearer ${{ secrets.AIRTABLE_WEBHOOKS_API_KEY }}" \
-H "Content-Type: text/csv" \
--data-binary "@bin/templates.csv"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/templates.csv
node_modules
48 changes: 48 additions & 0 deletions bin/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('fs');
const path = require('path');
const yaml = require('yaml');
const { createObjectCsvWriter } = require('csv-writer');

// Define paths to the templates.yml file and the directory containing the template files
const templatesYmlPath = path.join(__dirname, '..', 'templates.yml');
const templatesDir = path.join(__dirname, '..');

// Read and parse the templates.yml file
const templatesYml = fs.readFileSync(templatesYmlPath, 'utf8');
const templateNames = yaml.parse(templatesYml);

// Define the CSV writer
const csvWriter = createObjectCsvWriter({
path: path.join(__dirname, 'templates.csv'),
header: [
{ id: 'name', title: 'Name' },
{ id: 'description', title: 'Description' },
{ id: 'documentationUrl', title: 'Documentation URL' },
{ id: 'format', title: 'Format' },
]
});

// Function to read and parse each template file
const readTemplateFile = (templateName) => {
const templateFilePath = path.join(templatesDir, `${templateName}.yml`);
const templateYml = fs.readFileSync(templateFilePath, 'utf8');
const templateData = yaml.parse(templateYml);
let format = templateData.format;
if (format === 'json') {
format = format.toUpperCase();
}
return {
name: templateData.name,
description: templateData.description,
documentationUrl: templateData['documentation-url'],
format: format,
};
};

// Collect data from each template file
const templatesData = templateNames.map(templateName => readTemplateFile(templateName));

// Write data to CSV
csvWriter.writeRecords(templatesData)
.then(() => console.log('Templates data written to templates.csv'))
.catch(err => console.error('Error writing to CSV file', err));
110 changes: 110 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"csv-writer": "^1.6.0",
"fs": "^0.0.1-security",
"path": "^0.12.7",
"yaml": "^2.4.3"
}
}

0 comments on commit 6882f08

Please sign in to comment.