diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 00000000..56d82aaf --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,56 @@ +name: E2E test +description: Run E2E tests against the example application + +inputs: + working-directory: + description: The current working directory + required: true + +env: + SAMPLE_PATH: ${{ inputs.working-directory }} + IMAGE_NAME: ${{ github.event.pull_request.head.sha || github.sha }} + CONTAINER_NAME: ${{ github.event.pull_request.head.sha || github.sha }} + AUTH0_TEST_DOMAIN: ${{ secrets.AUTH0_TEST_DOMAIN }} + AUTH0_TEST_CLIENT_ID: ${{ secrets.AUTH0_TEST_CLIENT_ID }} + AUTH0_TEST_API_IDENTIFIER: ${{ secrets.AUTH0_TEST_API_IDENTIFIER }} + +runs: + using: composite + + steps: + - name: Replace Auth0 test credentials + shell: bash + env: + AUTH0_CFG: ${{ inputs.working-directory }}/auth_config.json + AUTH0_EXAMPLE_CFG: ${{ inputs.working-directory }}/auth_config.json.example + run: | + sed \ + -e "s/{DOMAIN}/$AUTH0_TEST_DOMAIN/g" \ + -e "s/{CLIENT_ID}/$AUTH0_TEST_CLIENT_ID/g" \ + -e "s/{API_IDENTIFIER}/$AUTH0_TEST_API_IDENTIFIER/g" \ + $AUTH0_EXAMPLE_CFG > $AUTH0_CFG + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build pull request + run: | + docker build -t $IMAGE_NAME ./$SAMPLE_PATH + docker run -d -p 4200:4200 --name $CONTAINER_NAME $IMAGE_NAME + - name: Wait for app to be available + run: | + sleep 10 + docker run --network host --rm appropriate/curl --retry 8 --retry-connrefused -v localhost:4200 + - name: Run tests + run: | + docker create --env "SAMPLE_PORT=4200" --network host --name tester codeceptjs/codeceptjs codeceptjs run-multiple --all --steps + docker cp $(pwd)/lock_login_test.js tester:/tests/lock_login_test.js + docker cp $(pwd)/codecept.conf.js tester:/tests/codecept.conf.js + docker start -i tester + working-directory: scripts + - name: Copy app container logs + run: | + mkdir -p /tmp/out + docker logs $CONTAINER_NAME > /tmp/out/app_logs.log + docker cp tester:/tests/out /tmp/ + if: failure() \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78eae15a..020a60a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,15 +58,6 @@ jobs: e2e-sample-01: name: E2E Test Sample runs-on: ubuntu-latest - env: - AUTH0_CFG: Sample-01/auth_config.json - AUTH0_EXAMPLE_CFG: Sample-01/auth_config.json.example - SAMPLE_PATH: Sample-01 - IMAGE_NAME: ${{ github.event.pull_request.head.sha || github.sha }} - CONTAINER_NAME: ${{ github.event.pull_request.head.sha || github.sha }} - AUTH0_TEST_DOMAIN: ${{ secrets.AUTH0_TEST_DOMAIN }} - AUTH0_TEST_CLIENT_ID: ${{ secrets.AUTH0_TEST_CLIENT_ID }} - AUTH0_TEST_API_IDENTIFIER: ${{ secrets.AUTH0_TEST_API_IDENTIFIER }} steps: - name: Checkout code @@ -76,38 +67,25 @@ jobs: - run: git clone https://github.com/auth0-samples/spa-quickstarts-tests scripts - - name: Replace Auth0 test credentials - run: | - sed \ - -e "s/{DOMAIN}/$AUTH0_TEST_DOMAIN/g" \ - -e "s/{CLIENT_ID}/$AUTH0_TEST_CLIENT_ID/g" \ - -e "s/{API_IDENTIFIER}/$AUTH0_TEST_API_IDENTIFIER/g" \ - $AUTH0_EXAMPLE_CFG > $AUTH0_CFG + - name: E2E Test Sample + uses: ./.github/actions/test + with: + working-directory: Sample-01 - - run: cat $AUTH0_CFG - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build pull request - run: | - docker build -t $IMAGE_NAME ./$SAMPLE_PATH - docker run -d -p 4200:4200 --name $CONTAINER_NAME $IMAGE_NAME - - name: Wait for app to be available - run: | - sleep 10 - docker run --network host --rm appropriate/curl --retry 8 --retry-connrefused -v localhost:4200 - - name: Run tests - run: | - docker create --env "SAMPLE_PORT=4200" --network host --name tester codeceptjs/codeceptjs codeceptjs run-multiple --all --steps - docker cp $(pwd)/lock_login_test.js tester:/tests/lock_login_test.js - docker cp $(pwd)/codecept.conf.js tester:/tests/codecept.conf.js - docker start -i tester - working-directory: scripts - - name: Copy app container logs - run: | - mkdir -p /tmp/out - docker logs $CONTAINER_NAME > /tmp/out/app_logs.log - docker cp tester:/tests/out /tmp/ - if: failure() + e2e-standalone: + name: E2E Test Standalone + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha || github.ref }} + + - run: git clone https://github.com/auth0-samples/spa-quickstarts-tests scripts + + - name: E2E Test Standalone + uses: ./.github/actions/test + with: + working-directory: Standalone