Skip to content

Commit cd09d4e

Browse files
committed
ci: integration test config with secrets
1 parent ae7a9d7 commit cd09d4e

File tree

8 files changed

+212
-170
lines changed

8 files changed

+212
-170
lines changed

.github/workflows/build_verify.yml

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
name: Build verification on push to main branch
2-
3-
on:
4-
push:
5-
branches: [ main ]
6-
7-
jobs:
8-
build-tasks:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v3
12-
- name: Npm Install
13-
run: |
14-
npm ci
15-
- name: eslint using npm run eslint
16-
run: |
17-
npm run lint
18-
- name: building build
19-
run: |
20-
npm run build
21-
- name: Unit tests with coverage
22-
run: |
23-
npm run cover:unit
24-
- name: Running Integration tests
25-
run: |
26-
npm run test:integ
1+
name: Build verification on push to main branch
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
build-tasks:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Npm Install
13+
run: |
14+
npm ci
15+
- name: eslint using npm run eslint
16+
run: |
17+
npm run lint
18+
- name: building build
19+
run: |
20+
npm run build
21+
- name: Unit tests with coverage
22+
run: |
23+
npm run cover:unit
24+
- name: Running Integration tests
25+
env:
26+
APP_CONFIG_FOR_INTEG_TESTS: ${{ secrets.APP_CONFIG_FOR_INTEG_TESTS || '' }}
27+
run: |
28+
npm run test:integ
Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,107 @@
1-
// goto this link for all available GitHub rest api functions. https://octokit.github.io/rest.js/v18#repos-update
2-
3-
console.log("Hello");
4-
5-
let github, context, org, repoName;
6-
7-
async function createIssue(title, body){
8-
await github.rest.issues.create({
9-
owner: org,
10-
repo: repoName,
11-
title: title,
12-
body: body
13-
});
14-
}
15-
16-
async function setupRepositoryDefaults(){
17-
// send a message to code guardian action repo eventually to enable auto setup https://github.com/aicore/Code-Guardian-Actions
18-
}
19-
20-
function _isValidRepoInitEvent(){
21-
if(context.eventName !== 'create'){
22-
return false;
23-
}
24-
if(!context.ref.endsWith(`/${context.payload.master_branch}`)){
25-
return false;
26-
}
27-
return true;
28-
}
29-
30-
async function initRepo(details){
31-
github = details.github;
32-
context = details.context;
33-
org = details.org;
34-
repoName = details.repoName;
35-
if(!_isValidRepoInitEvent()){
36-
console.log("Not a valid repo creation event. This task is only meant to be executed at repo creation. Exiting!");
37-
return;
38-
}
39-
await createIssue("Update package.json with your app defaults", _getPackageJsonComment());
40-
await createIssue("Verify Build actions on pull requests.", _getVerifyBuildActionComment());
41-
await createIssue("Enable Github Wikis for API docs", _getEnableWikiComment());
42-
await createIssue("Enable Sonar Cloud Code Checks", _getSonarSetupComment());
43-
await createIssue("Setup Repository settings", _setupRepoComment());
44-
}
45-
46-
function _setupRepoComment(){
47-
return `
48-
## Setup repository settings
49-
Setup your repository default settings. Goto this url https://github.com/${org}/${repoName}/settings
50-
51-
- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow merge commits \`
52-
- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow auto-merge \`. This is to prevent GitHub secrets leak after malicious pull request auto merges.
53-
- [ ] In \`Settings> General> Pull Requests\` check/enable \`Automatically delete head branches \`
54-
- [ ] Delete the file \`.github/workflows/setup_repository.yml\ and \`.github/workflows/js/setupRepository.cjs\`
55-
`;
56-
}
57-
58-
59-
function _getSonarSetupComment(){
60-
return `
61-
## Enable Sonar Cloud Code Scan for this repo
62-
Sonar cloud does code scanning for core.ai repos. Ensure that sonar cloud is enabled for this repo.
63-
64-
Usually available in this URL: https://sonarcloud.io/project/overview?id=${org}_${repoName}
65-
![image](https://user-images.githubusercontent.com/5336369/148695840-65585d04-5e59-450b-8794-54ca3c62b9fe.png)
66-
67-
- [ ] Contact an core.ai org administrator to enable sonar scan for this repo.
68-
- [ ] Verified that soncar scan code checks are available in your pull requests.
69-
- [ ] Get you sonar cloud ID for the repo. It will usually look like \`${org}_${repoName}\` for ${org} repos.
70-
- [ ] Update \`readme.md\` with sonar badges by replacing all \`aicore_template-nodejs-ts\` with the id you got above. See this link for a sample pull request : https://github.com/aicore/libcache/pull/13
71-
- [ ] Update \`readme.md\` build verification badge by replacing this line \`[![<app> build verification](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml/badge.svg)](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml)\`
72-
with \`[![<app> build verification](https://github.com/${org}/${repoName}/actions/workflows/build_verify.yml/badge.svg)](https://github.com/${org}/${repoName}/actions/workflows/build_verify.yml)\`
73-
`;
74-
}
75-
76-
function _getEnableWikiComment(){
77-
return `
78-
## Enable Github Wikis for API docs
79-
API Docs are autogenerated with core.ai repos. Got to the below wiki url and create a home page in wiki to start generating API docs.
80-
https://github.com/${org}/${repoName}/wiki
81-
- [ ] Created a home wiki page
82-
- [ ] Verified that api docs are generated after a push to main branch is done.
83-
`;
84-
}
85-
86-
function _getVerifyBuildActionComment(){
87-
return `
88-
## Verify that build actions
89-
We use GitHub actions extensively. Verify that Github Actions are being executed with the following url
90-
https://github.com/${org}/${repoName}/actions
91-
- [ ] All Build actions functioning as expected
92-
`;
93-
}
94-
95-
function _getPackageJsonComment(){
96-
return `
97-
## Update package.json with your app defaults
98-
- [ ] update package name to \`@aicore/${repoName}\`
99-
- [ ] update description
100-
- [ ] update keywords
101-
- [ ] update author
102-
- [ ] update bugs url
103-
- [ ] update homepage url
104-
`;
105-
}
106-
107-
module.exports.initRepo = initRepo;
1+
// goto this link for all available GitHub rest api functions. https://octokit.github.io/rest.js/v18#repos-update
2+
3+
console.log("Hello");
4+
5+
let github, context, org, repoName;
6+
7+
async function createIssue(title, body){
8+
await github.rest.issues.create({
9+
owner: org,
10+
repo: repoName,
11+
title: title,
12+
body: body
13+
});
14+
}
15+
16+
async function setupRepositoryDefaults(){
17+
// send a message to code guardian action repo eventually to enable auto setup https://github.com/aicore/Code-Guardian-Actions
18+
}
19+
20+
function _isValidRepoInitEvent(){
21+
if(context.eventName !== 'create'){
22+
return false;
23+
}
24+
if(!context.ref.endsWith(`/${context.payload.master_branch}`)){
25+
return false;
26+
}
27+
return true;
28+
}
29+
30+
async function initRepo(details){
31+
github = details.github;
32+
context = details.context;
33+
org = details.org;
34+
repoName = details.repoName;
35+
if(!_isValidRepoInitEvent()){
36+
console.log("Not a valid repo creation event. This task is only meant to be executed at repo creation. Exiting!");
37+
return;
38+
}
39+
await createIssue("Update package.json with your app defaults", _getPackageJsonComment());
40+
await createIssue("Verify Build actions on pull requests.", _getVerifyBuildActionComment());
41+
await createIssue("Enable Github Wikis for API docs", _getEnableWikiComment());
42+
await createIssue("Enable Sonar Cloud Code Checks", _getSonarSetupComment());
43+
await createIssue("Setup Repository settings", _setupRepoComment());
44+
}
45+
46+
function _setupRepoComment(){
47+
return `
48+
## Setup repository settings
49+
Setup your repository default settings. Goto this url https://github.com/${org}/${repoName}/settings
50+
51+
- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow merge commits \`
52+
- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow auto-merge \`. This is to prevent GitHub secrets leak after malicious pull request auto merges.
53+
- [ ] In \`Settings> General> Pull Requests\` check/enable \`Automatically delete head branches \`
54+
- [ ] Delete the file \`.github/workflows/setup_repository.yml\ and \`.github/workflows/js/setupRepository.cjs\`
55+
`;
56+
}
57+
58+
59+
function _getSonarSetupComment(){
60+
return `
61+
## Enable Sonar Cloud Code Scan for this repo
62+
Sonar cloud does code scanning for core.ai repos. Ensure that sonar cloud is enabled for this repo.
63+
64+
Usually available in this URL: https://sonarcloud.io/project/overview?id=${org}_${repoName}
65+
![image](https://user-images.githubusercontent.com/5336369/148695840-65585d04-5e59-450b-8794-54ca3c62b9fe.png)
66+
67+
- [ ] Contact an core.ai org administrator to enable sonar scan for this repo.
68+
- [ ] Verified that soncar scan code checks are available in your pull requests.
69+
- [ ] Get you sonar cloud ID for the repo. It will usually look like \`${org}_${repoName}\` for ${org} repos.
70+
- [ ] Update \`readme.md\` with sonar badges by replacing all \`aicore_template-nodejs-ts\` with the id you got above. See this link for a sample pull request : https://github.com/aicore/libcache/pull/13
71+
- [ ] Update \`readme.md\` build verification badge by replacing this line \`[![<app> build verification](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml/badge.svg)](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml)\`
72+
with \`[![<app> build verification](https://github.com/${org}/${repoName}/actions/workflows/build_verify.yml/badge.svg)](https://github.com/${org}/${repoName}/actions/workflows/build_verify.yml)\`
73+
`;
74+
}
75+
76+
function _getEnableWikiComment(){
77+
return `
78+
## Enable Github Wikis for API docs
79+
API Docs are autogenerated with core.ai repos. Got to the below wiki url and create a home page in wiki to start generating API docs.
80+
https://github.com/${org}/${repoName}/wiki
81+
- [ ] Created a home wiki page
82+
- [ ] Verified that api docs are generated after a push to main branch is done.
83+
`;
84+
}
85+
86+
function _getVerifyBuildActionComment(){
87+
return `
88+
## Verify that build actions
89+
We use GitHub actions extensively. Verify that Github Actions are being executed with the following url
90+
https://github.com/${org}/${repoName}/actions
91+
- [ ] All Build actions functioning as expected
92+
`;
93+
}
94+
95+
function _getPackageJsonComment(){
96+
return `
97+
## Update package.json with your app defaults
98+
- [ ] update package name to \`@aicore/${repoName}\`
99+
- [ ] update description
100+
- [ ] update keywords
101+
- [ ] update author
102+
- [ ] update bugs url
103+
- [ ] update homepage url
104+
`;
105+
}
106+
107+
module.exports.initRepo = initRepo;
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
name: Build verification on pull request
2-
3-
on:
4-
pull_request:
5-
branches: [ main ]
6-
7-
jobs:
8-
build-tasks:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v3
12-
- name: Npm Install
13-
run: |
14-
npm ci
15-
- name: eslint using npm run eslint
16-
run: |
17-
npm run lint
18-
- name: building build
19-
run: |
20-
npm run build
21-
- name: Unit tests with coverage
22-
run: |
23-
npm run cover:unit
24-
- name: Running Integration tests
25-
# SECURITY WARNING: Remove integration test run (this step) on pull request if any secret access is required to run integration tests.
26-
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
27-
run: |
28-
npm run test:integ
1+
name: Build verification on pull request
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
build-tasks:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Npm Install
13+
run: |
14+
npm ci
15+
- name: eslint using npm run eslint
16+
run: |
17+
npm run lint
18+
- name: building build
19+
run: |
20+
npm run build
21+
- name: Unit tests with coverage
22+
run: |
23+
npm run cover:unit
24+
- name: Running Integration tests
25+
# SECURITY WARNING: Remove integration test run (this step) on pull request if any secret access is required to run integration tests.
26+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
27+
run: |
28+
npm run test:integ

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ lerna-debug.log*
99
# config files
1010
src/.app.json
1111
src/app.json
12+
src/testConfig.json
1213

1314
# IDE exclusions
1415
.idea

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export APP_CONFIG=./src/.app.json
1111
npm install
1212
npm run serve
1313

14-
# To hit end point
15-
curl -X GET 'http://127.0.0.1:5000/hello?name=rambo' -H 'authorization: Basic 123' -H 'Content-Type: application/json' -v
14+
# To hit end point, go to browser url http://127.0.0.1:5000/hello?name=rambo
15+
# or to hit the authenticated url, do the curl command below
16+
curl -X GET 'http://127.0.0.1:5000/helloAuth?name=rambo' -H 'authorization: Basic 123' -H 'Content-Type: application/json' -v
1617

1718
```
1819

@@ -79,7 +80,27 @@ To Automatically fix lint errors:
7980

8081
## Testing
8182

82-
To run all tests:
83+
### Run unit tests
84+
```shell
85+
> npm run test:unit
86+
```
87+
88+
### Running integration tests locally
89+
90+
```shell
91+
> npm run test:integ
92+
```
93+
You can edit `src/testConfig.json` to change app config for tests after running the above command.
94+
95+
### Running integration tests in GitHub actions
96+
You have to set a repository secret `APP_CONFIG_FOR_INTEG_TESTS` with
97+
content of the text config.
98+
* Goto your repository settings https://github.com/<your org>/<your repo>/settings/secrets/actions
99+
* Create a new `Repository secret` with name `APP_CONFIG_FOR_INTEG_TESTS` and the secret as the config file contents.
100+
* The build verify action should now be able to use the secret.
101+
* Note that pull requests cannot read repository secrets and subsequently cannot run integration tests.
102+
103+
### To run all tests:
83104

84105
```shell
85106
> npm run test

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"prepare": "test -d node_modules/husky && husky install || echo \"husky is not installed\"",
2222
"test": "npm run test:unit && npm run test:integ",
2323
"test:unit": "APP_CONFIG=./test/unit/utils/.app.json mocha test/unit/*.spec.js test/unit/**/*.spec.js test/unit/**/*.spec.js test/unit/**/**/*.spec.js --timeout=3000",
24-
"test:integ": "APP_CONFIG=./test/integration/.app.json mocha test/integration/*.spec.js test/integration/**/*.spec.js --timeout=3000",
24+
"setupIntegTestConfig": "node ./test/integration/setupTestConfig.js",
25+
"test:integ": "npm run setupIntegTestConfig && APP_CONFIG=./src/testConfig.json mocha test/integration/*.spec.js test/integration/**/*.spec.js --timeout=3000",
2526
"printReportsLink": "echo Detailed unit test coverage report: file:///$(pwd)/coverage-unit/index.html && echo Detailed integration test coverage report: file:///$(pwd)/coverage-integration/index.html",
2627
"cover": "npm run cover:unit",
2728
"cover:unit": "c8 -c .nycrc.unit.json npm run test:unit && npm run --silent printReportsLink",

test/integration/.app.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)