From 8cb01c38c2e08ebae7481f6ab46cc8d7d4ecd62a Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Thu, 9 Nov 2023 15:20:04 +0100 Subject: [PATCH] Add GitHub Actions (#455) * Add GitHub Actions * Remove unnecessary step * Move test scripts checkout to action * fix yml --- .github/actions/build/action.yml | 43 ++++++++++++++++++ .github/actions/test/action.yml | 76 ++++++++++++++++++++++++++++++++ .github/workflows/e2e-test.yml | 70 +++++++++++++++++++++++++++++ .github/workflows/test.yml | 52 ++++++++++++++++++++++ 4 files changed, 241 insertions(+) create mode 100644 .github/actions/build/action.yml create mode 100644 .github/actions/test/action.yml create mode 100644 .github/workflows/e2e-test.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 00000000..109b06c3 --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,43 @@ +name: Build application +description: Build the example application + +inputs: + working-directory: + description: The current working directory + required: true + +runs: + using: composite + + steps: + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Install dependencies + shell: bash + run: npm ci + working-directory: ${{ inputs.working-directory }} + + - 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: Build + shell: bash + run: npm run build + working-directory: ${{ inputs.working-directory }} + + - name: Tests + shell: bash + run: npm run test:ci + working-directory: ${{ inputs.working-directory }} \ No newline at end of file diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 00000000..3fa2af47 --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,76 @@ +name: E2E test +description: Run E2E tests against the example application + +inputs: + working-directory: + description: The current working directory + required: true + domain: + description: The Auth0 domain to use + required: true + client-id: + description: The Auth0 client id to use + required: true + api-identifier: + description: The Auth0 API identifier to use + required: true + +runs: + using: composite + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + repository: auth0-samples/spa-quickstarts-tests + path: scripts + + - 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 + AUTH0_TEST_DOMAIN: ${{ inputs.domain }} + AUTH0_TEST_CLIENT_ID: ${{ inputs.client-id }} + AUTH0_TEST_API_IDENTIFIER: ${{ inputs.api-identifier }} + 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 + 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 }} + shell: bash + 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 + shell: bash + run: | + sleep 10 + docker run --network host --rm appropriate/curl --retry 8 --retry-connrefused -v localhost:4200 + - name: Run tests + shell: bash + 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 + env: + CONTAINER_NAME: ${{ github.event.pull_request.head.sha || github.sha }} + shell: bash + 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/e2e-test.yml b/.github/workflows/e2e-test.yml new file mode 100644 index 00000000..99494ccb --- /dev/null +++ b/.github/workflows/e2e-test.yml @@ -0,0 +1,70 @@ +name: E2E Test + +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 + CACHE_KEY: '${{ github.ref }}-${{ github.run_id }}-${{ github.run_attempt }}' + +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-01: + needs: authorize + name: E2E 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: E2E Test Sample + uses: ./.github/actions/test + with: + working-directory: Sample-01 + domain: ${{ secrets.AUTH0_TEST_DOMAIN }} + client-id: ${{ secrets.AUTH0_TEST_CLIENT_ID }} + api-identifier: ${{ secrets.AUTH0_TEST_API_IDENTIFIER }} + + standalone: + needs: authorize + 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 }} + + - name: E2E Test Standalone + uses: ./.github/actions/test + with: + working-directory: Standalone + domain: ${{ secrets.AUTH0_TEST_DOMAIN }} + client-id: ${{ secrets.AUTH0_TEST_CLIENT_ID }} + api-identifier: ${{ secrets.AUTH0_TEST_API_IDENTIFIER }} + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..c17fa563 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,52 @@ +name: Build and Test + +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 + CACHE_KEY: '${{ github.ref }}-${{ github.run_id }}-${{ github.run_attempt }}' + +jobs: + sample-01: + name: Build and Unit 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: Build Sample + uses: ./.github/actions/build + with: + working-directory: Sample-01 + standalone: + name: Build and Unit Test Standalone + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha || github.ref }} + + - name: Build Standalone + uses: ./.github/actions/build + with: + working-directory: Standalone \ No newline at end of file