Skip to content

Commit

Permalink
ci: restructure e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
necipallef committed Sep 16, 2024
1 parent 5ea4433 commit 454fcfd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 122 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/e2e_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: AWS E2E

on:
workflow_dispatch:
push:
branches:
- main
- rc
paths-ignore:
- '**.md'
- 'cloudformation/*.yml'

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
RunE2E:
runs-on: ubuntu-latest
steps:
- name: Git clone
uses: actions/checkout@v4
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.AWS_E2E_ROLE_ARN}}
aws-region: ${{secrets.AWS_E2E_REGION}}
- name: Trigger AWS CodePipeline
run: |
codepipeline_execution_id=$(aws codepipeline start-pipeline-execution --name ${{secrets.AWS_E2E_CODEPIPELINE_NAME}} --query 'pipelineExecutionId' --output text)
echo "Pipeline execution ID: $codepipeline_execution_id"
echo "codepipeline_execution_id=$codepipeline_execution_id" >> $GITHUB_ENV
- name: Poll Pipeline Status
id: poll-status
run: |
while true; do
sleep 30
status=$(aws codepipeline get-pipeline-execution \
--pipeline-name ${{secrets.AWS_E2E_CODEPIPELINE_NAME}} \
--pipeline-execution-id ${{ env.codepipeline_execution_id }} \
--query 'pipelineExecution.status' --output text)
echo "Current pipeline status: $status"
if [[ "$status" == "Succeeded" ]]; then
echo "Pipeline execution succeeded!"
exit 0
elif [[ "$status" == "Failed" ]]; then
echo "Pipeline execution failed!"
exit 1
fi
done
36 changes: 2 additions & 34 deletions buildspec-e2e-rc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
version: 0.2
env:
secrets-manager:
GITHUB_TOKEN: "fpjs-dev-cloudfront-secrets:GITHUB_TOKEN"

phases:
install:
runtime-versions:
Expand All @@ -12,14 +10,6 @@ phases:
- echo $CODEBUILD_SOURCE_VERSION
- echo $CODEBUILD_BUILD_ID
- echo $CODEBUILD_PUBLIC_BUILD_URL
- |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_ID \
-d "{\"state\":\"pending\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/$AWS_ACCOUNT_ID/projects/fpjs-dev-cloudfront-lambda-e2e-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"E2E tests for release are running\",\"context\":\"e2e-release\"}"
- ls -a
- curl -fsSL https://get.pulumi.com | sh
- export PATH=$PATH:$HOME/.pulumi/bin
Expand All @@ -31,37 +21,15 @@ phases:
pre_build:
commands:
- pwd
- pulumi version
- pulumi version
- cd e2e/infra/lambda && pulumi stack init e2e && pulumi stack select e2e && cd ../../..
- cd e2e/infra/cloudfront && pulumi stack init e2e && pulumi stack select e2e && cd ../../..
- cd e2e/infra && pnpm run lambda:up && pnpm run lambda:export && pnpm run cloudfront:up && pnpm run cloudfront:export && cd ../..
finally:
- |
if [ "$CODEBUILD_BUILD_SUCCEEDING" -eq 0 ]; then
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_ID \
-d "{\"state\":\"error\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/$AWS_ACCOUNT_ID/projects/fpjs-dev-cloudfront-lambda-e2e-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"E2E tests for release failed during the pre-build step\",\"context\":\"e2e-release\"}"
fi
build:
commands:
- ls -a
- cd e2e/tests && pnpm test
finally:
- cd ../..
- echo $CODEBUILD_BUILD_SUCCEEDING
- echo $COMMIT_ID
- export STATUS=$(sh ./e2e/scripts/get-codebuild-status.sh)
- echo $STATUS
- |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_ID \
-d "{\"state\":\"$STATUS\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/$AWS_ACCOUNT_ID/projects/fpjs-dev-cloudfront-lambda-e2e-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"E2E tests for release finished\",\"context\":\"e2e-release\"}"
- cd e2e/infra && pnpm cloudfront:destroy && pnpm lambda:destroy && cd ../..
34 changes: 1 addition & 33 deletions buildspec-e2e.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
version: 0.2
env:
secrets-manager:
GITHUB_TOKEN: "fpjs-dev-cloudfront-secrets:GITHUB_TOKEN"

phases:
install:
runtime-versions:
Expand All @@ -12,14 +10,6 @@ phases:
- echo $COMMIT_SHA
- echo $CODEBUILD_BUILD_ID
- echo $CODEBUILD_PUBLIC_BUILD_URL
- |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_SHA \
-d "{\"state\":\"pending\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/fpjs-dev-cloudfront-lambda-e2e-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"E2E tests are running\",\"context\":\"e2e\"}"
- ls -a
- curl -fsSL https://get.pulumi.com | sh
- export PATH=$PATH:$HOME/.pulumi/bin
Expand All @@ -35,33 +25,11 @@ phases:
- cd infra/lambda && pnpm install && pulumi stack init e2e && pulumi stack select e2e && cd ../../
- cd infra/cloudfront && pnpm install && pulumi stack init e2e && pulumi stack select e2e && cd ../../
- cd infra && pnpm install && pnpm run lambda:up && pnpm run lambda:export && pnpm run cloudfront:up && pnpm run cloudfront:export && cd ../
finally:
- |
if [ "$CODEBUILD_BUILD_SUCCEEDING" -eq 0 ]; then
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_SHA \
-d "{\"state\":\"error\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/fpjs-dev-cloudfront-lambda-e2e-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"E2E tests failed during the pre-build step\",\"context\":\"e2e\"}"
fi
build:
commands:
- ls -a
- cd tests && pnpm test
finally:
- cd ../
- echo $CODEBUILD_BUILD_SUCCEEDING
- echo $COMMIT_SHA
- export STATUS=$(sh ./scripts/get-codebuild-status.sh)
- echo $STATUS
- |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_SHA \
-d "{\"state\":\"$STATUS\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/fpjs-dev-cloudfront-lambda-e2e-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"E2E tests finished\",\"context\":\"e2e\"}"
- cd infra && pnpm cloudfront:destroy && pnpm lambda:destroy && cd ../
34 changes: 1 addition & 33 deletions buildspec-mock-e2e.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
version: 0.2
env:
secrets-manager:
GITHUB_TOKEN: "fpjs-dev-cloudfront-secrets:GITHUB_TOKEN"

phases:
install:
runtime-versions:
Expand All @@ -14,14 +12,6 @@ phases:
- echo $VERSION
- echo $CODEBUILD_BUILD_ID
- echo $CODEBUILD_PUBLIC_BUILD_URL
- |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_SHA \
-d "{\"state\":\"pending\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/fpjs-dev-cloudfront-lambda-e2e-mock-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"Mock E2E Tests are running\",\"context\":\"mock-e2e\"}"
- ls -a
- curl -fsSL https://get.pulumi.com | sh
- export PATH=$PATH:$HOME/.pulumi/bin
Expand All @@ -38,32 +28,10 @@ phases:
- cd infra/lambda && pnpm install && pulumi stack init e2e && pulumi stack select e2e && cd ../../
- cd infra/cloudfront && pnpm install && pulumi stack init e2e && pulumi stack select e2e && cd ../../
- cd infra && pnpm install && pnpm run lambda:up && pnpm run lambda:export && pnpm run cloudfront:up && pnpm run cloudfront:export && cd ../
finally:
- |
if [ "$CODEBUILD_BUILD_SUCCEEDING" -eq 0 ]; then
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_SHA \
-d "{\"state\":\"error\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/fpjs-dev-cloudfront-lambda-e2e-mock-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"Mock E2E Tests failed during the pre-build step\",\"context\":\"mock-e2e\"}"
fi
build:
commands:
- ts-node ./scripts/mockTests.ts --project=tsconfig.json
finally:
- echo $CODEBUILD_BUILD_SUCCEEDING
- echo $COMMIT_SHA
- export STATUS=$(sh ./scripts/get-codebuild-status.sh)
- echo $STATUS
- |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/statuses/$COMMIT_SHA \
-d "{\"state\":\"$STATUS\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/fpjs-dev-cloudfront-lambda-e2e-mock-tests/build/$CODEBUILD_BUILD_ID/?region=us-east-1\",\"description\":\"Mock E2E Tests finished\",\"context\":\"mock-e2e\"}"
- cd infra && pnpm cloudfront:destroy && pnpm lambda:destroy && cd ../

5 changes: 0 additions & 5 deletions e2e/scripts/get-codebuild-status.sh

This file was deleted.

20 changes: 3 additions & 17 deletions scripts/downloadGithubRelease.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { fileURLToPath } from 'url'
import Zip from 'adm-zip'

const config = {
token: process.env.GITHUB_TOKEN,
owner: 'fingerprintjs',
repo: 'fingerprint-pro-cloudfront-integration',
}
Expand All @@ -31,7 +30,7 @@ async function main() {
return
}

const zip = await downloadReleaseAsset(asset.url, config.token)
const zip = await downloadReleaseAsset(asset.url)

if (process.env.UNPACK_TO_DIST) {
new Zip(zip).extractAllTo(path.resolve(dirname, '../dist'), true)
Expand All @@ -40,10 +39,6 @@ async function main() {
}
}

function bearer(token) {
return `Bearer ${token}`
}

async function getGitHubRelease() {
const commitId = process.env.COMMIT_ID

Expand Down Expand Up @@ -95,25 +90,16 @@ async function getLatestGitHubRelease() {
}

async function doGitHubGetRequest(url) {
const response = await fetch(url, {
headers: config.token
? {
Authorization: bearer(config.token),
}
: undefined,
})
const response = await fetch(url)

return await response.json()
}

async function downloadReleaseAsset(url, token) {
async function downloadReleaseAsset(url) {
const headers = {
Accept: 'application/octet-stream',
'User-Agent': 'fingerprint-pro-cloudfront-integration',
}
if (token) {
headers['Authorization'] = bearer(token)
}

console.info('Downloading release asset...', url)

Expand Down

0 comments on commit 454fcfd

Please sign in to comment.