Skip to content

Commit 436a7a1

Browse files
authored
Merge pull request #61 from shandli123/CAD_REORTING
cad reporting browserstack-report action
2 parents dba20ea + 064d4fb commit 436a7a1

File tree

17 files changed

+56207
-0
lines changed

17 files changed

+56207
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
es2020: true,
5+
mocha: true,
6+
},
7+
extends: 'airbnb-base',
8+
parserOptions: {
9+
ecmaVersion: 11,
10+
sourceType: 'script',
11+
},
12+
rules: {
13+
semi: ['error', 'always'],
14+
indent: ['error', 2, { SwitchCase: 1 }],
15+
quotes: 'off',
16+
'consistent-return': 'off',
17+
'no-underscore-dangle': 'off',
18+
'no-case-declarations': 'error',
19+
'prefer-destructuring': ['error', { object: true, array: false }],
20+
'no-restricted-syntax': 'off',
21+
'linebreak-style': 'off',
22+
},
23+
ignorePatterns: ['dist/index.js'],
24+
};

browserstack-report-action/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Node
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Misc
8+
.DS_Store
9+
10+
# Coverage
11+
coverage/
12+
.nyc_output/

browserstack-report-action/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# BrowserStack Report GitHub Action
2+
3+
This action fetches a report from a (currently dummy) BrowserStack-like API, polls for its completion, and displays the HTML report in the GitHub Actions summary tab.
4+
The polling interval and maximum retries are determined by the initial API response.
5+
6+
## Inputs
7+
8+
- `username` (**required**): Your BrowserStack username.
9+
It's recommended to store this as a GitHub secret.
10+
- `access-key` (**required**): Your BrowserStack access key.
11+
It's recommended to store this as a GitHub secret.
12+
- `build-name` (optional): The name of the build on BrowserStack.
13+
Defaults to `<GitHub Workflow Name>_<GitHub Run ID>`.
14+
- `report-timeout` (optional): User-defined timeout value (in seconds) to be sent to the report API.
15+
Default: `10`.
16+
17+
## Example Usage
18+
19+
```yaml
20+
name: CI with BrowserStack Report
21+
22+
on: [push]
23+
24+
jobs:
25+
test_and_report:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v3
30+
31+
# ... your test steps that trigger a BrowserStack build ...
32+
33+
- name: Fetch BrowserStack Report
34+
# If using a published version:
35+
# uses: your-org/browserstack-report-action@v1
36+
# If using a local version from the same repository:
37+
uses: ./.github/actions/browserstack-report-action
38+
with:
39+
username: ${{ secrets.BROWSERSTACK_USERNAME }}
40+
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
41+
build-name: 'My Awesome App E2E Tests'
42+
#user-timeout can be specified if needed, e.g.:
43+
report-timeout: '10'
44+
```
45+
46+
## Development
47+
48+
1. Clone the repository (or create these files in your existing one).
49+
2. Navigate to the `browserstack-report-action` directory.
50+
3. Run `npm install` to install dependencies.
51+
4. Make changes to the source code in the `src` directory or constants in the `config` directory.
52+
5. Run `npm run build` to compile the action to the `dist` directory.
53+
6. Run `npm test` to run unit tests.
54+
7. Run `npm run all` to run linting, tests, and build.
55+
56+
## Project Structure
57+
58+
```
59+
browserstack-report-action/
60+
├── .gitignore - Gitignore file
61+
├── .eslintrc.js - ESLint configuration
62+
├── action.yml - GitHub Action metadata
63+
├── package.json - Node.js package file
64+
├── README.md - Documentation
65+
├── config/ - Configuration files
66+
│ └── constants.js - Constants used throughout the action
67+
├── dist/ - Compiled code (generated by ncc)
68+
├── src/ - JavaScript source code
69+
│ ├── main.js - Main action code
70+
│ └── actionInput/ - Input handling and validation
71+
│ ├── index.js - ActionInput class
72+
│ └── inputValidator.js - InputValidator class
73+
└── test/ - Test files
74+
└── main.test.js - Tests for main.js
75+
```
76+
77+
## Notes
78+
79+
- The current API interaction is simulated within `src/main.js`. You'll need to replace `fetchDummyReportAPI` with actual API calls to BrowserStack, including proper authentication using the provided username and access key.
80+
- The initial API response is expected to provide `polling_interval` (seconds) and `retry_count` which dictate the polling behavior. If not provided, defaults are used.
81+
- The `report_status` values handled are: `in_progress`, `complete`, `tests_available`, `not_available`, `build_not_found`, `more_than_one_build_found`.
82+
- The HTML report from `report.basic_html` is added to the GitHub Actions summary.

browserstack-report-action/action.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'BrowserStack Report Action'
2+
description: 'Fetches a BrowserStack report and displays it in the GitHub Actions summary.'
3+
author: 'BrowserStack'
4+
5+
inputs:
6+
username:
7+
description: 'Your BrowserStack username.'
8+
required: true
9+
access-key:
10+
description: 'Your BrowserStack access key.'
11+
required: true
12+
build-name:
13+
description: 'The name of the build on BrowserStack. Defaults to GitHub workflow name and run ID.'
14+
required: false
15+
report-timeout:
16+
description: 'User-defined timeout value (in seconds) to be sent to the report API.'
17+
required: false
18+
default: '300'
19+
20+
runs:
21+
using: 'node16'
22+
main: 'dist/index.js'
23+
24+
branding:
25+
icon: 'bar-chart-2'
26+
color: 'blue'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module.exports = {
2+
// Default values
3+
DEFAULT_POLLING_INTERVAL_SECONDS: 3,
4+
DEFAULT_MAX_RETRIES: 3,
5+
DEFAULT_USER_TIMEOUT_SECONDS: 130,
6+
7+
// API simulation constants
8+
MAX_POLLS_FOR_IN_PROGRESS: 3,
9+
10+
// Report formats
11+
REPORT_FORMAT: {
12+
BASIC_HTML: 'basicHtml',
13+
RICH_HTML: 'richHtml',
14+
},
15+
16+
INPUT: {
17+
USERNAME: 'username',
18+
ACCESS_KEY: 'access-key',
19+
BUILD_NAME: 'build-name',
20+
TIMEOUT: 'report-timeout',
21+
},
22+
23+
// Report statuses
24+
REPORT_STATUS: {
25+
IN_PROGRESS: 'IN_PROGRESS',
26+
COMPLETED: 'COMPLETED',
27+
TEST_AVAILABLE: 'TEST_AVAILABLE',
28+
NOT_AVAILABLE: 'NOT_AVAILABLE',
29+
BUILD_NOT_FOUND: 'BUILD_NOT_FOUND',
30+
MULTIPLE_BUILD_FOUND: 'MULTIPLE_BUILD_FOUND',
31+
},
32+
33+
// Integration types
34+
INTEGRATION_TYPE: {
35+
SDK: 'sdk',
36+
NON_SDK: 'non-sdk',
37+
},
38+
39+
// CI system identifiers
40+
CI_SYSTEM: {
41+
GITHUB_ACTIONS: 'github-actions',
42+
},
43+
44+
// REPORT_REQUEST_STATE
45+
REPORT_REQUEST_STATE: {
46+
FIRST: 'FIRST',
47+
POLL: 'POLL',
48+
LAST: 'LAST',
49+
},
50+
};

0 commit comments

Comments
 (0)