Skip to content

Feature/release e2e tests #62

Feature/release e2e tests

Feature/release e2e tests #62

Workflow file for this run

name: Test e2e for PR
on:
pull_request:
jobs:
check-changed-files:
runs-on: ubuntu-20.04
name: Check changed files
outputs:
CANT_PASS_WITHOUT_TESTS: ${{ steps.decision.outputs.CANT_PASS_WITHOUT_TESTS }}
steps:
- id: files
uses: jitterbit/get-changed-files@b17fbb00bdc0c0f63fcf166580804b4d2cdc2a42
- name: Make decision based on changed files
id: decision
run: |
cantPassWithoutTests=false
for changed_file in ${{ steps.files.outputs.all }}; do
if [[ ${changed_file} =~ ^(assets|generators)\/.+$ ]]; then
cantPassWithoutTests=true
fi
if [[ ${changed_file} =~ ^build\.ts$ ]]; then
cantPassWithoutTests=true
fi
done
echo $cantPassWithoutTests
echo CANT_PASS_WITHOUT_TESTS=${cantPassWithoutTests} >> $GITHUB_OUTPUT
get-subdomain:
runs-on: ubuntu-20.04
name: Get subdomain
outputs:
SUBDOMAIN: ${{ steps.extract-branch.outputs.SUBDOMAIN }}
steps:
- name: Extract Branch Name
id: extract-branch
run: |
echo SUBDOMAIN=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | perl -pe 's/[^a-zA-Z0-9]+/-/g and s/-+$//g' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
test-patch-body:
runs-on: ubuntu-20.04
name: Test patch body
needs:
- check-changed-files
- get-subdomain
if: needs['check-changed-files'].outputs.CANT_PASS_WITHOUT_TESTS == 'true'
steps:
- uses: actions/checkout@v3
- name: Install node
uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
- name: Install dependencies
run: yarn install
- name: Install Playwright
run: npx playwright install
- name: Run test
run: yarn test:e2e
env:
TEST_DOMAIN: 'https://${{needs.get-subdomain.outputs.SUBDOMAIN}}.${{secrets.FPJS_CI_DOMAIN}}'
TEST_RESULT_DOMAIN: ${{secrets.TEST_RESULT_DOMAIN}}
TEST_RESULT_PATH: ${{secrets.TEST_RESULT_PATH}}
INTEGRATION_PATH: ${{secrets.INTEGRATION_PATH}}
RESULT_PATH: ${{secrets.RESULT_PATH}}
AGENT_PATH: ${{secrets.AGENT_PATH}}
FPJS_API_KEY: ${{secrets.FPJS_API_KEY}}
test-terraform:
runs-on: ubuntu-20.04
name: Test terraform
env:
SUBDOMAIN: '${{needs.get-subdomain.outputs.SUBDOMAIN}}-tf-test.${{secrets.FPJS_CI_DOMAIN}}'
needs:
- check-changed-files
- get-subdomain
steps:
- uses: actions/checkout@v3
- name: Install node
uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
- name: Setup terraform
uses: hashicorp/setup-terraform@v3
- name: Install dependencies
run: yarn install
- name: Check If DNS Record Exists
id: cloudflare-dns-check
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records?name=${{env.SUBDOMAIN}}'
method: 'GET'
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
- name: Create Cloudflare DNS Record
if: ${{ fromJson(steps.cloudflare-dns-check.outputs.response).result_info.total_count < 1 }}
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records'
method: 'POST'
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
data: '{"content": "${{env.SUBDOMAIN}}.edgesuite.net", "name": "${{env.SUBDOMAIN}}", "proxied": false, "type": "CNAME", "comment": "Akamai CI run for ${{needs.get-subdomain.outputs.SUBDOMAIN}}", "ttl": 3600, "tags": ["owner:akamai-integration-ci"]}'
- name: Build
run: yarn build --type terraform
- name: Deploy terraform
working-directory: test/terraform
env:
TF_VAR_domain: ${{env.SUBDOMAIN}}
TF_VAR_group_name: ${{ secrets.AK_GROUP_NAME }}
TF_VAR_origin: origin-akamai.${{ secrets.FPJS_CI_DOMAIN }}
TF_VAR_contact_email: ${{ secrets.NOTIFY_EMAIL_ADDRESS }}
TF_VAR_proxy_secret: ${{ secrets.PROXY_SECRET }}
TF_VAR_agent_path: ${{ secrets.AGENT_PATH }}
TF_VAR_result_path: ${{ secrets.RESULT_PATH }}
AKAMAI_ACCESS_TOKEN: ${{ secrets.AK_ACCESS_TOKEN }}
AKAMAI_CLIENT_SECRET: ${{ secrets.AK_CLIENT_SECRET }}
AKAMAI_CLIENT_TOKEN: ${{ secrets.AK_CLIENT_TOKEN }}
AKAMAI_HOST: ${{ secrets.AK_HOST }}
run: |
terraform init
terraform apply -auto-approve
- name: Wait for property
run: yarn ts-node scripts/waitForProperty.ts
env:
URL: 'https://${{env.SUBDOMAIN}}/${{secrets.INTEGRATION_PATH}}/status'
NODE_TLS_REJECT_UNAUTHORIZED: '0'
- name: Install Playwright
run: npx playwright install
- uses: Wandalen/wretry.action@a163f62ae554a8f3cbe27b23db15b60c0ae2e93c
with:
command: yarn test:e2e
attempt_limit: 3
# Wait 4 minutes between attempts
attempt_delay: 240000
env:
TEST_DOMAIN: 'https://${{env.SUBDOMAIN}}'
TEST_RESULT_DOMAIN: ${{secrets.TEST_RESULT_DOMAIN}}
TEST_RESULT_PATH: ${{secrets.TEST_RESULT_PATH}}
INTEGRATION_PATH: ${{secrets.INTEGRATION_PATH}}
RESULT_PATH: ${{secrets.RESULT_PATH}}
AGENT_PATH: ${{secrets.AGENT_PATH}}
FPJS_API_KEY: ${{secrets.FPJS_API_KEY}}
- name: Destroy terraform
if: ${{ always() }}
working-directory: test/terraform
run: terraform destroy -auto-approve
- name: Delete Cloudflare DNS Record
if: ${{ always() && fromJson(steps.cloudflare-dns-check.outputs.response).result_info.total_count > 0 }}
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records/${{ fromJson(steps.cloudflare-dns-check.outputs.response).result[0].id }}'
method: 'DELETE'
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'