Skip to content

Mock report generation GHA #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f85cbf1
cad reporting browserstack-report action
shandli123 May 13, 2025
1191a0a
fix report timeout input name
shandli123 May 13, 2025
24ad8b8
input params change
shandli123 May 14, 2025
c9c01d8
testing with mock
shandli123 May 14, 2025
e3ed5d0
fixes
shandli123 May 14, 2025
9c3a9d4
update html
shandli123 May 14, 2025
7a34ff7
remove title
shandli123 May 14, 2025
8c8824a
artifact addition
shandli123 May 14, 2025
ecb45cd
artifact addition package name
shandli123 May 14, 2025
8f1c36e
artifact addition package name
shandli123 May 14, 2025
9e72c6c
artifact addition package name
shandli123 May 14, 2025
15d297d
artifact addition package name
shandli123 May 14, 2025
2ece26b
artifact addition package name
shandli123 May 14, 2025
12cf39a
artifact addition package name
shandli123 May 14, 2025
e0687b5
add fix for artifact
shandli123 May 14, 2025
6291e29
add fix for artifact
shandli123 May 14, 2025
c492cc5
add fix for artifact
shandli123 May 14, 2025
f19c9ec
add fix for artifact
shandli123 May 14, 2025
efc800e
add fix for artifact
shandli123 May 14, 2025
47c3991
add fix for artifact
shandli123 May 14, 2025
a58af3c
add fix for artifact
shandli123 May 14, 2025
408dbd0
add fix for artifact
shandli123 May 14, 2025
f823dbb
add fix for artifact
shandli123 May 14, 2025
b5ef1d0
add fix for artifact debug
shandli123 May 14, 2025
daa6a94
add fix for artifact debug
shandli123 May 14, 2025
aa49dfd
add fix for artifact debug
shandli123 May 15, 2025
b2e7673
add fix for artifact debug
shandli123 May 15, 2025
472c5f1
add fix for artifact debug
shandli123 May 15, 2025
96b6c96
add fix for artifact debug
shandli123 May 15, 2025
7c0b532
add fix for artifact debug
shandli123 May 15, 2025
7410733
add fix for artifact debug
shandli123 May 15, 2025
daa63f3
add fix for artifact debug
shandli123 May 15, 2025
f2653b1
add fix for artifact debug
shandli123 May 15, 2025
e375ae4
add fix for artifact debug
shandli123 May 15, 2025
afdff2b
add fix for artifact debug
shandli123 May 15, 2025
f8d1609
add fix for artifact debug
shandli123 May 15, 2025
6a72559
add fix for artifact debug
shandli123 May 15, 2025
f1b38b6
add fix for artifact debug
shandli123 May 15, 2025
ea45eae
add fix for artifact debug package.json change
shandli123 May 15, 2025
b072b0e
add fix for artifact debug package.json change
shandli123 May 15, 2025
bcbc474
add fix for artifact debug package.json change
shandli123 May 15, 2025
c6c1a35
add fix for artifact debug package.json change
shandli123 May 15, 2025
b98259e
artifact name update
shandli123 May 15, 2025
332a73c
linting fixes
shandli123 May 15, 2025
e748ba4
adding default numbers
shandli123 May 15, 2025
a88ad67
adding default numbers and sanitizing
shandli123 May 15, 2025
110767d
camel case params
shandli123 May 15, 2025
721b7c4
linting fixes
shandli123 May 15, 2025
ef251f9
readme update
shandli123 May 15, 2025
5b916a5
Update browserstack-report-action/src/utils/UploadFileForArtifact.js
shandli123 May 15, 2025
412efc7
commemnt resolution
shandli123 May 15, 2025
7a08922
commemnt resolution
shandli123 May 15, 2025
00f0327
updating buildCreatedAt type to timestamp
shandli123 May 15, 2025
4880a2c
status variable fix
shandli123 May 16, 2025
31f135e
adding check for intial report fetching
shandli123 May 16, 2025
2f790e5
remove additional error scenarios
shandli123 May 16, 2025
0b6cc9c
adding default time out
shandli123 May 16, 2025
a21daaf
refactoring code
shandli123 May 19, 2025
d9b6328
removing static function
shandli123 May 19, 2025
cdffece
removing static function
shandli123 May 19, 2025
064ba03
adding pollingInterval setter
shandli123 May 19, 2025
b777462
removing static function
shandli123 May 19, 2025
d5ff664
adding new variable for code clarity
shandli123 May 19, 2025
fed47c9
test
shandli123 May 19, 2025
33edbc7
testing \n revert
shandli123 May 19, 2025
59f509b
mock report code
shandli123 May 21, 2025
5e0241b
contract changes
shandli123 May 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions browserstack-report-action/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
env: {
node: true,
es2020: true,
mocha: true,
},
extends: 'airbnb-base',
parserOptions: {
ecmaVersion: 11,
sourceType: 'script',
},
rules: {
semi: ['error', 'always'],
indent: ['error', 2, { SwitchCase: 1 }],
quotes: 'off',
'consistent-return': 'off',
'no-underscore-dangle': 'off',
'no-case-declarations': 'error',
'prefer-destructuring': ['error', { object: true, array: false }],
'no-restricted-syntax': 'off',
'linebreak-style': 'off',
},
ignorePatterns: ['dist/index.js'],
};
13 changes: 13 additions & 0 deletions browserstack-report-action/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Node
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json

# Misc
.DS_Store

# Coverage
coverage/
.nyc_output/
82 changes: 82 additions & 0 deletions browserstack-report-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# BrowserStack Report GitHub Action

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.
The polling interval and maximum retries are determined by the initial API response.

## Inputs

- `username` (**required**): Your BrowserStack username.
It's recommended to store this as a GitHub secret.
- `access-key` (**required**): Your BrowserStack access key.
It's recommended to store this as a GitHub secret.
- `build-name` (optional): The name of the build on BrowserStack.
Defaults to `<GitHub Workflow Name>_<GitHub Run ID>`.
- `report-timeout` (optional): User-defined timeout value (in seconds) to be sent to the report API.
Default: `10`.

## Example Usage

```yaml
name: CI with BrowserStack Report

on: [push]

jobs:
test_and_report:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

# ... your test steps that trigger a BrowserStack build ...

- name: Fetch BrowserStack Report
# If using a published version:
# uses: your-org/browserstack-report-action@v1
# If using a local version from the same repository:
uses: ./.github/actions/browserstack-report-action
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
build-name: 'My Awesome App E2E Tests'
#user-timeout can be specified if needed, e.g.:
report-timeout: '10'
```

## Development

1. Clone the repository (or create these files in your existing one).
2. Navigate to the `browserstack-report-action` directory.
3. Run `npm install` to install dependencies.
4. Make changes to the source code in the `src` directory or constants in the `config` directory.
5. Run `npm run build` to compile the action to the `dist` directory.
6. Run `npm test` to run unit tests.
7. Run `npm run all` to run linting, tests, and build.

## Project Structure

```
browserstack-report-action/
├── .gitignore - Gitignore file
├── .eslintrc.js - ESLint configuration
├── action.yml - GitHub Action metadata
├── package.json - Node.js package file
├── README.md - Documentation
├── config/ - Configuration files
│ └── constants.js - Constants used throughout the action
├── dist/ - Compiled code (generated by ncc)
├── src/ - JavaScript source code
│ ├── main.js - Main action code
│ └── actionInput/ - Input handling and validation
│ ├── index.js - ActionInput class
│ └── inputValidator.js - InputValidator class
└── test/ - Test files
└── main.test.js - Tests for main.js
```

## Notes

- 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.
- 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.
- The `report_status` values handled are: `in_progress`, `complete`, `tests_available`, `not_available`, `build_not_found`, `more_than_one_build_found`.
- The HTML report from `report.basic_html` is added to the GitHub Actions summary.
26 changes: 26 additions & 0 deletions browserstack-report-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'BrowserStack Report Action'
description: 'Fetches a BrowserStack report and displays it in the GitHub Actions summary.'
author: 'BrowserStack'

inputs:
username:
description: 'Your BrowserStack username.'
required: true
access-key:
description: 'Your BrowserStack access key.'
required: true
build-name:
description: 'The name of the build on BrowserStack. Defaults to GitHub workflow name and run ID.'
required: false
report-timeout:
description: 'User-defined timeout value (in seconds) to be sent to the report API.'
required: false
default: '300'

runs:
using: 'node16'
main: 'dist/index.js'

branding:
icon: 'bar-chart-2'
color: 'blue'
50 changes: 50 additions & 0 deletions browserstack-report-action/config/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = {
// Default values
DEFAULT_POLLING_INTERVAL_SECONDS: 3,
DEFAULT_MAX_RETRIES: 3,
DEFAULT_USER_TIMEOUT_SECONDS: 120,

// API simulation constants
MAX_POLLS_FOR_IN_PROGRESS: 3,

// Report formats
REPORT_FORMAT: {
BASIC_HTML: 'basicHtml',
RICH_HTML: 'richHtml',
},

INPUT: {
USERNAME: 'username',
ACCESS_KEY: 'access-key',
BUILD_NAME: 'build-name',
TIMEOUT: 'report-timeout',
},

// Report statuses
REPORT_STATUS: {
IN_PROGRESS: 'IN_PROGRESS',
COMPLETED: 'COMPLETED',
TEST_AVAILABLE: 'TEST_AVAILABLE',
NOT_AVAILABLE: 'NOT_AVAILABLE',
BUILD_NOT_FOUND: 'BUILD_NOT_FOUND',
MULTIPLE_BUILD_FOUND: 'MULTIPLE_BUILD_FOUND',
},

// Integration types
INTEGRATION_TYPE: {
SDK: 'sdk',
NON_SDK: 'non-sdk',
},

// CI system identifiers
CI_SYSTEM: {
GITHUB_ACTIONS: 'github-actions',
},

// REPORT_REQUEST_STATE
REPORT_REQUEST_STATE: {
FIRST: 'FIRST',
POLL: 'POLL',
LAST: 'LAST',
},
};
Loading