Skip to content

Commit

Permalink
Move to a reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Dec 19, 2023
1 parent 6080259 commit f9b2dd7
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 72 deletions.
112 changes: 112 additions & 0 deletions .github/workflows/api-qs-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Run API QuickStart Sample Tests

on:
workflow_call:
inputs:
sample-directory:
required: true
type: string
api-url:
default: 'http://localhost:3010'
type: string
test-directory:
default: 'tests'
type: string
test-ref:
default: 'master'
type: string
secrets:
AUTH0_DOMAIN:
required: true
API_IDENTIFIER:
required: true
CLIENT_ID_SCOPES_NONE:
required: true
CLIENT_SECRET_SCOPES_NONE:
required: true
CLIENT_ID_SCOPES_READ:
required: true
CLIENT_SECRET_SCOPES_READ:
required: true
CLIENT_ID_SCOPES_WRITE:
required: true
CLIENT_SECRET_SCOPES_WRITE:
required: true
CLIENT_ID_SCOPES_READWRITE:
required: true
CLIENT_SECRET_SCOPES_READWRITE:
required: true
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

sample:
needs: authorize
name: Test Sample
runs-on: ubuntu-latest

steps:

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

- name: Checkout Tests
uses: actions/checkout@v4
with:
repository: auth0-samples/api-quickstarts-tests
path: ${{ inputs.test-directory }}
ref: ${{ inputs.test-ref }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Setup sample .env
working-directory: ${{ inputs.sample-directory }}
env:
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
API_IDENTIFIER: ${{ secrets.API_IDENTIFIER }}
run: |
sed \
-e "s|{DOMAIN}|$AUTH0_DOMAIN|g" \
-e "s|{API_IDENTIFIER}|$API_IDENTIFIER|g" \
.env.example > .env
- name: Build PR image
working-directory: ${{ inputs.sample-directory }}
env:
IMAGE_NAME: ${{ github.event.pull_request.head.sha || github.sha }}
CONTAINER_NAME: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
docker build -t $IMAGE_NAME .
docker run -d --env-file .env -p 3010:3010 --name $CONTAINER_NAME $IMAGE_NAME
- name: Wait for sample to start
run: |
sleep 10
docker run --network host --rm appropriate/curl --retry 8 --retry-connrefused -v localhost:3010
- name: Install dependencies
working-directory: tests
run: npm i

- name: Run tests
working-directory: tests
env:
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
API_IDENTIFIER: ${{ secrets.API_IDENTIFIER }}
API_URL: ${{ inputs.api-url }}
AUTH0_CLIENT_ID_1: ${{ secrets.CLIENT_ID_SCOPES_NONE }}
AUTH0_CLIENT_SECRET_1: ${{ secrets.CLIENT_SECRET_SCOPES_NONE }}
AUTH0_CLIENT_ID_2: ${{ secrets.CLIENT_ID_SCOPES_READ }}
AUTH0_CLIENT_SECRET_2: ${{ secrets.CLIENT_SECRET_SCOPES_READ }}
AUTH0_CLIENT_ID_3: ${{ secrets.CLIENT_ID_SCOPES_WRITE }}
AUTH0_CLIENT_SECRET_3: ${{ secrets.CLIENT_SECRET_SCOPES_WRITE }}
AUTH0_CLIENT_ID_4: ${{ secrets.CLIENT_ID_SCOPES_READWRITE }}
AUTH0_CLIENT_SECRET_4: ${{ secrets.CLIENT_SECRET_SCOPES_READWRITE }}
run: npm test
77 changes: 5 additions & 72 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,8 @@ on:
- ci/setup-gh-actions

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

sample:
needs: authorize
name: Test Sample
runs-on: ubuntu-latest

steps:

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

- name: Checkout Tests
uses: actions/checkout@v4
with:
repository: auth0-samples/api-quickstarts-tests
path: tests

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Setup sample .env
working-directory: 01-Authorization-RS256
env:
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
API_IDENTIFIER: ${{ secrets.API_IDENTIFIER }}
run: |
sed \
-e "s|{DOMAIN}|$AUTH0_DOMAIN|g" \
-e "s|{API_IDENTIFIER}|$API_IDENTIFIER|g" \
.env.example > .env
- name: Build PR image
working-directory: 01-Authorization-RS256
env:
IMAGE_NAME: ${{ github.event.pull_request.head.sha || github.sha }}
CONTAINER_NAME: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
docker build -t $IMAGE_NAME .
docker run -d --env-file .env -p 3010:3010 --name $CONTAINER_NAME $IMAGE_NAME
- name: Wait for sample to start
run: |
sleep 10
docker run --network host --rm appropriate/curl --retry 8 --retry-connrefused -v localhost:3010
- name: Install dependencies
working-directory: tests
run: npm i

- name: Run tests
working-directory: tests
env:
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
API_IDENTIFIER: ${{ secrets.API_IDENTIFIER }}
API_URL: 'http://localhost:3010'
AUTH0_CLIENT_ID_1: ${{ secrets.CLIENT_ID_SCOPES_NONE }}
AUTH0_CLIENT_SECRET_1: ${{ secrets.CLIENT_SECRET_SCOPES_NONE }}
AUTH0_CLIENT_ID_2: ${{ secrets.CLIENT_ID_SCOPES_READ }}
AUTH0_CLIENT_SECRET_2: ${{ secrets.CLIENT_SECRET_SCOPES_READ }}
AUTH0_CLIENT_ID_3: ${{ secrets.CLIENT_ID_SCOPES_WRITE }}
AUTH0_CLIENT_SECRET_3: ${{ secrets.CLIENT_SECRET_SCOPES_WRITE }}
AUTH0_CLIENT_ID_4: ${{ secrets.CLIENT_ID_SCOPES_READWRITE }}
AUTH0_CLIENT_SECRET_4: ${{ secrets.CLIENT_SECRET_SCOPES_READWRITE }}
run: npm test
RS256-tests:
uses: ./.github/workflows/api-qs-tests.yml
with:
sample-directory: '01-Authorization-RS256'
secrets: inherit

0 comments on commit f9b2dd7

Please sign in to comment.