Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload CSV to partner portal #96

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 50 additions & 0 deletions bin/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require('fs');
const path = require('path');
const yaml = require('yaml');
const { createObjectCsvWriter } = require('csv-writer');

LDannijs marked this conversation as resolved.
Show resolved Hide resolved
// 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' },
{ id: 'logoUrl', title: 'Logo URL' }
]
});

// 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,
logoUrl: templateData['logo-url']
};
};

// 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"
}
}
Loading