forked from ringcentral/pubnub-jtools
-
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.
- Loading branch information
1 parent
f09f565
commit cef9c0d
Showing
67 changed files
with
2,448 additions
and
853 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
* @kleewho @bartk @budgetpreneur | ||
* @kleewho @bartk @budgetpreneur | ||
.travis/* @parfeon @kleewho @bartk @budgetpreneur | ||
|
||
README.md @polarweasel @samiahmedsiddiqui @techwritermat |
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,24 @@ | ||
name: validate-pubnub-yml | ||
|
||
# Controls when the action will run. Workflow runs when manually triggered using the UI | ||
# or API. | ||
on: [push] | ||
|
||
jobs: | ||
build: | ||
name: Validate PubNub yml | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '12.x' | ||
- name: Install dependencies | ||
run: | | ||
npm install ajv@6.12.6 | ||
npm install yaml@1.10.0 | ||
npm install node-fetch@2.6.1 | ||
npm install chalk@2.4.2 | ||
- name: Validate | ||
run: GITHUB_TOKEN=${{ secrets.GH_TOKEN }} node ./.github/workflows/validate-yml.js |
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,94 @@ | ||
const YAML = require('yaml') | ||
const Ajv = require('ajv'); | ||
const fetch = require('node-fetch'); | ||
const fs = require('fs'); | ||
const chalk = require('chalk'); | ||
|
||
const ghToken = process.env.GITHUB_TOKEN; | ||
const ghHeaders = {'User-Agent': 'sdk-bot', 'Authorization': 'token ' + ghToken,'Accept': 'application/vnd.github.v3.raw'}; | ||
|
||
const sdkReposJSONBranch = "develop"; | ||
let sdkReposJSONPath = "http://api.github.com/repos/pubnub/documentation-resources/contents/website-common/tools/build/sdk-repos.json?ref=" + sdkReposJSONBranch; | ||
startExecution(sdkReposJSONPath); | ||
|
||
async function startExecution(sdkReposJSONPath){ | ||
var sdkRepos = await requestGetFromGithub(sdkReposJSONPath); | ||
var sdkReposAndFeatureMappingArray = parseReposAndFeatureMapping(sdkRepos); | ||
var schemaText = await requestGetFromGithub(sdkReposAndFeatureMappingArray[2]); | ||
|
||
schema = JSON.parse(schemaText); | ||
var yaml = fs.readFileSync(".pubnub.yml", 'utf8'); | ||
|
||
if(yaml != null){ | ||
yml = YAML.parse(yaml); | ||
var ajv = new Ajv({schemaId: 'id', "verbose":true, "allErrors": true}); | ||
const validate = ajv.compile(schema); | ||
const valid = validate(yml); | ||
if (validate.errors!= null) { | ||
console.log(chalk.cyan("===================================")); | ||
console.log(chalk.red(yml["version"] + " validation errors...")); | ||
console.log(chalk.cyan("===================================")); | ||
console.log(validate.errors); | ||
console.log(chalk.cyan("===================================")); | ||
var result = {code:1, repo: yml["version"], msg: "validation errors"}; | ||
printResult(result); | ||
process.exit(1); | ||
} | ||
else { | ||
var result = {code: 0, repo: yml["version"], msg: "validation pass"}; | ||
printResult(result); | ||
} | ||
} else { | ||
var result = {code:1, repo: "yml null", msg: "validation errors"}; | ||
printResult(result); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function printResult(result){ | ||
var str = result.repo + ", " + result.msg; | ||
if(result.code === 0){ | ||
console.log(chalk.green(str) + ", Code: " + result.code); | ||
} else { | ||
console.log(chalk.red(str) + ", Code: " + result.code); | ||
} | ||
} | ||
|
||
async function requestGetFromGithub(url){ | ||
try { | ||
const response = await fetch(url, { | ||
headers: ghHeaders, | ||
method: 'get', | ||
}); | ||
if(response.status == 200){ | ||
const json = await response.text(); | ||
return json; | ||
} else { | ||
console.error(chalk.red("res.status: " + response.status + "\n URL: " + url)); | ||
return null; | ||
} | ||
|
||
} catch (error) { | ||
console.error(chalk.red("requestGetFromGithub: " + error + "\n URL: " + url)); | ||
return null; | ||
} | ||
} | ||
|
||
function parseReposAndFeatureMapping(body){ | ||
if(body != null){ | ||
var sdkRepos = JSON.parse(body); | ||
var locations = sdkRepos["locations"]; | ||
if(locations!=null){ | ||
var sdkURLs = locations["sdks"]; | ||
var featureMappingURL = locations["featureMapping"]; | ||
var pubnubYAMLSchemaURL = locations["pubnubYAMLSchema"]; | ||
return [sdkURLs, featureMappingURL, pubnubYAMLSchemaURL]; | ||
} else { | ||
console.log(chalk.red("response locations null")); | ||
return null; | ||
} | ||
} else { | ||
console.log(chalk.red("response body null")); | ||
return null; | ||
} | ||
} |
Oops, something went wrong.