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

JSUI-3159 Run CI/CD on jenkins and deploy beta tags to npm #1665

Merged
merged 17 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .deployment.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"product": "coveo-search-ui",
"team_name": "searchui",
"general": {
"aws_regions": {
"sequential": [
"us-east-1"
]
},
"environments_order": {
"sequential": [
"dev",
"qa",
"prd"
]
},
"team_jenkins": "searchuibuilds",
"start_environment_automatically": false,
"notifications": {
"slack_channels": [
"#searchuibuilds"
]
}
},
"phases": {
"s3": {
"bucket": "coveo-nprod-binaries",
"directory": "proda/StaticCDN/searchui/v$[MAJOR_MINOR_VERSION]",
"parameters": {
"acl": "public-read"
},
"dev": {
"disabled": true
},
"qa": {
"disabled": true
},
"source": "bin"
}
},
"certifiers": {
"dev": [
{
"job_name": "search_ui/job/functional_tests",
"tag_suffix": "passed_functional_tests",
"extra_parameters": {
"SEARCH_UI_VERSION": "$[HEROKU_VERSION]"
}
},
{
"system_certifier": "snyk"
},
{
"system_certifier": "veracode"
}
],
"prd": [
{
"job_name": "search_ui/job/update_npm_latest_tag",
"tag_suffix": "npm_latest_tag_updated",
"extra_parameters": {
"LATEST_NPM_VERSION": "$[LATEST_NPM_VERSION]"
}
}
]
},
"snyk": {
"org": "coveo-jsui",
"no_container_images": true,
"configurations": [
{
"directory": ".",
"project_name": "search-ui"
}
]
},
"veracode": {
"sandbox_name": "JS UI",
"scan_include_patterns": "*"
},
"observatory": {
"no_endpoint": true
},
"package_rollout": {
"only_consider_changesets_after": "16247824e24b"
},
"deployment_config_version": 1
}
76 changes: 76 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
node('linux && docker') {
checkout scm

withEnv([
'npm_config_cache=npm-cache'
]){
withDockerContainer(image: 'node:14', args: '-u=root') {
stage('Install') {
sh 'yarn install'
}

stage('Build') {
sh '. ./read.version.sh'
sh 'echo $PACKAGE_JSON_VERSION'
sh 'yarn run injectTag'
sh 'yarn run build'

if (env.GIT_TAG_NAME) {
sh 'yarn run minimize'
}
}

stage('Install Chrome') {
sh "wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -"
sh "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list"
sh "apt-get update"
sh "apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 libxtst6 --no-install-recommends"
sh "google-chrome --version"
}

stage('Test') {
sh 'yarn run unitTests'

if (env.GIT_TAG_NAME) {
sh 'yarn run accessibilityTests'
}

sh 'set +e'
// sh 'yarn run uploadCoverage'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the issue is the same as the one here: https://stackoverflow.com/questions/41978173/grunt-karma-coverage-fails-on-jenkins-but-works-on-windows-unix

I did not see a way to configure the option in the solution. I will revisit this in the future,

sh 'set -e'
sh 'yarn run validateTypeDefinitions'
}

stage('Docs') {
sh 'if [[ "x$GIT_TAG_NAME" != "x" && $IS_PULL_REQUEST_PUSH_BUILD = false ]]; then bash ./deploy.doc.sh ; fi'
sh 'yarn run docsitemap'
sh 'yarn run zipForGitReleases'
}
}

if (!env.GIT_TAG_NAME) {
return
}

stage('Deploy') {
withCredentials([
string(credentialsId: 'NPM_TOKEN', variable: 'NPM_TOKEN')
]) {
sh(script: 'node ./build/npm.deploy.js')
}
}

withDockerContainer(image: '458176070654.dkr.ecr.us-east-1.amazonaws.com/jenkins/deployment_package:v7') {
stage('Veracode package') {
sh 'rm -rf veracode && mkdir veracode'

sh 'mkdir veracode/search-ui'
sh 'cp -R src package.json yarn.lock veracode/search-ui'
}

stage('Deployment pipeline upload') {
sh 'deployment-package package create --with-deploy || true'
}
}
}
}
42 changes: 42 additions & 0 deletions build/npm.deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
const fs = require('fs');
const os = require('os');

const tag = process.env.GIT_TAG_NAME;

function isTagged() {
return tag && tag !== '';
}

async function deployTaggedVersion() {
const suffix = 'beta';
console.log(`Doing a NPM deployment of a ${suffix} version`);
await publishToNpm(['--tag', suffix], `Deploy ${suffix} is done`);
}

async function publishToNpm(publishArgs = [], successMessage) {
const args = ['publish', ...publishArgs].join(' ');
await exec(`npm ${args}`);
console.log(successMessage);
}

function setNpmrcFile() {
const fileName = `${os.homedir()}/.npmrc`;
const npmrcString = `//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}`;

console.log('setting npmrc file');
return new Promise((resolve, reject) => fs.writeFile(fileName, npmrcString, err => (err ? reject(err) : resolve())));
}

async function main() {
if (!isTagged()) {
return console.log('Skipping NPM deployment because this is not a tagged commit');
}

await setNpmrcFile();
await deployTaggedVersion();
}

main();
29 changes: 0 additions & 29 deletions deploy.beta.js

This file was deleted.

6 changes: 3 additions & 3 deletions gulpTasks/injectTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const replace = require('gulp-replace');
const colors = require('colors');

function injectTag() {
if (process.env.TRAVIS_TAG) {
console.log(`Injecting ${process.env.TRAVIS_TAG} in Coveo.version ...`.black.bgGreen);
if (process.env.GIT_TAG_NAME) {
console.log(`Injecting ${process.env.GIT_TAG_NAME} in Coveo.version ...`.black.bgGreen);
return gulp
.src('./src/misc/Version.ts')
.pipe(replace(/0\.0\.0\.0/g, process.env.TRAVIS_TAG))
.pipe(replace(/0\.0\.0\.0/g, process.env.GIT_TAG_NAME))
.pipe(gulp.dest('./src/misc/'));
}

Expand Down
2 changes: 1 addition & 1 deletion gulpTasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function configureTestServer(configPath, cb) {

const coverage = gulp.series(remapCoverage, convertCoverageToLcovFormat);

const uploadCoverage = gulp.series(coverage, shell.task(['cat bin/coverage/lcov.info | npx coveralls']));
const uploadCoverage = gulp.series(coverage, shell.task([`cat ${COVERAGE_DIR}/lcov.info | npx coveralls`]));

function remapCoverage() {
return gulp
Expand Down
4 changes: 2 additions & 2 deletions invalidate.cloudfront.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const shouldDoInvalidation = () => {
if (!process.env.TRAVIS) {
return false;
}
if (!process.env.TRAVIS_TAG) {
if (!process.env.GIT_TAG_NAME) {
return false;
}
if (process.env.TRAVIS_TAG.indexOf('beta') != -1) {
if (process.env.GIT_TAG_NAME.indexOf('beta') != -1) {
return false;
}
return true;
Expand Down
8 changes: 7 additions & 1 deletion karma.unit.test.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ process.env.CHROME_BIN = puppeteer.executablePath();

const configuration = {
singleRun: true,
browsers: ['ChromeHeadless'],
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed to use no-sandbox to run on the latest chrome.

Ref: karma-runner/karma-chrome-launcher#158 (comment)

frameworks: ['jasmine'],
browserDisconnectTimeout: 120000,
browserNoActivityTimeout: 120000,
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
"lint-staged": "^4.1.3",
"node-fetch": "^2.6.1",
"node-sass": "^4.14.1",
"npm-cli-login": "0.1.1",
"null-loader": "^0.1.1",
"pg": "^7.3.0",
"plop": "^1.5.0",
Expand Down Expand Up @@ -181,4 +180,4 @@
"@types/node": "~10.5.4"
},
"snyk": true
}
}
2 changes: 1 addition & 1 deletion read.version.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash

export PACKAGE_JSON_VERSION=`cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed -E 's/\.[0-9]+$//g' | xargs`
export PACKAGE_PATCH_VERSION=`cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed -E 's/[0-9]+\.[0-9]+\.//g' | xargs`
Loading