Skip to content

Commit

Permalink
add utlity flow
Browse files Browse the repository at this point in the history
  • Loading branch information
jablonnc committed Oct 27, 2023
1 parent 64402b5 commit 390f319
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 187 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Default workflow for triggering E2E tests when a PR comment is left

This is the [default workflow](../../frontend_runtime_utility_manual_e2e_trigger.yml) that is leveraged to trigger E2E tests for for a `utility runtime`. Specifically, when a PR is opened and a comment of `/run-e2e-tests` is left, it will trigger E2E tests in other repos.

## Inputs

This action takes the following inputs:

| Name | Type | Default | Required | Description |
| --------------------------- | ------- | ---------------------------- | --------- | -------------------------------------------------------------------------------------- |
| `fallback_runner` | String | False | False | If true will leverage ubuntu-latest, otherwise will fall back to the J1 in-house runner
| `e2e_pass_on_error` | Boolean | false | False | Pass the workflow even if the E2E test fail
| `repos_to_test` | String | | False | The relative route the magic url should go to

## Secrets

This action takes the following secrets:

| Name | Required | Description |
| --------------------------- | --------- | ----------------------------------------- |
| `NPM_TOKEN` | True | A J1 npm.com Publish token
| `E2E_AUTO` | False | A J1 token for kicking off cypress tests in other repos

## Example Usage

### Default Flow

#### Usage

```yaml
# Triggered by adding a comment to a PR
on:
issue_comment:
types: [created]

jobs:
trigger_e2e_tests:
# Check if the comments come from pull request and contains '/run-e2e-test'
if: github.event.issue.pull_request && contains(github.event.comment.body, '/run-e2e-tests')
uses: jupiterone/.github/.github/workflows/frontend_runtime_application_pr.yml@v#
secrets:
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
E2E_AUTO: ${{ secrets.E2E_AUTO }}
```
#### Diagram
```mermaid
graph LR;
A[start flow];
B[e2e_pending_status];
C[migration_number];
D[magic_url];
E[e2e_trigger_remote_tests];
F[external_repo];
G[e2e_status];

A --> B --> C --> D --> E -->|trigger E2E tests and wait| F -->|report back status| E --> G;
```
45 changes: 2 additions & 43 deletions .github/workflows/docs/frontend/frontend_runtime_utility_pr.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Default workflow for a runtime application when a PR is opened
# Default workflow for a utility runtime when a PR is opened


This is the [default workflow](../../frontend_runtime_application_pr.yml) that is run when a `PR is opened` for a `utility runtime`. It is meant to test the quality and safety of the code being committed.
This is the [default workflow](../../frontend_runtime_utility_pr.yml) that is run when a `PR is opened` for a `utility runtime`. It is meant to test the quality and safety of the code being committed.

## Inputs

Expand All @@ -12,9 +12,6 @@ This action takes the following inputs:
| `fallback_runner` | String | False | False | If true will leverage ubuntu-latest, otherwise will fall back to the J1 in-house runner
| `use_validate` | Boolean | True | False | Run validation, in most case we want this
| `use_chromatic` | Boolean | false | False | Run VRT Storybook tests with chromatic
| `use_e2e_trigger` | Boolean | false | False | Trigger E2E tests in other repos
| `e2e_pass_on_error` | Boolean | false | False | Pass the workflow even if the E2E test fail
| `repos_to_test` | String | | False | The relative route the magic url should go to

## Secrets

Expand All @@ -24,7 +21,6 @@ This action takes the following secrets:
| --------------------------- | --------- | ----------------------------------------- |
| `NPM_TOKEN` | True | A J1 npm.com Publish token
| `CHROMATIC_PROJECT_TOKEN` | False | The Chromatic API token
| `E2E_AUTO` | False | A J1 token for kicking off cypress tests

## Example Usage

Expand All @@ -38,7 +34,6 @@ jobs:
uses: jupiterone/.github/.github/workflows/frontend_runtime_utility_pr.yml@v#
secrets:
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
E2E_AUTO: ${{ secrets.E2E_AUTO }}
```
#### Diagram
Expand Down Expand Up @@ -69,7 +64,6 @@ jobs:
use_chromatic: true
secrets:
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
E2E_AUTO: ${{ secrets.E2E_AUTO }}
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
```
Expand All @@ -91,38 +85,3 @@ graph LR;
B --> C;
```

### With E2E Trigger

#### Usage

```yaml
jobs:
pr:
uses: jupiterone/.github/.github/workflows/frontend_runtime_application_pr.yml@v#
with:
use_e2e_trigger: true
secrets:
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
E2E_AUTO: ${{ secrets.E2E_AUTO }}
```
#### Diagram
```mermaid
graph LR;
A[start flow];

B[migration_number];
C[validate];
D[magic_url];
E[e2e_trigger_remote_tests];
F[external_repo];
G[e2e_status];
H[security];

B --> D --> E -->|trigger E2E tests and wait| F -->|report back status| E --> G;

A --> B;
A --> C;
A --> H;
```
112 changes: 112 additions & 0 deletions .github/workflows/frontend_runtime_utility_manual_e2e_trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Default workflow for a runtime utility when a PR is opened

on:
workflow_call:
inputs:
fallback_runner:
description: "If true will leverage ubuntu-latest, otherwise will fall back to the J1 in-house runner"
default: false
type: boolean
e2e_pass_on_error:
description: "Pass the workflow even if the E2E test fail"
type: boolean
default: false
repos_to_test:
description: "Kick off a n+ spec files within n+ repos"
type: string
secrets:
NPM_TOKEN:
description: "A J1 npm.com Publish token"
required: true
E2E_AUTO:
description: "A J1 token for kicking off cypress tests"
required: false

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
e2e_pending_status:
runs-on: ${{ (inputs.fallback_runner && 'ubuntu-latest') || 'scaleset-jupiterone-infra-arm64' }}
steps:
- uses: actions/checkout@v3
- name: e2e_pending_status
uses: jupiterone/.github/.github/actions/frontend/runtime/e2e_pending_status
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

migration_number:
runs-on: ${{ (inputs.fallback_runner && 'ubuntu-latest') || 'scaleset-jupiterone-infra-arm64' }}
outputs:
migration: ${{ steps.migration_number.outputs.migration }}
steps:
- uses: actions/checkout@v3
- id: migration_number
name: migration_number
uses: jupiterone/.github/.github/actions/frontend/runtime/migration_number@v2

magic_url:
runs-on: ${{ (inputs.fallback_runner && 'ubuntu-latest') || 'scaleset-jupiterone-infra-arm64' }}
needs: [migration_number]
permissions:
id-token: write
statuses: write
contents: read
issues: read
pull-requests: read
steps:
- uses: actions/checkout@v3
- name: setup_env
uses: jupiterone/.github/.github/actions/setup_env@v2
with:
use_dev: true
- name: build
uses: jupiterone/.github/.github/actions/build@v2
- name: magic_url
uses: jupiterone/.github/.github/actions/frontend/runtime/magic_url@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
migration_number: ${{ needs.migration_number.outputs.migration }}
# runtime utilities do not have a route of there own, so we default to home
magic_url_route: '/home'

e2e_trigger_remote_tests:
runs-on: ${{ (inputs.fallback_runner && 'ubuntu-latest') || 'scaleset-jupiterone-infra-arm64' }}
needs: [magic_url]
strategy:
matrix:
repos: ${{ fromJson(inputs.repos_to_test) }}
continue-on-error: ${{ inputs.e2e_pass_on_error }}
outputs:
test_passed: ${{ steps.e2e_trigger_remote_tests.outputs.test_passed }}
steps:
- uses: actions/checkout@v3
- name: setup_env
uses: jupiterone/.github/.github/actions/setup_env@v2
with:
use_dev: true
- id: e2e_trigger_remote_tests
name: e2e_trigger_remote_tests
uses: jupiterone/.github/.github/actions/frontend/runtime/e2e_trigger_remote_tests@v2
with:
e2e_pass_on_error: ${{ inputs.e2e_pass_on_error }}
e2e_auto: ${{ secrets.E2E_AUTO }}
repo_name: ${{ matrix.repos.repo.name }}
repo_spec: ${{ matrix.repos.repo.spec }}

e2e_status:
name: E2E Status
runs-on: ${{ (inputs.fallback_runner && 'ubuntu-latest') || 'scaleset-jupiterone-infra-arm64' }}
needs: [e2e_pending_status, e2e_trigger_remote_tests]
steps:
- uses: actions/checkout@v3
- name: e2e_status
uses: jupiterone/.github/.github/actions/frontend/runtime/e2e_status
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
e2e_pass_on_error: ${{ inputs.e2e_pass_on_error }}
63 changes: 0 additions & 63 deletions .github/workflows/frontend_runtime_utility_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,13 @@ on:
description: "Run VRT Storybook tests with chromatic"
default: false
type: boolean
use_e2e_trigger:
description: "Trigger E2E tests in other repos"
type: boolean
default: false
e2e_pass_on_error:
description: "Pass the workflow even if the E2E test fail"
type: boolean
default: false
repos_to_test:
description: "Kick off a n+ spec files within n+ repos"
type: string
secrets:
NPM_TOKEN:
description: "A J1 npm.com Publish token"
required: true
CHROMATIC_PROJECT_TOKEN:
description: "The Chromatic API token"
required: false
E2E_AUTO:
description: "A J1 token for kicking off cypress tests"
required: false

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -51,10 +37,6 @@ jobs:
migration: ${{ steps.migration_number.outputs.migration }}
steps:
- uses: actions/checkout@v3
- name: setup_env
uses: jupiterone/.github/.github/actions/setup_env@v2
with:
use_dev: true
- id: migration_number
name: migration_number
uses: jupiterone/.github/.github/actions/frontend/runtime/migration_number@v2
Expand Down Expand Up @@ -135,48 +117,3 @@ jobs:
migration_number: ${{ needs.migration_number.outputs.migration }}
# runtime utilities do not have a route of there own, so we default to home
magic_url_route: '/home'

e2e_trigger_remote_tests:
runs-on: ${{ (inputs.fallback_runner && 'ubuntu-latest') || 'scaleset-jupiterone-infra-arm64' }}
needs: [magic_url]
if: ${{ inputs.use_e2e_trigger }}
strategy:
matrix:
repos: ${{ fromJson(inputs.repos_to_test) }}
continue-on-error: ${{ inputs.e2e_pass_on_error }}
outputs:
test_passed: ${{ steps.e2e_trigger_remote_tests.outputs.test_passed }}
steps:
- uses: actions/checkout@v3
- name: setup_env
uses: jupiterone/.github/.github/actions/setup_env@v2
with:
use_dev: true
- id: e2e_trigger_remote_tests
name: e2e_trigger_remote_tests
uses: jupiterone/.github/.github/actions/frontend/runtime/e2e_trigger_remote_tests@v2
with:
e2e_pass_on_error: ${{ inputs.e2e_pass_on_error }}
e2e_auto: ${{ secrets.E2E_AUTO }}
repo_name: ${{ matrix.repos.repo.name }}
repo_spec: ${{ matrix.repos.repo.spec }}

# Unless e2e_pass_on_error is true, this will never get hit if an E2E test fails
e2e_status:
# Name targeted by branch protections, do not change
name: E2E Status
runs-on: ${{ (inputs.fallback_runner && 'ubuntu-latest') || 'scaleset-jupiterone-infra-arm64' }}
needs: [e2e_trigger_remote_tests]
steps:
- uses: actions/checkout@v3
- name: setup_env
uses: jupiterone/.github/.github/actions/setup_env@v2
with:
use_dev: true
- name: e2e_status
uses: jupiterone/.github/.github/actions/frontend/runtime/e2e_status@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_info_sha: ${{ github.sha }}
e2e_passed: ${{ needs.e2e_trigger_remote_tests.outputs.test_passed }}
e2e_pass_on_error: ${{ inputs.e2e_pass_on_error }}
Loading

0 comments on commit 390f319

Please sign in to comment.