diff --git a/.deployment.config.json b/.deployment.config.json deleted file mode 100644 index ff6f9483..00000000 --- a/.deployment.config.json +++ /dev/null @@ -1,111 +0,0 @@ -{ - "product": "coveo-analytics-js", - "team_name": "dataplatformfoundation", - "general": { - "environments_order": { - "sequential": [ - "dev", - "stg", - "prd" - ] - }, - "notifications": { - "slack_channels": [ - "analyticsdeployments" - ] - }, - "team_jenkins": "uabuilds" - }, - "package_rollout": { - "only_consider_changesets_after": "688b6873442721d61e2a0ac492b9da808ddb0ef0" - }, - "observatory": { - "no_endpoint": true - }, - "ordered_phases": [ - { - "id": "deploy-major-minor-patch", - "s3": { - "bucket": "coveo-ndev-binaries", - "directory": "proda/StaticCDN/coveo.analytics.js/$[PACKAGE_JSON_MAJOR_MINOR_PATCH_VERSION]", - "parameters": { - "include": ".*", - "metadata": "X-Frame-Options=deny,X-Content-Type-Options=nosniff", - "acl": "public-read" - }, - "source": "deploy", - "stg": { - "bucket": "coveo-hstg-binaries" - }, - "prd": { - "bucket": "coveo-public-content", - "directory": "coveo.analytics.js/$[PACKAGE_JSON_MAJOR_MINOR_PATCH_VERSION]" - } - } - }, - { - "id": "deploy-major-minor", - "s3": { - "bucket": "coveo-ndev-binaries", - "directory": "proda/StaticCDN/coveo.analytics.js/$[PACKAGE_JSON_MAJOR_MINOR_VERSION]", - "parameters": { - "include": ".*", - "metadata": "X-Frame-Options=deny,X-Content-Type-Options=nosniff", - "acl": "public-read" - }, - "source": "deploy", - "stg": { - "bucket": "coveo-hstg-binaries" - }, - "prd": { - "bucket": "coveo-public-content", - "directory": "coveo.analytics.js/$[PACKAGE_JSON_MAJOR_MINOR_VERSION]" - } - } - }, - { - "id": "deploy-major", - "s3": { - "bucket": "coveo-ndev-binaries", - "directory": "proda/StaticCDN/coveo.analytics.js/$[PACKAGE_JSON_MAJOR_VERSION]", - "parameters": { - "include": ".*", - "metadata": "X-Frame-Options=deny,X-Content-Type-Options=nosniff", - "acl": "public-read" - }, - "source": "deploy", - "stg": { - "bucket": "coveo-hstg-binaries" - }, - "prd": { - "bucket": "coveo-public-content", - "directory": "coveo.analytics.js/$[PACKAGE_JSON_MAJOR_VERSION]" - } - } - }, - { - "id": "invalidate-cloudfront", - "terraform": { - "disabled": true, - "terragrunt_path": "", - "prd": { - "auto_approve": true, - "auto_approve_in_production": true, - "disabled": false - } - } - } - ], - "deployment_config_version": 13, - "certifiers": { - "dev": [ - { - "job_name": "coveoanalyticsjs_fts", - "extra_parameters": { - "VERSION": "$[PACKAGE_JSON_MAJOR_MINOR_PATCH_VERSION]" - }, - "name": "FTs" - } - ] - } -} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..36484045 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,38 @@ +name: Deployment +on: + push: + branches: [ "master" ] + workflow_dispatch: + inputs: + FORCE_DEPLOY: + type: boolean + description: Force the deploy, even if the last commit is a version bump? + DRY_RUN: + type: boolean + description: Dry run? + +jobs: + deploy: + name: Trigger Deployment + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + registry-url: 'https://registry.npmjs.org' + + - name: Build + run: npm install + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Call coveo.analytics.js-infra + run: node ./scripts/trigger-cd.mjs + env: + GH_TOKEN: ${{ secrets.CD_DISPATCHER }} + FORCE_DEPLOY: ${{ inputs.FORCE_DEPLOY || false }} + DRY_RUN: ${{ inputs.DRY_RUN || github.base_ref == 'master' || false }} + diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml new file mode 100644 index 00000000..91681f15 --- /dev/null +++ b/.github/workflows/pr-checks.yml @@ -0,0 +1,32 @@ +name: Build and Test +on: + pull_request: + branches: [ "master" ] + +jobs: + build-and-test: + name: 'Build and Test' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm install + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Build + run: npm run build + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Test + run: npm run test + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.terragrunt.hcl b/.terragrunt.hcl deleted file mode 100644 index a3504b90..00000000 --- a/.terragrunt.hcl +++ /dev/null @@ -1,3 +0,0 @@ -inputs = { - project = "coveo.analytics.js" -} \ No newline at end of file diff --git a/.terragrunt.ignore b/.terragrunt.ignore deleted file mode 100644 index e69de29b..00000000 diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 4f95fac8..00000000 --- a/Jenkinsfile +++ /dev/null @@ -1,138 +0,0 @@ -#!groovy - -def IS_MASTER = env.BRANCH_NAME == 'master' -def skipRemainingStages = false - -library( - identifier: 'jenkins-common-lib@v1.6', - retriever: modernSCM(github(credentialsId: 'github-app-dev', repository: 'jenkins-common-lib', repoOwner: 'coveo')), - changelog: false -) - -pipeline { - agent { - label 'build && docker && linux' - } - - parameters { - booleanParam(defaultValue: false, description: 'Forces the deploy, even if the last commit is a version bump', name: 'FORCE_DEPLOY') - } - - environment { - NPM_TOKEN = credentials("coveo-analytics-js-npm-deployment-token") - GIT = credentials('github-coveobot') - GH_TOKEN = credentials('github-coveobot_token') - } - - options { - ansiColor('xterm') - timestamps() - disableConcurrentBuilds() - timeout(time: 45, unit: 'MINUTES') - } - - stages { - stage('Skip') { - when { expression { params.FORCE_DEPLOY == false } } - steps { - script { - commitMessage = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim() - if (commitMessage.contains('[version bump]')) { - skipRemainingStages = true - println 'Skipping this build because it was triggered by a version bump.' - } else { - skipRemainingStages = false - println 'Not a version bump, the build will proceed.' - } - } - } - } - - stage('Setup') { - when { expression { !skipRemainingStages } } - steps { - script { - def nodeHome = tool name: 'NodeJS Latest', type: 'nodejs' - env.PATH = "${nodeHome}/bin:${env.PATH}" - sh "npm config set //registry.npmjs.org/:_authToken=${env.NPM_TOKEN}" - } - } - } - - stage('Bump version') { - when { - allOf { - expression { IS_MASTER } - expression { !skipRemainingStages } - } - } - steps { - script { - gitUtils.withCredentialHelper() { - gitUtils.setUser() - sh "git fetch" - sh "git checkout master" - sh "git pull" - sh "npm version patch -m \"[version bump] Automated release to v%s\"" - } - } - } - } - - stage('Build') { - when { expression { !skipRemainingStages }} - steps { - sh 'npm install' - sh 'npm run build' - } - } - - stage('Test') { - when { expression { !skipRemainingStages }} - steps { - sh 'npm run test' - } - } - - stage('Deployment Pipeline') { - when { expression { !skipRemainingStages }} - steps { - script { - sh "npm publish --dry-run" - sh 'npm run prepare-deploy' - env.PACKAGE_JSON_MAJOR_MINOR_PATCH_VERSION = sh(script: './read.version.sh patch', returnStdout: true).trim() - env.PACKAGE_JSON_MAJOR_MINOR_VERSION = sh(script: './read.version.sh minor', returnStdout: true).trim() - env.PACKAGE_JSON_MAJOR_VERSION = sh(script: './read.version.sh major', returnStdout: true).trim() - def tgfResolveParameter = [ - "PACKAGE_JSON_MAJOR_MINOR_PATCH_VERSION=${env.PACKAGE_JSON_MAJOR_MINOR_PATCH_VERSION}", - "PACKAGE_JSON_MAJOR_MINOR_VERSION=${env.PACKAGE_JSON_MAJOR_MINOR_VERSION}", - "PACKAGE_JSON_MAJOR_VERSION=${env.PACKAGE_JSON_MAJOR_VERSION}", - "TF_VAR_package_json_major_version=${env.PACKAGE_JSON_MAJOR_VERSION}" - ] - deploymentPackage.command(command: 'package create', parameters: [ - version: env.PACKAGE_JSON_MAJOR_VERSION, - 'package-suffix': env.PACKAGE_JSON_MAJOR_MINOR_PATCH_VERSION, - resolve: tgfResolveParameter, - withDeploy: IS_MASTER, - dryRun: !IS_MASTER - ]) - } - } - } - - stage('Publish') { - when { - allOf { - expression { IS_MASTER } - expression { !skipRemainingStages } - } - } - steps { - script { - sh "npm publish" - gitUtils.push() - } - } - } - } -} diff --git a/deploy.sh b/deploy.sh deleted file mode 100644 index 1f307187..00000000 --- a/deploy.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/env bash - -git config user.name "via Jenkins" -git config user.email "jenkins@coveo.com" - -echo "> git checkout $RELEASE_TAG" -git checkout $RELEASE_TAG - -echo "> git tag -a -f latest -m \"Deploy $RELEASE_TAG\"" -git tag -a -f latest -m "Deploy $RELEASE_TAG" - -echo "> git push --force --tags \"https://${GH_TOKEN}@github.com/coveo/coveo.analytics.js.git\" > /dev/null 2>&1" -git push --force --tags "https://${GH_TOKEN}@github.com/coveo/coveo.analytics.js.git" > /dev/null 2>&1 diff --git a/package.json b/package.json index d5382225..2730edd5 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,9 @@ "@babel/core": "^7.23.2", "@babel/preset-env": "7.23.2", "@babel/register": "^7.22.15", + "@actions/core": "1.10.1", + "@actions/github": "6.0.0", + "@octokit/rest": "20.1.1", "@rollup/plugin-alias": "^5.0.0", "@rollup/plugin-commonjs": "^24.1.0", "@rollup/plugin-json": "^6.0.0", diff --git a/read.version.sh b/read.version.sh deleted file mode 100755 index 8bc7a854..00000000 --- a/read.version.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -if [ "$1" == "" ] -then - export PACKAGE_JSON_MAJOR_MINOR_PATCH_VERSION=`cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | xargs` - export PACKAGE_JSON_MAJOR_MINOR_VERSION=`cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed -E 's/\.[0-9]+$//g' | xargs` - export PACKAGE_JSON_MAJOR_VERSION=`cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed -E 's/\.[0-9]+\.[0-9]+$//g' | xargs` -elif [ "$1" == "patch" ] -then - echo `cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | xargs` -elif [ "$1" == "minor" ] -then - echo `cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed -E 's/\.[0-9]+$//g' | xargs` -elif [ "$1" == "major" ] -then - echo `cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed -E 's/\.[0-9]+\.[0-9]+$//g' | xargs` -fi \ No newline at end of file diff --git a/scripts/trigger-cd.mjs b/scripts/trigger-cd.mjs new file mode 100644 index 00000000..baf9853d --- /dev/null +++ b/scripts/trigger-cd.mjs @@ -0,0 +1,15 @@ +import {context, getOctokit} from '@actions/github'; + +const octokit = getOctokit(process.env.GH_TOKEN); + +await octokit.rest.repos.createDispatchEvent({ + event_type: 'deploy', + client_payload: { + run_Id: context.runId, + FORCE_DEPLOY: process.env.FORCE_DEPLOY, + DRY_RUN: process.env.DRY_RUN + }, + owner: 'coveo-platform', + repo: 'coveo.analytics.js-infra', +}); + diff --git a/terraform/.terragrunt.hcl b/terraform/.terragrunt.hcl deleted file mode 100644 index 6c3f709b..00000000 --- a/terraform/.terragrunt.hcl +++ /dev/null @@ -1,3 +0,0 @@ -inputs = { - project = "coveo-analytics-js" -} \ No newline at end of file diff --git a/terraform/.tgf.config b/terraform/.tgf.config deleted file mode 100644 index e398269d..00000000 --- a/terraform/.tgf.config +++ /dev/null @@ -1 +0,0 @@ -docker-image-version: "3.21" \ No newline at end of file diff --git a/terraform/coveo-analytics-js/.terragrunt.hcl b/terraform/coveo-analytics-js/.terragrunt.hcl deleted file mode 100644 index 425111f0..00000000 --- a/terraform/coveo-analytics-js/.terragrunt.hcl +++ /dev/null @@ -1,10 +0,0 @@ -include { - path = find_in_parent_folders() -} - -inputs = { - import_prefix = "@" - import_projects = [ - "cdn/static-cloud-coveo-com", - ] -} diff --git a/terraform/coveo-analytics-js/@env-dev-us-east-1.tfvars b/terraform/coveo-analytics-js/@env-dev-us-east-1.tfvars deleted file mode 100644 index 39480f46..00000000 --- a/terraform/coveo-analytics-js/@env-dev-us-east-1.tfvars +++ /dev/null @@ -1,2 +0,0 @@ -# current cloudfront value in dev (will be soon dynamic from cdn project outputs) -cloudfront_id = "E3V0XLBYVY9KPS" \ No newline at end of file diff --git a/terraform/coveo-analytics-js/@env-prd-us-east-1.tfvars b/terraform/coveo-analytics-js/@env-prd-us-east-1.tfvars deleted file mode 100644 index 4820e4ba..00000000 --- a/terraform/coveo-analytics-js/@env-prd-us-east-1.tfvars +++ /dev/null @@ -1,2 +0,0 @@ -# current cloudfront value in production (will be soon dynamic from cdn project outputs) -cloudfront_id = "E2VWLFSCSD1GLA" \ No newline at end of file diff --git a/terraform/coveo-analytics-js/invalidate-cloudfront.tf b/terraform/coveo-analytics-js/invalidate-cloudfront.tf deleted file mode 100644 index b59d9c53..00000000 --- a/terraform/coveo-analytics-js/invalidate-cloudfront.tf +++ /dev/null @@ -1,29 +0,0 @@ -locals { - # until the cdn project is deployed, the variable does not exist yet, so we are taking default value. - cloudfront_id = try(var.cdn.static_cloud_coveo_com.static_cloudfront_id, var.cloudfront_id) -} - -variable "cloudfront_id" { - description = "Cloudfront distribution id (will soon be dynamic and removed)" - default = "" -} - -variable "package_version" { - description = "Defines the major version that has just been deployed" -} - -resource "null_resource" "invalidate-cloudfront" { - triggers = { - always_run = "${timestamp()}" - } - # do not do the call if the id is empty - count = local.cloudfront_id != "" ? 1 : 0 - provisioner "local-exec" { - command = "aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths \"/coveo.analytics.js/${var.package_version}/*\"" - - environment = { - CLOUDFRONT_DISTRIBUTION_ID = local.cloudfront_id - AWS_DEFAULT_REGION = var.region - } - } -}