Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: make release test pipeline use commit with tag INTER-924 #295

Merged
merged 9 commits into from
Oct 4, 2024
5 changes: 4 additions & 1 deletion .github/workflows/e2e_test_for_prs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Run e2e for topic branch
name: AWS E2E for topic branch

on:
pull_request:
branches:
- rc

jobs:
check-changed-files:
Expand Down
124 changes: 113 additions & 11 deletions .github/workflows/e2e_test_for_releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,111 @@ name: AWS E2E for releases and pre-releases

on:
workflow_dispatch:
push:
tags:
- v*
paths-ignore:
- '**.md'
- 'cloudformation/*.yml'

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
pull_request:
branches:
- main
ilfa marked this conversation as resolved.
Show resolved Hide resolved
# push:
# tags:
# - v*

# todo: find a way to not use hardcoded `rc`
jobs:
check-commit-with-tag-and-old-tests:
runs-on: ubuntu-20.04
name: Check latest commit with tag and its checks
outputs:
NEED_TO_RUN_TESTS: ${{ steps.decision.outputs.NEED_TO_RUN_TESTS }}
COMMIT_WITH_TAG: ${{ steps.decision.outputs.COMMIT_WITH_TAG }}
steps:
- name: Git clone
uses: actions/checkout@v4
- name: Check latest commit with tag
id: latest_commit_with_test
run: |
git fetch origin $GITHUB_BASE_REF
ilfa marked this conversation as resolved.
Show resolved Hide resolved
git fetch origin rc --tags
diff=$(git log origin/$GITHUB_BASE_REF..origin/rc --oneline --format="%H")
echo "diff=$diff"
latestCommitWithTag=''
for commit in $diff; do
echo "checking commit $commit for tag"
tag=$(git tag --points-at "$commit")
if [[ -n "$tag" ]]; then
latestCommitWithTag=$commit
break
fi
done
echo "latestCommitWithTag=$latestCommitWithTag"
echo "latestCommitWithTag=$latestCommitWithTag" >> $GITHUB_OUTPUT

- name: Fetch checks from GitHub
id: response_from_github
if: steps.latest_commit_with_test.outputs.latestCommitWithTag != ''
run: |
latestCommitWithTag=${{ steps.latest_commit_with_test.outputs.latestCommitWithTag }}
response=$(curl \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/fingerprintjs/fingerprint-pro-cloudfront-integration/commits/$latestCommitWithTag/check-runs)
ilfa marked this conversation as resolved.
Show resolved Hide resolved
if [[ $? -ne 0 ]]; then
echo "Failed to fetch check runs. Exiting."
exit 1
fi
if ! echo "$response" | jq . >/dev/null 2>&1; then
echo "Invalid JSON response: $response"
exit 1
fi
file_name=response_from_github.json
echo "$response" > $file_name
echo "filename=$file_name" >> $GITHUB_OUTPUT

- name: Find test conclusion
if: steps.response_from_github.outputs.filename != ''
id: conclusion
run: |
latestCommitWithTag=${{ steps.latest_commit_with_test.outputs.latestCommitWithTag }}
response="$(cat ${{ steps.response_from_github.outputs.filename }} )"
needToRunTests=false
number_of_checks=$(echo "$response" | jq '.check_runs | length')
echo "# of check runs=$number_of_checks"
run_conclusion='(empty)'
if [[ "$number_of_checks" -ne 0 ]]; then
# Note: Iterating with `for run in $(...)` can lead issues with whitespaces, so using `while read` here
while read -r run; do
run_name=$(echo "$run" | jq -r '.name')
echo "run_name=$run_name"
if [[ "$run_name" == 'Run e2e for releases and pre-releases' ]]; then
run_conclusion=$(echo "$run" | jq -r '.conclusion')
break
fi
done < <(echo "$response" | jq -c '.check_runs[]')
fi
echo "run_conclusion=$run_conclusion"
echo "run_conclusion=$run_conclusion" >> $GITHUB_OUTPUT

- name: Decide whether to run tests
id: decision
run: |
latestCommitWithTag=${{ steps.latest_commit_with_test.outputs.latestCommitWithTag }}
run_conclusion=${{ steps.conclusion.outputs.run_conclusion }}
if [[ "$run_conclusion" == "success" ]]; then
echo "test has run successfully before. Skipping..."
elif [[ "$run_conclusion" == "failure" ]]; then
echo "test has failed before. Exiting..."
exit 1
else
echo "COMMIT_WITH_TAG=${latestCommitWithTag}" >> $GITHUB_OUTPUT
echo "NEED_TO_RUN_TESTS=true" >> $GITHUB_OUTPUT
fi

run-e2e-for-releases-and-pre-releases:
needs: check-commit-with-tag-and-old-tests
if: needs['check-commit-with-tag-and-old-tests'].outputs.NEED_TO_RUN_TESTS == 'true'
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
name: Run e2e for releases and pre-releases
runs-on: ubuntu-latest
steps:
Expand All @@ -27,7 +119,7 @@ jobs:
aws-region: ${{vars.AWS_E2E_REGION}}
- name: Trigger AWS CodePipeline
run: |
codepipeline_execution_id=$(aws codepipeline start-pipeline-execution --name ${{vars.AWS_E2E_RC_CODEPIPELINE_NAME}} --query 'pipelineExecutionId' --output text)
codepipeline_execution_id=$(aws codepipeline start-pipeline-execution --name ${{vars.AWS_E2E_RC_CODEPIPELINE_NAME}} --source-revisions actionName=Source,revisionType=COMMIT_ID,revisionValue=${{needs['check-commit-with-tag-and-old-tests'].outputs.COMMIT_WITH_TAG}} --query 'pipelineExecutionId' --output text)
echo "Pipeline execution ID: $codepipeline_execution_id"
echo "codepipeline_execution_id=$codepipeline_execution_id" >> $GITHUB_ENV
- name: Poll Pipeline Status
Expand All @@ -52,3 +144,13 @@ jobs:
fi

done
- name: Output Pipeline Link
if: always()
run: |
region=${{ vars.AWS_E2E_REGION }}
pipeline_name=${{ vars.AWS_E2E_RC_CODEPIPELINE_NAME }}
execution_id=${{ env.codepipeline_execution_id }}
pipeline_url="https://${region}.console.aws.amazon.com/codesuite/codepipeline/pipelines/${pipeline_name}/executions/${execution_id}?region=${region}"
echo "AWS CodePipeline Execution URL: $pipeline_url"
echo "## AWS CodePipeline Execution Link" >> $GITHUB_STEP_SUMMARY
echo "[$pipeline_url]($pipeline_url)" >> $GITHUB_STEP_SUMMARY
12 changes: 6 additions & 6 deletions buildspec-e2e-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ phases:
- export PATH=$PATH:$HOME/.pulumi/bin
- pulumi version
- pnpm install
- cd e2e/tests && npx playwright install --with-deps && cd ../..
- cd e2e/tests && npx playwright install --with-deps && cd -
- pnpm -C e2e/website install && pnpm -C e2e/website build
- UNPACK_TO_DIST=true node scripts/downloadGithubRelease.mjs
pre_build:
commands:
- pwd
- 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 ../..
- 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 -
build:
commands:
- ls -a
- cd e2e/tests && pnpm test
finally:
- cd ../..
- cd -
- echo $COMMIT_ID
- cd e2e/infra && pnpm cloudfront:destroy && pnpm lambda:destroy && cd ../..
- cd e2e/infra && pnpm cloudfront:destroy && pnpm lambda:destroy && cd -
12 changes: 12 additions & 0 deletions buildspec-e2e-release-pr-join-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 0.2

phases:

build:
commands:
- cd $CODEBUILD_SRC_DIR
- git checkout main
ilfa marked this conversation as resolved.
Show resolved Hide resolved
artifacts:
files:
- '**/*'
base-directory: $CODEBUILD_SRC_DIR
Loading