-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from LDannijs/partner-portal
Upload CSV to partner portal
- Loading branch information
Showing
5 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/templates.csv | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |