Skip to content

Commit c004476

Browse files
authored
Merge pull request #1 from vinodbhorge/git-action
#SBCOSS-157-Feat: Github-Action - Validate PR: Unit Tests and Linting
2 parents 5dc00bf + dd57bfc commit c004476

File tree

5 files changed

+183
-50
lines changed

5 files changed

+183
-50
lines changed

.eslintrc

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

.eslintrc.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// this plugin is used to make all rules default to warnings
2+
equire('eslint-plugin-only-warn');
3+
4+
module.exports = {
5+
extends: 'standard',
6+
plugins: ['only-warn'], // makes all rules default to warnings
7+
ignorePatterns: ['gulpfile.js', 'webpack.config.js', 'app/bower_components/**'],
8+
globals: {
9+
org: true,
10+
CryptoJS: true,
11+
_: true,
12+
$: true,
13+
angular: true,
14+
ecEditor: true,
15+
EkTelemetry: true,
16+
EkstepEditor: true,
17+
EkstepEditorAPI: true,
18+
Class: true,
19+
UUID: true,
20+
WebFontConfig: true,
21+
TextWYSIWYG: true,
22+
ManifestGenerator: true,
23+
WebFont: true,
24+
fabric: true,
25+
ServiceConstants: true,
26+
async: true,
27+
Fingerprint2: true,
28+
describe: true,
29+
jasmine: true,
30+
afterAll: true,
31+
beforeAll: true,
32+
it: true,
33+
spyOn: true,
34+
expect: true,
35+
xit: true,
36+
EventBus: true,
37+
beforeEach: true,
38+
canvas: true,
39+
Plugin: true,
40+
createjs: true,
41+
p: true,
42+
basePlugin: true,
43+
Mousetrap: true,
44+
afterEach: true,
45+
location: true,
46+
X2JS: true
47+
},
48+
rules: {
49+
indent: [2, 'tab'],
50+
'no-tabs': 0,
51+
'no-throw-literal': 'error',
52+
}
53+
}

.github/workflows/pull-request.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Build and Test on Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '**'
7+
8+
env:
9+
CONTENT_PLUGIN_VERSION: ${{ vars.CONTENT_PLUGIN_VERSION || 'release-8.0.0' }}
10+
11+
jobs:
12+
build-test:
13+
runs-on: ubuntu-latest
14+
env:
15+
version_number: ${{ github.ref_name }}
16+
build_number: ${{ github.run_number }}
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
- name: Set up Node.js 10
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: 10.24.1
25+
26+
- name: Cache node modules
27+
uses: actions/cache@v3
28+
with:
29+
path: node_modules
30+
key: ${{ runner.os }}-node-${{ hashFiles('package.json') }}
31+
32+
- name: Clone plugins (from fork)
33+
run: |
34+
git clone --branch ${{ env.CONTENT_PLUGIN_VERSION }} https://github.com/vinodbhorge/sunbird-content-plugins.git plugins
35+
36+
- name: Install dependencies
37+
run: |
38+
which bower || sudo npm install -g [email protected]
39+
which grunt || sudo npm install -g [email protected]
40+
which gulp || sudo npm install -g [email protected]
41+
sudo apt-get install build-essential libpng-dev
42+
43+
- name: Bower cache clean
44+
working-directory: app
45+
run: bower cache clean --allow-root
46+
47+
- name: Bower install
48+
working-directory: app
49+
run: bower install --force --allow-root
50+
51+
- name: Install global npm packages
52+
run: npm install --legacy-peer-deps
53+
54+
- name: Gulp packageCorePlugins
55+
run: gulp packageCorePlugins
56+
57+
- name: Plugin build
58+
run: npm run plugin-build
59+
60+
- name: Run build
61+
run: npm run build
62+
63+
- name: Test
64+
run: npm run test
65+
continue-on-error: true
66+
67+
- name: Set up Node.js 14 (for Sonar)
68+
uses: actions/setup-node@v3
69+
with:
70+
node-version: 14
71+
72+
- name: Install SonarQube scanner
73+
run: npm install -g sonarqube-scanner
74+
75+
- name: Run SonarQube scanner
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
79+
run: sonar-scanner
80+
81+
lint:
82+
needs: build-test
83+
runs-on: ubuntu-latest
84+
85+
steps:
86+
- name: Checkout code
87+
uses: actions/checkout@v3
88+
89+
- name: Set up Node.js 18
90+
uses: actions/setup-node@v3
91+
with:
92+
node-version: 18
93+
94+
- name: Cache node modules
95+
uses: actions/cache@v3
96+
with:
97+
path: node_modules
98+
key: ${{ runner.os }}-node-${{ hashFiles('package.json') }}
99+
100+
- name: Run Lint
101+
run: npm run lint

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,27 @@ We use [SemVer](https://semver.org/) for versioning. For the versions available,
170170
171171
## Any Issues?
172172
We have an open and active [issue tracker](https://project-sunbird.atlassian.net/issues/). Please report any issues.
173+
174+
# GitHub Actions
175+
176+
## Build and Test on Pull Request
177+
178+
This GitHub Actions workflow runs **build, test, and lint checks** automatically when a pull request is opened against any branch.
179+
180+
### When It Runs
181+
182+
- **Trigger**: On every `pull_request` to any branch (`'**'`)
183+
184+
### Prerequisites Before Triggering
185+
186+
Make sure the following are set up **before** opening a pull request:
187+
188+
### Secrets
189+
`SONAR_TOKEN`: For SonarQube authentication
190+
191+
### Repository Variables
192+
`CONTENT_PLUGIN_VERSION`: Have to specify the branch or tag you want fetch. By default it will take `release-8.0.0`
193+
194+
Note: The secrets and variables should be set in Github UI (`settings/secrets and variables/actions`).
195+
196+
For any changes to the workflow, update the file `.github/workflows/build-test.yml` accordingly.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
"css-tree": "1.0.0-alpha.29",
2626
"csso": "3.5.1",
2727
"cssnano": "4.1.10",
28-
"eslint": "^5.6.0",
28+
"eslint": "^8.57.1",
2929
"global": "^4.4.0",
3030
"eslint-plugin-import": "^2.14.0",
3131
"eslint-plugin-node": "^7.0.1",
3232
"eslint-plugin-promise": "^4.0.1",
3333
"eslint-plugin-standard": "^4.0.0",
34+
"eslint-config-standard": "^12.0.0",
35+
"eslint-plugin-only-warn": "^1.0.4",
3436
"expose-loader": "^0.7.5",
3537
"express-http-proxy": "^1.2.0",
3638
"extract": "^1.0.0",
@@ -105,7 +107,8 @@
105107
"plugin-build": "webpack --config webpack.plugin.config.js",
106108
"build-editor": "npm run test && npm run collection-plugins && npm run build",
107109
"test": "karma start karmaconf.js",
108-
"build-npm-pkg": "gulp packageCorePlugins && npm run plugin-build && webpack --env.channel=NPM_PACKAGE && cd generic-editor && gulp copystyleImages && gulp clean && gulp injectrenamedfiles"
110+
"build-npm-pkg": "gulp packageCorePlugins && npm run plugin-build && webpack --env.channel=NPM_PACKAGE && cd generic-editor && gulp copystyleImages && gulp clean && gulp injectrenamedfiles",
111+
"lint": "eslint . --quiet"
109112
},
110113
"repository": {
111114
"type": "git",

0 commit comments

Comments
 (0)