From b1891f6d7c71eec6352703f4b346ce7153f6f885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Thu, 23 Nov 2023 12:35:54 +0200 Subject: [PATCH 01/13] ci: introduce e2e pipeline for pre-releases --- azure-pipelines-rc.yml | 63 +++++++++++++++++++++++++ azure-pipelines.yml | 2 + management/github.ts | 2 +- scripts/downloadGithubReleasePackage.ts | 39 +++++++++++++++ scripts/tsconfig.json | 17 +++++++ tsconfig.json | 5 +- 6 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 azure-pipelines-rc.yml create mode 100644 scripts/downloadGithubReleasePackage.ts create mode 100644 scripts/tsconfig.json diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml new file mode 100644 index 00000000..a04510d9 --- /dev/null +++ b/azure-pipelines-rc.yml @@ -0,0 +1,63 @@ +trigger: + tags: + include: + - 'v*-test.*' + +pool: + vmImage: ubuntu-latest + +steps: +- script: echo $(Build.SourceBranch) | sed 's/refs\/tags\///' + displayName: 'Output tag' +- script: yarn install --ignore-engines && npx playwright install + displayName: 'Install dependencies' +- script: ts-node scripts/downloadGithubReleasePackage.ts + displayName: 'Download release artifact from GitHub' + env: + TAG: $(Build.SourceBranch) | sed 's/refs\/tags\///' +- script: yarn build:example-website + displayName: 'Build website' + env: + VITE_API_KEY: $(API_KEY) + VITE_ENDPOINT: $(VITE_ENDPOINT) + VITE_SCRIPT_URL_PATTERN: $(VITE_SCRIPT_URL_PATTERN) + NODE_OPTIONS: "--max_old_space_size=16384" + +- task: AzureCLI@2 + displayName: 'Deploy infrastructure' + env: + AZURE_STORAGE_ACCOUNT_NAME: $(AZURE_STORAGE_ACCOUNT_NAME) + AZURE_STORAGE_CONTAINER_NAME: $(AZURE_STORAGE_CONTAINER_NAME) + AZURE_STORAGE_RESOURCE_GROUP: $(AZURE_STORAGE_RESOURCE_GROUP) + AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID) + FPJS_PRE_SHARED_SECRET: $(FPJS_PRE_SHARED_SECRET) + inputs: + azureSubscription: 'azure-proxy-integration-e2e-tests' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: 'yarn e2e-deploy-infra' + +- task: AzureCLI@2 + inputs: + azureSubscription: 'azure-proxy-integration-e2e-tests' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: 'yarn test:e2e' + displayName: 'Run e2e tests' + env: + CI: 'true' + +- task: AzureCLI@2 + inputs: + azureSubscription: 'azure-proxy-integration-e2e-tests' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: 'yarn e2e-destroy-infra' + displayName: 'Destroy infrastructure' + condition: always() + env: + AZURE_STORAGE_ACCOUNT_NAME: $(AZURE_STORAGE_ACCOUNT_NAME) + AZURE_STORAGE_CONTAINER_NAME: $(AZURE_STORAGE_CONTAINER_NAME) + AZURE_STORAGE_RESOURCE_GROUP: $(AZURE_STORAGE_RESOURCE_GROUP) + AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID) + FPJS_PRE_SHARED_SECRET: $(FPJS_PRE_SHARED_SECRET) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e0b06b9a..9af1af20 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,5 +1,7 @@ trigger: branches: + exclude: + - 'test' include: - '*' diff --git a/management/github.ts b/management/github.ts index cd2a2a70..c20572f2 100644 --- a/management/github.ts +++ b/management/github.ts @@ -2,7 +2,7 @@ import { config } from './config' import { isSemverGreater } from './semver' import { Logger } from '@azure/functions' -function bearer(token?: string) { +export function bearer(token?: string) { return `Bearer ${token}` } diff --git a/scripts/downloadGithubReleasePackage.ts b/scripts/downloadGithubReleasePackage.ts new file mode 100644 index 00000000..f022358a --- /dev/null +++ b/scripts/downloadGithubReleasePackage.ts @@ -0,0 +1,39 @@ +import { config } from '../management/config' +import { bearer, downloadReleaseAsset, findFunctionZip, GithubRelease } from '../management/github' +import fs from 'fs' +import path from 'path' + +async function main() { + const tag = process.env.TAG + const token = process.env.GITHUB_TOKEN + + if (!tag) { + throw new Error('TAG environment variable is required') + } + + const githubRelease: GithubRelease = await fetch( + `https://api.github.com/repos/${config.repositoryOwner}/${config.repository}/releases/tags/${tag}`, + { + headers: token + ? { + Authorization: bearer(token), + } + : undefined, + }, + ).then((res) => res.json()) + + const functionZip = await findFunctionZip(githubRelease.assets) + + if (!functionZip) { + throw new Error('No function zip found') + } + + const asset = await downloadReleaseAsset(functionZip.url, token) + + fs.writeFileSync(path.resolve(__dirname, '../package.zip'), asset) +} + +main().catch((err) => { + console.error(err) + process.exit(1) +}) diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json new file mode 100644 index 00000000..142490a2 --- /dev/null +++ b/scripts/tsconfig.json @@ -0,0 +1,17 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "types": ["node"], + "module": "CommonJS" + }, + "exclude": [ + "../dist", + "node_modules", + "**/*.test.ts", + "test", + "e2e" + ], + "include": [ + "scripts/**.ts" + ] +} diff --git a/tsconfig.json b/tsconfig.json index 165bce56..4c58599d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,10 @@ "esModuleInterop": true, "sourceMap": true }, - "include": ["proxy", "management"], + "include": [ + "proxy", + "management" + ], "references": [ { "path": "./tsconfig.app.json" From 34e149b1e1f6ea822e5685235e96a65640a81a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Thu, 23 Nov 2023 12:47:40 +0200 Subject: [PATCH 02/13] ci: add ts-node --- azure-pipelines-rc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml index a04510d9..74198c79 100644 --- a/azure-pipelines-rc.yml +++ b/azure-pipelines-rc.yml @@ -9,7 +9,7 @@ pool: steps: - script: echo $(Build.SourceBranch) | sed 's/refs\/tags\///' displayName: 'Output tag' -- script: yarn install --ignore-engines && npx playwright install +- script: yarn install --ignore-engines && npx playwright install && yarn global add ts-node displayName: 'Install dependencies' - script: ts-node scripts/downloadGithubReleasePackage.ts displayName: 'Download release artifact from GitHub' From 9e8cd2899927a4cea7266ea74e63e71d95a210a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Thu, 23 Nov 2023 12:52:51 +0200 Subject: [PATCH 03/13] chore: add debug logs --- scripts/downloadGithubReleasePackage.ts | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/downloadGithubReleasePackage.ts b/scripts/downloadGithubReleasePackage.ts index f022358a..36fc70c5 100644 --- a/scripts/downloadGithubReleasePackage.ts +++ b/scripts/downloadGithubReleasePackage.ts @@ -11,19 +11,26 @@ async function main() { throw new Error('TAG environment variable is required') } - const githubRelease: GithubRelease = await fetch( - `https://api.github.com/repos/${config.repositoryOwner}/${config.repository}/releases/tags/${tag}`, - { - headers: token - ? { - Authorization: bearer(token), - } - : undefined, - }, - ).then((res) => res.json()) + console.debug('tag', tag) + + const url = `https://api.github.com/repos/${config.repositoryOwner}/${config.repository}/releases/tags/${tag}` + + console.debug('url', url) + + const githubRelease: GithubRelease = await fetch(url, { + headers: token + ? { + Authorization: bearer(token), + } + : undefined, + }).then((res) => res.json()) + + console.debug('githubRelease', githubRelease) const functionZip = await findFunctionZip(githubRelease.assets) + console.debug('functionZip', functionZip) + if (!functionZip) { throw new Error('No function zip found') } From e3487466835d85cf312d7645271a7dba3a4634ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Thu, 23 Nov 2023 12:57:55 +0200 Subject: [PATCH 04/13] ci: use correct tag name --- azure-pipelines-rc.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml index 74198c79..3744a2d4 100644 --- a/azure-pipelines-rc.yml +++ b/azure-pipelines-rc.yml @@ -6,15 +6,20 @@ trigger: pool: vmImage: ubuntu-latest +variables: + TAG: $[replace(variables['Build.SourceBranch'], 'refs/tags/', '')] + steps: -- script: echo $(Build.SourceBranch) | sed 's/refs\/tags\///' +- script: echo $TAG displayName: 'Output tag' + env: + TAG: $(TAG) - script: yarn install --ignore-engines && npx playwright install && yarn global add ts-node displayName: 'Install dependencies' - script: ts-node scripts/downloadGithubReleasePackage.ts displayName: 'Download release artifact from GitHub' env: - TAG: $(Build.SourceBranch) | sed 's/refs\/tags\///' + TAG: $(TAG) - script: yarn build:example-website displayName: 'Build website' env: From 5e92333fc63b3969d2934b838de15892584b5dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Thu, 23 Nov 2023 14:21:51 +0200 Subject: [PATCH 05/13] ci: create PR after tests pass --- azure-pipelines-rc.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml index 3744a2d4..49a879ef 100644 --- a/azure-pipelines-rc.yml +++ b/azure-pipelines-rc.yml @@ -66,3 +66,19 @@ steps: AZURE_STORAGE_RESOURCE_GROUP: $(AZURE_STORAGE_RESOURCE_GROUP) AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID) FPJS_PRE_SHARED_SECRET: $(FPJS_PRE_SHARED_SECRET) + +- script: | + curl -X POST \ + -H "Authorization: token $TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/$USER/$REPO/pulls \ + -d '{"title":"'"$PR_TITLE"'","body":"'"$PR_BODY"'","head":"'"$HEAD_BRANCH"'","base":"'"$BASE_BRANCH"'"}' + displayName: Create PR from test to main branch + env: + TOKEN: $(GITHUB_TOKEN) + USER: fingerprintjs + REPO: fingerprint-pro-azure-integration + PR_TITLE: New release + PR_BODY: New release from $(TAG) + HEAD_BRANCH: $(TAG) + BASE_BRANCH: main From 439d78b6c5357d4a5e9e892be9842249b9b69a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Thu, 23 Nov 2023 15:43:04 +0200 Subject: [PATCH 06/13] ci: revert create PR after tests pass --- azure-pipelines-rc.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml index 49a879ef..3744a2d4 100644 --- a/azure-pipelines-rc.yml +++ b/azure-pipelines-rc.yml @@ -66,19 +66,3 @@ steps: AZURE_STORAGE_RESOURCE_GROUP: $(AZURE_STORAGE_RESOURCE_GROUP) AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID) FPJS_PRE_SHARED_SECRET: $(FPJS_PRE_SHARED_SECRET) - -- script: | - curl -X POST \ - -H "Authorization: token $TOKEN" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/$USER/$REPO/pulls \ - -d '{"title":"'"$PR_TITLE"'","body":"'"$PR_BODY"'","head":"'"$HEAD_BRANCH"'","base":"'"$BASE_BRANCH"'"}' - displayName: Create PR from test to main branch - env: - TOKEN: $(GITHUB_TOKEN) - USER: fingerprintjs - REPO: fingerprint-pro-azure-integration - PR_TITLE: New release - PR_BODY: New release from $(TAG) - HEAD_BRANCH: $(TAG) - BASE_BRANCH: main From d90c35392f30010e7114b857528b725001822216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Fri, 24 Nov 2023 14:55:43 +0200 Subject: [PATCH 07/13] ci: use published trigger --- .github/workflows/create-pr-to-main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/create-pr-to-main.yml b/.github/workflows/create-pr-to-main.yml index 0dd9bf3a..790c620c 100644 --- a/.github/workflows/create-pr-to-main.yml +++ b/.github/workflows/create-pr-to-main.yml @@ -4,7 +4,6 @@ on: release: types: - published - - prereleased permissions: pull-requests: write From 7219b4b730e7ccf1bc9a9fac05618666214df18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Fri, 24 Nov 2023 14:55:54 +0200 Subject: [PATCH 08/13] ci: allow edits as well --- .github/workflows/create-pr-to-main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/create-pr-to-main.yml b/.github/workflows/create-pr-to-main.yml index 790c620c..a9049e6c 100644 --- a/.github/workflows/create-pr-to-main.yml +++ b/.github/workflows/create-pr-to-main.yml @@ -4,6 +4,7 @@ on: release: types: - published + - edited permissions: pull-requests: write From 777ff9c565cf3e45af5907098cff8907d0edd0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Mon, 27 Nov 2023 13:15:56 +0200 Subject: [PATCH 09/13] ci: remove edit trigger --- .github/workflows/create-pr-to-main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/create-pr-to-main.yml b/.github/workflows/create-pr-to-main.yml index a9049e6c..790c620c 100644 --- a/.github/workflows/create-pr-to-main.yml +++ b/.github/workflows/create-pr-to-main.yml @@ -4,7 +4,6 @@ on: release: types: - published - - edited permissions: pull-requests: write From 23f758e0ec3bb450e3597d87826dad7716f6bc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Mon, 27 Nov 2023 14:08:58 +0200 Subject: [PATCH 10/13] ci: run on all tags --- azure-pipelines-rc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml index 3744a2d4..907f4db5 100644 --- a/azure-pipelines-rc.yml +++ b/azure-pipelines-rc.yml @@ -1,7 +1,7 @@ trigger: tags: include: - - 'v*-test.*' + - '*' pool: vmImage: ubuntu-latest From 25c2cf854d5a613a7f7bf46b1bcc9a04ca00781c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Mon, 27 Nov 2023 14:10:39 +0200 Subject: [PATCH 11/13] ci: change tag --- azure-pipelines-rc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml index 907f4db5..1db1717e 100644 --- a/azure-pipelines-rc.yml +++ b/azure-pipelines-rc.yml @@ -1,7 +1,7 @@ trigger: tags: include: - - '*' + - 'v*' pool: vmImage: ubuntu-latest From 34bdda66fd17db7f7ec3d7ebb97e86c3b9bdc7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Mon, 27 Nov 2023 15:32:30 +0200 Subject: [PATCH 12/13] ci: enable manual releases --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 573fef5f..9b0361bb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,6 @@ name: release on: + workflow_dispatch: push: branches: - main From 7e033ee1e645988d961eed076b9ce3a1b58680c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Mon, 27 Nov 2023 15:42:53 +0200 Subject: [PATCH 13/13] ci: run tests only if ran from a release --- azure-pipelines-rc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml index 1db1717e..9f4c4851 100644 --- a/azure-pipelines-rc.yml +++ b/azure-pipelines-rc.yml @@ -1,3 +1,4 @@ +pr: none trigger: tags: include: