Skip to content

Commit

Permalink
Agent mock aws (#283)
Browse files Browse the repository at this point in the history
* Added unit test that tests pewpewtest for 30 second and mocks aws

* Added integration tests for agent that runs a subset of createtest

* Moved build test to integration

* Cleaned up unit test for pewpewtest

* Added initial PR code to get changed files

* Added some clean-up code

- Chaned PPaasS3Message to use the built-in function to generate the message
- Added additional logging
- Removed a race condition where endtime might not match start time
- Added an exported const for tests to use for checking endtime on bypass parser

* Updated mock file with changes

- Added keymatch to GetObjectError
- Added once option to ListObject to only return once then returne not found

* Converted createtest to mock aws

- The agent npm run createtest now uses mocks for AWS letting it be run in Github actions, only integration requires AWS
- Added code to the PR script that if agent/package.json, agent/src/pewpewtest.ts, or agent/createtest/ change we run the create test as part of the PR.

* Added try catch to the reset mock code

* Updated lock file to latest

* Added missing environment variable needed for unit tests

* Attempt to fix createtest pr check

* Attempt to fix createtest pr check

* For the agent also check package-lock

---------

Co-authored-by: Trevor McMaster <[email protected]>
  • Loading branch information
tkmcmaster and tkmcmaster authored Jan 24, 2025
1 parent 30b0bc1 commit f84e98a
Show file tree
Hide file tree
Showing 15 changed files with 2,029 additions and 1,010 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pr-ppaas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,50 @@ on:

name: Pull Request PPaaS
jobs:
changedfiles: # https://dev.to/scienta/get-changed-files-in-github-actions-1p36
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
all_files: ${{ steps.changes.outputs.all_files}}
lock_file: ${{ steps.changes.outputs.lock_file }}
create_test: ${{ steps.changes.outputs.create_test }}
steps:
# Make sure we have some code to diff.
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Get changed files
id: changes
run: |
export all_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)
# Send to outside variable
echo "all_files=$all_files" >> $GITHUB_OUTPUT
echo "all_files=$all_files"
export agent_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep "^agent/createtest/" | grep ".spec.ts$" | xargs)
echo "agent_files=$agent_files"
if [[ ! -z "${agent_files[@]}" ]] || ([[ "${all_files[@]}" =~ "agent/package.json" ]] || [[ "${all_files[@]}" =~ "agent/src/pewpewtest.ts" ]]); then
echo "Createtest test files changed, changed package.json, or changed pewpewtest.ts"
echo "create_test=true" >> $GITHUB_OUTPUT
echo "create_test=true"
fi
if [[ "${all_files[@]}" =~ "package-lock.json" ]]; then
echo "Lock file changed"
echo "lock_file=true" >> $GITHUB_OUTPUT
echo "lock_file=true"
fi
test-release:
name: Build project
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
fail-fast: false
needs: changedfiles
runs-on: ubuntu-latest
env:
DOWNLOAD_PEWPEW: true

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -86,3 +123,6 @@ jobs:
run: npm run build:react
- name: Run Tests
run: NODE_ENV=test npm test
- name: Run Agent CreateTest
if: ${{ needs.changedfiles.outputs.create_test }}
run: cd agent/ && NODE_ENV=test npm run createtest
42 changes: 40 additions & 2 deletions agent/.github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,49 @@ on:

name: Pull Request Javascript
jobs:
changedfiles: # https://dev.to/scienta/get-changed-files-in-github-actions-1p36
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
all_files: ${{ steps.changes.outputs.all_files}}
lock_file: ${{ steps.changes.outputs.lock_file }}
create_test: ${{ steps.changes.outputs.create_test }}
steps:
# Make sure we have some code to diff.
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Get changed files
id: changes
run: |
export all_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)
# Send to outside variable
echo "all_files=$all_files" >> $GITHUB_OUTPUT
echo "all_files=$all_files"
export agent_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep "^createtest/" | grep ".spec.ts$" | xargs)
echo "agent_files=$agent_files"
if [[ ! -z "${agent_files[@]}" ]] || ([[ "${all_files[@]}" =~ "package.json" ]] || [[ "${all_files[@]}" =~ "package-lock.json" ]] || [[ "${all_files[@]}" =~ "src/pewpewtest.ts" ]]); then
echo "Createtest test files changed, changed package.json, or changed pewpewtest.ts"
echo "create_test=true" >> $GITHUB_OUTPUT
echo "create_test=true"
fi
if [[ "${all_files[@]}" =~ "package-lock.json" ]]; then
echo "Lock file changed"
echo "lock_file=true" >> $GITHUB_OUTPUT
echo "lock_file=true"
fi
test-release:
name: Build project
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
needs: changedfiles
runs-on: ubuntu-latest
# env:
# USE_XVFB: true
env:
DOWNLOAD_PEWPEW: true

steps:
- uses: actions/checkout@v4
Expand All @@ -34,3 +69,6 @@ jobs:
run: npm ci
- name: Run Tests
run: NODE_ENV=test npm test
- name: Run Agent CreateTest
if: ${{ needs.changedfiles.outputs.create_test }}
run: NODE_ENV=test npm run createtest
Loading

0 comments on commit f84e98a

Please sign in to comment.