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

Add E2E tests for pre-releases #150

Merged
merged 12 commits into from
Dec 1, 2023
15 changes: 15 additions & 0 deletions .github/workflows/create-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Create PR

on:
release:
types:
- published

jobs:
create-pr:
name: Create PR
uses: fingerprintjs/dx-team-toolkit/.github/workflows/create-pr.yml@v1
with:
target_branch: ${{ github.event.release.prerelease && 'main' || 'test' }}
tag_name: ${{ github.event.release.tag_name }}
prerelease: ${{ github.event.release.prerelease }}
1 change: 1 addition & 0 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
[
"@semantic-release/git",
{
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}",
"assets": [
"CHANGELOG.md",
"package.json"
Expand Down
56 changes: 56 additions & 0 deletions buildspec-e2e-rc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: 0.2
env:
secrets-manager:
GITHUB_TOKEN: "fpjs-dev-cloudfront-secrets:GITHUB_TOKEN"
phases:
install:
commands:
- echo $COMMIT_ID
- 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/708050157146/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
- pulumi version
- yarn install
- yarn install --cwd=e2e/infra
- yarn install --cwd=e2e/website
- yarn install --cwd=e2e/tests
- cd e2e/tests && npx playwright install --with-deps && cd ../..
- UNPACK_TO_DIST=true node scripts/downloadGithubRelease.mjs
pre_build:
commands:
- pwd
- pulumi version
- cd e2e/website && yarn build && 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 && yarn lambda:up && yarn lambda:export && yarn cloudfront:up && yarn cloudfront:export && cd ../..
build:
commands:
- ls -a
- cd e2e/tests && yarn test
finally:
- cd ../..
- echo $CODEBUILD_BUILD_SUCCEEDING
- echo $COMMIT_ID
- 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_ID \
-d "{\"state\":\"$STATUS\",\"target_url\":\"https://us-east-1.console.aws.amazon.com/codesuite/codebuild/708050157146/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 && yarn cloudfront:destroy && yarn lambda:destroy && cd ../..
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dist"
],
"engines": {
"node": "~16"
"node": ">=16"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the adm-zip I had to change the engine.
I think that we can leave it as it is, and also consider bumping the lambda@edge runtime to node 18 at some point.

},
"resolutions": {
"wrap-ansi": "7.0.0"
Expand All @@ -46,6 +46,7 @@
"@types/punycode": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"adm-zip": "^0.5.10",
"commitizen": "^4.2.4",
"conventional-changelog-conventionalcommits": "5.0.0",
"cz-conventional-changelog": "^3.3.0",
Expand All @@ -54,9 +55,9 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"jest": "^29.2.2",
"jest-environment-jsdom": "^29.2.2",
"lint-staged": "^13.0.3",
"prettier": "^2.8.0",
"rollup": "^2.70.1",
"rollup-plugin-dts": "^5.0.0",
Expand Down
59 changes: 55 additions & 4 deletions scripts/downloadGithubRelease.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import Zip from 'adm-zip'

const config = {
token: process.env.GITHUB_TOKEN,
Expand All @@ -13,7 +14,7 @@ const dirname = path.dirname(fileURLToPath(import.meta.url))
console.debug('dirname', dirname)

async function main() {
const release = await getLatestGithubRelease()
const release = await getGithubRelease()

if (!release) {
console.warn('No release found')
Expand All @@ -32,18 +33,68 @@ async function main() {

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

fs.writeFileSync(path.resolve(dirname, '../package.zip'), zip)
if (process.env.UNPACK_TO_DIST) {
new Zip(zip).extractAllTo(path.resolve(dirname, '../dist'), true)
} else {
fs.writeFileSync(path.resolve(dirname, '../package.zip'), zip)
}
}

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

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

if (!commitId) {
return getLatestGithubRelease()
}

console.info('Using commit id', commitId)

return getGithubReleaseByCommitId(commitId)
}

async function listTags() {
const url = `https://api.github.com/repos/${config.owner}/${config.repo}/tags`

console.debug('fetchTags url', url)

return await doGithubGetRequest(url)
}

async function getGithubReleaseByCommitId(commitId) {
const tag = await listTags().then((response) => findTagByCommitId(response, commitId))

if (!tag) {
throw new Error(`Tag for commit ${commitId} not found`)
}

return await getGithubReleaseByTag(tag.name)
}

async function getGithubReleaseByTag(tag) {
const url = `https://api.github.com/repos/${config.owner}/${config.repo}/releases/tags/${tag}`

console.debug('getGithubReleaseByTag url', url)

return await doGithubGetRequest(url)
}

function findTagByCommitId(tags, commitId) {
return tags.find((tag) => tag?.commit?.sha === commitId)
}

async function getLatestGithubRelease() {
const url = `https://api.github.com/repos/${config.owner}/${config.repo}/releases/latest`

console.info('url', url)
console.info('getLatestGithubRelease url', url)

return await doGithubGetRequest(url)
}

async function doGithubGetRequest(url) {
const response = await fetch(url, {
headers: config.token
? {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,11 @@ acorn@^8.4.1:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5"
integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==

adm-zip@^0.5.10:
version "0.5.10"
resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.5.10.tgz#4a51d5ab544b1f5ce51e1b9043139b639afff45b"
integrity sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==

agent-base@6:
version "6.0.2"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
Expand Down
Loading