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 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 diff --git a/azure-pipelines-rc.yml b/azure-pipelines-rc.yml new file mode 100644 index 00000000..9f4c4851 --- /dev/null +++ b/azure-pipelines-rc.yml @@ -0,0 +1,69 @@ +pr: none +trigger: + tags: + include: + - 'v*' + +pool: + vmImage: ubuntu-latest + +variables: + TAG: $[replace(variables['Build.SourceBranch'], 'refs/tags/', '')] + +steps: +- 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: $(TAG) +- 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..36fc70c5 --- /dev/null +++ b/scripts/downloadGithubReleasePackage.ts @@ -0,0 +1,46 @@ +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') + } + + 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') + } + + 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"