From 454fcfd62c47d6332d746fc3a766639d69fb584e Mon Sep 17 00:00:00 2001 From: Necip Allef Date: Tue, 17 Sep 2024 00:31:42 +0300 Subject: [PATCH] ci: restructure e2e tests --- .github/workflows/e2e_test.yml | 54 +++++++++++++++++++++++++++++ buildspec-e2e-rc.yml | 36 ++----------------- buildspec-e2e.yml | 34 +----------------- buildspec-mock-e2e.yml | 34 +----------------- e2e/scripts/get-codebuild-status.sh | 5 --- scripts/downloadGithubRelease.mjs | 20 ++--------- 6 files changed, 61 insertions(+), 122 deletions(-) create mode 100644 .github/workflows/e2e_test.yml delete mode 100644 e2e/scripts/get-codebuild-status.sh diff --git a/.github/workflows/e2e_test.yml b/.github/workflows/e2e_test.yml new file mode 100644 index 00000000..16f917cd --- /dev/null +++ b/.github/workflows/e2e_test.yml @@ -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 diff --git a/buildspec-e2e-rc.yml b/buildspec-e2e-rc.yml index 90b12865..a195b363 100644 --- a/buildspec-e2e-rc.yml +++ b/buildspec-e2e-rc.yml @@ -1,7 +1,5 @@ version: 0.2 -env: - secrets-manager: - GITHUB_TOKEN: "fpjs-dev-cloudfront-secrets:GITHUB_TOKEN" + phases: install: runtime-versions: @@ -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 @@ -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 ../.. diff --git a/buildspec-e2e.yml b/buildspec-e2e.yml index a7004bb6..285805bc 100644 --- a/buildspec-e2e.yml +++ b/buildspec-e2e.yml @@ -1,7 +1,5 @@ version: 0.2 -env: - secrets-manager: - GITHUB_TOKEN: "fpjs-dev-cloudfront-secrets:GITHUB_TOKEN" + phases: install: runtime-versions: @@ -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 @@ -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 ../ diff --git a/buildspec-mock-e2e.yml b/buildspec-mock-e2e.yml index c01dcdd3..04641e73 100644 --- a/buildspec-mock-e2e.yml +++ b/buildspec-mock-e2e.yml @@ -1,7 +1,5 @@ version: 0.2 -env: - secrets-manager: - GITHUB_TOKEN: "fpjs-dev-cloudfront-secrets:GITHUB_TOKEN" + phases: install: runtime-versions: @@ -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 @@ -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 ../ diff --git a/e2e/scripts/get-codebuild-status.sh b/e2e/scripts/get-codebuild-status.sh deleted file mode 100644 index dee8aff6..00000000 --- a/e2e/scripts/get-codebuild-status.sh +++ /dev/null @@ -1,5 +0,0 @@ -if [ "$CODEBUILD_BUILD_SUCCEEDING" = 1 ]; then - echo success -else - echo error -fi diff --git a/scripts/downloadGithubRelease.mjs b/scripts/downloadGithubRelease.mjs index 0ce05e84..6a05467c 100644 --- a/scripts/downloadGithubRelease.mjs +++ b/scripts/downloadGithubRelease.mjs @@ -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', } @@ -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) @@ -40,10 +39,6 @@ async function main() { } } -function bearer(token) { - return `Bearer ${token}` -} - async function getGitHubRelease() { const commitId = process.env.COMMIT_ID @@ -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)