Skip to content

Commit

Permalink
[SDK-4436] test: Migrate CI to GitHub Actions (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
evansims authored Sep 8, 2023
2 parents 5533a1e + d518a97 commit c1068ce
Show file tree
Hide file tree
Showing 13 changed files with 3,319 additions and 11,759 deletions.
26 changes: 26 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build package
description: Build the SDK package

inputs:
node:
description: The Node version to use
required: false
default: 18

runs:
using: composite

steps:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node }}
cache: 'npm'

- name: Install dependencies
shell: bash
run: npm ci --include=dev

- name: Build package
shell: bash
run: npm run build
76 changes: 76 additions & 0 deletions .github/actions/integration/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Run integration test
description: Prepares the environment and runs an integration test using Cypress

inputs:
integration:
description: The integration test to run
required: true
node:
description: The Node version to use
required: false
default: 18
dotenv:
description: The path to the .env file
required: false
default: .env.sample

runs:
using: composite

steps:
- uses: pnpm/action-setup@v2
with:
version: 8

- name: Prepare dependencies
shell: bash
run: |
pnpm import
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node }}
cache: 'pnpm'

- name: Update /etc/hosts
shell: bash
run: |
sudo echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts
- name: Move dotenv file
shell: bash
run: |
mv examples/${{ inputs.integration }}/${{ inputs.dotenv }} examples/${{ inputs.integration }}/.env
- name: Install dependencies
shell: bash
run: |
pnpm i
- name: Start mock API server
shell: bash
run: |
cd examples/users-api
pnpm i
pnpm run start &
env:
DOMAIN: your-tenant.auth0.com
AUDIENCE: https://api.example.com/users
PORT: 3001

- name: Start application
shell: bash
run: |
cd examples/${{ inputs.integration }}
pnpm i
pnpm run start &
env:
PORT: 3000

- name: Run Cypress test
uses: cypress-io/github-action@v6
with:
spec: cypress/integration/smoke.test.ts
install: false
wait-on: 'http://localhost:3001/, http://localhost:3000'
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
60 changes: 60 additions & 0 deletions .github/workflows/browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Browserstack

on:
merge_group:
workflow_dispatch:
pull_request_target:
types:
- opened
- synchronize
push:
branches:
- master

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

env:
NODE_VERSION: 18

jobs:
authorize:
name: Authorize
environment: ${{ github.actor != 'dependabot[bot]' && github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true

browserstack:
needs: authorize # Require approval before running on forked pull requests

name: BrowserStack Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm

- name: Build package
uses: ./.github/actions/build
with:
node: ${{ env.NODE_VERSION }}

- name: Run tests
shell: bash
run: npx concurrently --raw --kill-others --success first "npm:start" "wait-on http://127.0.0.1:3000/ && browserstack-cypress run --build-name ${{ github.event.pull_request.head.sha || github.ref }} --no-wrap --specs "cypress/integration/smoke-bs.test.ts""
env:
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
33 changes: 23 additions & 10 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
name: 'CodeQL'
name: CodeQL

on:
push:
branches: ['master', 'beta']
merge_group:
pull_request:
branches: ['master']
types:
- opened
- synchronize
push:
branches:
- master
- beta
schedule:
- cron: '37 10 * * 2'

permissions:
actions: read
contents: read
security-events: write

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
analyze:
name: Analyze
name: Check for Vulnerabilities
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [javascript]

steps:
- if: github.actor == 'dependabot[bot]' || github.event_name == 'merge_group'
run: exit 0 # Skip unnecessary test runs for dependabot and merge queues. Artifically flag as successful, as this is a required check for branch protection.

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Integration Tests

on:
# merge_group:
workflow_dispatch:
# pull_request:
# branches:
# - master
# push:
# branches:
# - master

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

env:
NODE_VERSION: 18
# Mock user credentials for Cypress tests
CYPRESS_USER_EMAIL: [email protected]
CYPRESS_USER_PASSWORD: mockpassword

jobs:
test-react-router:
name: Run react-router tests
runs-on: ubuntu-latest

env:
SKIP_PREFLIGHT_CHECK: true
REACT_APP_DOMAIN: your-tenant.auth0.com
REACT_APP_CLIENT_ID: yourclientid
REACT_APP_AUDIENCE: https://api.example.com/users
REACT_APP_API_PORT: 3001

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run integration test
uses: ./.github/actions/integration
with:
integration: 'cra-react-router'
node: ${{ env.NODE_VERSION }}

test-gatsby:
name: Run Gatsby tests
runs-on: ubuntu-latest

env:
GATSBY_DOMAIN: your-tenant.auth0.com
GATSBY_CLIENT_ID: yourclientid
GATSBY_AUDIENCE: https://api.example.com/users
GATSBY_API_PORT: 3001

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run integration test
uses: ./.github/actions/integration
with:
integration: 'gatsby-app'
node: ${{ env.NODE_VERSION }}
dotenv: '.env.development.sample'

test-nextjs:
name: Run NextJS tests
runs-on: ubuntu-latest

env:
NEXT_PUBLIC_DOMAIN: your-tenant.auth0.com
NEXT_PUBLIC_CLIENT_ID: yourclientid
NEXT_PUBLIC_AUDIENCE: https://api.example.com/users
NEXT_PUBLIC_API_PORT: 3001

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run integration test
uses: ./.github/actions/integration
with:
integration: 'nextjs-app'
node: ${{ env.NODE_VERSION }}
Loading

0 comments on commit c1068ce

Please sign in to comment.