Skip to content

Commit d840f41

Browse files
PubNub SDK v5.1.4 release.
1 parent e3d40b3 commit d840f41

File tree

8 files changed

+378
-44
lines changed

8 files changed

+378
-44
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: validate-pubnub-yml
2+
3+
# Controls when the action will run. Workflow runs when manually triggered using the UI
4+
# or API.
5+
on: [push]
6+
7+
jobs:
8+
build:
9+
name: Validate PubNub yml
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Use Node.js
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: '12.x'
17+
- name: Install dependencies
18+
run: |
19+
npm install [email protected]
20+
npm install [email protected]
21+
npm install [email protected]
22+
npm install [email protected]
23+
- name: Validate
24+
run: GITHUB_TOKEN=${{ secrets.GH_TOKEN }} node ./.github/workflows/validate-yml.js

.github/workflows/validate-yml.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
const YAML = require('yaml')
2+
const Ajv = require('ajv');
3+
const fetch = require('node-fetch');
4+
const fs = require('fs');
5+
const chalk = require('chalk');
6+
7+
const ghToken = process.env.GITHUB_TOKEN;
8+
const ghHeaders = {'User-Agent': 'sdk-bot', 'Authorization': 'token ' + ghToken,'Accept': 'application/vnd.github.v3.raw'};
9+
10+
const sdkReposJSONBranch = "develop";
11+
let sdkReposJSONPath = "http://api.github.com/repos/pubnub/documentation-resources/contents/website-common/tools/build/sdk-repos.json?ref=" + sdkReposJSONBranch;
12+
startExecution(sdkReposJSONPath);
13+
14+
async function startExecution(sdkReposJSONPath){
15+
var sdkRepos = await requestGetFromGithub(sdkReposJSONPath);
16+
var sdkReposAndFeatureMappingArray = parseReposAndFeatureMapping(sdkRepos);
17+
var schemaText = await requestGetFromGithub(sdkReposAndFeatureMappingArray[2]);
18+
19+
schema = JSON.parse(schemaText);
20+
var yaml = fs.readFileSync(".pubnub.yml", 'utf8');
21+
22+
if(yaml != null){
23+
yml = YAML.parse(yaml);
24+
var ajv = new Ajv({schemaId: 'id', "verbose":true, "allErrors": true});
25+
const validate = ajv.compile(schema);
26+
const valid = validate(yml);
27+
if (validate.errors!= null) {
28+
console.log(chalk.cyan("==================================="));
29+
console.log(chalk.red(yml["version"] + " validation errors..."));
30+
console.log(chalk.cyan("==================================="));
31+
console.log(validate.errors);
32+
console.log(chalk.cyan("==================================="));
33+
var result = {code:1, repo: yml["version"], msg: "validation errors"};
34+
printResult(result);
35+
process.exit(1);
36+
}
37+
else {
38+
var result = {code: 0, repo: yml["version"], msg: "validation pass"};
39+
printResult(result);
40+
}
41+
} else {
42+
var result = {code:1, repo: "yml null", msg: "validation errors"};
43+
printResult(result);
44+
process.exit(1);
45+
}
46+
}
47+
48+
function printResult(result){
49+
var str = result.repo + ", " + result.msg;
50+
if(result.code === 0){
51+
console.log(chalk.green(str) + ", Code: " + result.code);
52+
} else {
53+
console.log(chalk.red(str) + ", Code: " + result.code);
54+
}
55+
}
56+
57+
async function requestGetFromGithub(url){
58+
try {
59+
const response = await fetch(url, {
60+
headers: ghHeaders,
61+
method: 'get',
62+
});
63+
if(response.status == 200){
64+
const json = await response.text();
65+
return json;
66+
} else {
67+
console.error(chalk.red("res.status: " + response.status + "\n URL: " + url));
68+
return null;
69+
}
70+
71+
} catch (error) {
72+
console.error(chalk.red("requestGetFromGithub: " + error + "\n URL: " + url));
73+
return null;
74+
}
75+
}
76+
77+
function parseReposAndFeatureMapping(body){
78+
if(body != null){
79+
var sdkRepos = JSON.parse(body);
80+
var locations = sdkRepos["locations"];
81+
if(locations!=null){
82+
var sdkURLs = locations["sdks"];
83+
var featureMappingURL = locations["featureMapping"];
84+
var pubnubYAMLSchemaURL = locations["pubnubYAMLSchema"];
85+
return [sdkURLs, featureMappingURL, pubnubYAMLSchemaURL];
86+
} else {
87+
console.log(chalk.red("response locations null"));
88+
return null;
89+
}
90+
} else {
91+
console.log(chalk.red("response body null"));
92+
return null;
93+
}
94+
}

0 commit comments

Comments
 (0)