-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from Bandwidth/SWI-2821
SWI-2821 Migrate to Internal Action
- Loading branch information
Showing
12 changed files
with
11,560 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,18 @@ | ||
# Test the CLI | ||
name: Test CLI | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
test-cli: | ||
name: Test CLI | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Test CLI | ||
run: | | ||
npm i | ||
npm run test |
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,21 @@ | ||
name: API Specs Combine Action | ||
description: A GitHub Action that combines the Bandwidth Product API specs into one file for SDK generation. | ||
inputs: | ||
username: | ||
required: false | ||
description: Github Username | ||
default: DX-Bandwidth | ||
token: | ||
required: true | ||
description: Github Token | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Clone and Combine Product Specs | ||
run: | | ||
git clone https://${{ inputs.username }}:${{ inputs.token }}@github.com/Bandwidth/api-specs | ||
cd ${{ github.action_path }} | ||
npm i | ||
node index.js --config oas-merge-config.yml --path ${{ github.workspace }} | ||
shell: bash |
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,75 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const yaml = require('js-yaml'); | ||
const { merge, isErrorResult } = require('openapi-merge'); | ||
const argv = require('minimist')(process.argv.slice(2)); | ||
|
||
function buildSpecArray(config, basePath) { | ||
const mergeArray = []; | ||
for (i in config.inputs) { | ||
let apiSpec = yaml.load( | ||
fs.readFileSync(`${basePath}${configFile.inputs[i].inputFile}`, 'utf8') | ||
); | ||
let servers = apiSpec.servers; | ||
|
||
for (specPath in apiSpec.paths) { | ||
apiSpec.paths[specPath].servers = servers; | ||
} | ||
|
||
delete apiSpec.info; | ||
delete apiSpec.servers; | ||
|
||
mergeObj = { | ||
oas: apiSpec, | ||
}; | ||
|
||
mergeArray.push(mergeObj); | ||
} | ||
return mergeArray; | ||
} | ||
|
||
function mergeSpecs(mergeArray) { | ||
const mergeResult = merge(mergeArray); | ||
if (isErrorResult(mergeResult)) { | ||
console.error(`${mergeResult.message} (${mergeResult.type})`); | ||
} else { | ||
console.log(`Merge successful!`); | ||
// console.log(JSON.stringify(mergeResult.output, null, 2)); | ||
return mergeResult; | ||
} | ||
} | ||
|
||
function main(config, basePath) { | ||
const mergeArray = buildSpecArray(config, basePath); | ||
const apiSpec = mergeSpecs(mergeArray).output; | ||
|
||
let info = { | ||
title: 'Bandwidth', | ||
description: `Bandwidth's Communication APIs`, | ||
contact: { | ||
name: 'Bandwidth', | ||
url: 'https://dev.bandwidth.com', | ||
email: 'letstalk@bandwidth.com', | ||
}, | ||
version: '1.0.0', | ||
}; | ||
apiSpec.info = info; | ||
|
||
/** | ||
* Only save the file if the -t/--test flag is not present | ||
*/ | ||
fileExtension = path.extname(configFile.output); | ||
if( argv.t != true && argv.test != true ){ | ||
if(fileExtension == '.json'){ | ||
fs.writeFileSync(`${basePath}${configFile.output}`, JSON.stringify(apiSpec, null, 4), 'utf8'); | ||
} else if(fileExtension == '.yaml' || fileExtension == '.yml'){ | ||
fs.writeFileSync(`${basePath}${configFile.output}`, yaml.dump(apiSpec)); | ||
} else { | ||
throw new Error('Unsupported output file type. Only `.json`, `.yaml`, and `.yml` are supported.'); | ||
} | ||
} | ||
} | ||
|
||
const configFile = yaml.load(fs.readFileSync(argv.c || argv.config, 'utf8')); | ||
const basePath = argv.path; | ||
main(configFile, basePath); |
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,7 @@ | ||
--- | ||
inputs: | ||
- inputFile: "/api-specs/external/messaging.yml" | ||
- inputFile: "/api-specs/external/voice.yml" | ||
- inputFile: "/api-specs/external/multi-factor-auth.yml" | ||
- inputFile: "/api-specs/external/phone-number-lookup.yml" | ||
output: "/api-specs/bandwidth.yml" |
Oops, something went wrong.