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

Chore: CI for nightly build #68

Merged
merged 6 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
90 changes: 85 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ executors:
# https://github.com/facebook/jest/issues/11956
- image: cimg/node:16.10.0

parameters:
workflow_name:
type: string
default: 'none'

# Set some environment variables like the base SHA of PRs ...etc.
set_env: &set_env
name: Setup Environment Variables
Expand All @@ -26,11 +31,21 @@ set_env: &set_env
echo 'export AFFECTED_ARGS="--head=HEAD --base=${CIRCLE_PR_BASE_SHA}"' >> $BASH_ENV

elif [ "$CIRCLE_BRANCH" == "develop" ]; then
# Merge into develop branch, use main branch as the base.

echo "Using main branch as the base"
echo 'export AFFECTED_ARGS="--head=HEAD --base=origin/main"' >> $BASH_ENV

# Use the last build commit if there is nightly-build tag

last_commit="$(git rev-list -n 1 tags/nightly-build || echo '')"

# Check whether the commit is on the target branch
if [ "$last_commit" != "" ] && [ "$(git merge-base $last_commit $CIRCLE_BRANCH)" == "$last_commit" ]; then
# use last build sha as the base.
echo "Using $last_commit as the base (last build)"
echo "export AFFECTED_ARGS=\"--head=HEAD --base=$last_commit\"" >> $BASH_ENV
else
# use main branch as the base.
echo "Using main branch as the base"
echo 'export AFFECTED_ARGS="--head=HEAD --base=origin/main"' >> $BASH_ENV
fi

else

echo "Testing/Linting on all packages"
Expand Down Expand Up @@ -136,9 +151,52 @@ jobs:
echo "No coverage report found."
fi

nightly-build:
executor: node-executor
steps:
# Using the deployment key with write access
- add_ssh_keys:
fingerprints:
- 'd8:c0:e1:c8:8b:8d:dd:f8:50:cd:d9:34:1c:21:3d:85'
- checkout
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
# Setup remote docker to build image
# https://circleci.com/docs/building-docker-images
- setup_remote_docker
- run:
name: NPM publish
# running with yarn nx causes npm config issues
command: ./node_modules/.bin/nx affected --target=publish ${AFFECTED_ARGS} --tag dev
environment:
READY_FOR_PUBLISH: 'true'
- run:
name: Docker login
command: echo "${GITHUB_PAT}" | docker login ghcr.io -u ${GITHUB_USER} --password-stdin
- run:
name: Docker publish
command: yarn nx affected --target=publish:docker ${AFFECTED_ARGS} --tag dev
environment:
READY_FOR_PUBLISH: 'true'
# After a success build, move the tag nightly-build to HEAD
- run:
name: Move nightly-build tag
command: |
# delete remote tag
git push origin :refs/tags/nightly-build
# tag current HEAD
git tag -f nightly-build
# push tag
git push origin $CIRCLE_BRANCH --tags

workflows:
version: 2
pr-check:
when:
not:
equal: [scheduled_pipeline, << pipeline.trigger_source >>]
jobs:
- install
- lint:
Expand All @@ -147,3 +205,25 @@ workflows:
- test:
requires:
- install
nightly-build:
when:
or:
- and:
- equal: [scheduled_pipeline, << pipeline.trigger_source >>]
- equal: ['nightly build', << pipeline.schedule.name >>]
- and:
- equal: [api, << pipeline.trigger_source >>]
- equal: ['nightly build', << pipeline.parameters.workflow_name >>]
jobs:
- install
- lint:
requires:
- install
- test:
requires:
- install
- nightly-build:
requires:
- install
- lint
- test
4 changes: 2 additions & 2 deletions packages/build/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vulcan-sql/build",
"description": "VulcanSQL package for building projects",
"version": "0.1.0-alpha.1",
"version": "0.2.0",
"type": "commonjs",
"publishConfig": {
"access": "public"
Expand All @@ -22,6 +22,6 @@
},
"license": "MIT",
"peerDependencies": {
"@vulcan-sql/core": "0.1.0-alpha.1"
"@vulcan-sql/core": "~0.2.0-0"
}
}
2 changes: 1 addition & 1 deletion packages/build/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node ../../../tools/scripts/publish.mjs {args.tag}",
"command": "node ../../../tools/scripts/publish.mjs {args.tag} {args.version}",
"cwd": "dist/packages/build"
},
"dependsOn": [
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM node:16-alpine
# Annotation required by Github to link with our repository
LABEL org.opencontainers.image.source https://github.com/canner/vulcan-sql

COPY ../../dist/packages/cli/ /usr/cli
# We'll execute docker build from project root. Using absolute path to avoid "forbidden path outside the build contex" error
COPY /dist/packages/cli/ /usr/cli
WORKDIR /usr/cli
ENV NODE_ENV=production
RUN npm i
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vulcan-sql/cli",
"description": "CLI tools for VulcanSQL",
"version": "0.1.0-alpha.1",
"version": "0.2.0",
"type": "commonjs",
"bin": {
"vulcan": "./src/index.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node ../../../tools/scripts/publish.mjs {args.tag}",
"command": "node ../../../tools/scripts/publish.mjs {args.tag} {args.version}",
"cwd": "dist/packages/cli"
},
"dependsOn": [
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ program
.argument('[path]', 'folder path to initialize Vulcan project')
.description('create a new Vulcan project')
.option('-p --project-name <project-name>', 'specify project name')
.option('-v --version <version>', 'specify Vulcan version')
.action(async (path: string | undefined, options) => {
await handleInit(path, options || {});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const serveVulcan = async (options: ServeCommandOptions) => {
// Start server
logger.info(`Starting server...`);
const server = new VulcanServer(config);
await server.start(options.port);
logger.info(`Server is listening at port ${options.port}.`);
await server.start();
logger.info(`Server is listening at port ${config.port || 3000}.`);
addShutdownJob(async () => {
logger.info(`Stopping server...`);
await server.close();
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/schemas/init/vulcan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ document-generator:
folderPath: .
types:
- RESTFUL
enforce-https:
enabled: false
34 changes: 27 additions & 7 deletions packages/cli/test/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,36 @@ import * as jsYAML from 'js-yaml';
import * as path from 'path';
import { runShutdownJobs } from '../src/utils';
import * as supertest from 'supertest';
import faker from '@faker-js/faker';

const projectName = 'test-vulcan-project';
const testingVersion = '0.1.2-dev.20220913.0';
const testingServerPort = faker.datatype.number({ min: 20000, max: 30000 });

const workspaceRoot = path.resolve(__dirname, '..', '..', '..');
const projectRoot = path.resolve(workspaceRoot, projectName);

beforeAll(async () => {
await fs.rm(projectRoot, { recursive: true, force: true });
await program.parseAsync(['node', 'vulcan', 'init', '-p', projectName]);
await program.parseAsync([
'node',
'vulcan',
'init',
'-p',
projectName,
'-v',
testingVersion,
]);
process.chdir(projectRoot);
const projectConfig = jsYAML.load(
await fs.readFile(path.resolve(projectRoot, 'vulcan.yaml'), 'utf-8')
) as Record<string, any>;
projectConfig['port'] = testingServerPort;
fs.writeFile(
path.resolve(projectRoot, 'vulcan.yaml'),
jsYAML.dump(projectConfig),
'utf-8'
);
}, 30000);

afterAll(async () => {
Expand Down Expand Up @@ -45,19 +65,19 @@ it('Build command should make result.json', async () => {
it('Serve command should start Vulcan server', async () => {
// Action
await program.parseAsync(['node', 'vulcan', 'build']);
await program.parseAsync(['node', 'vulcan', 'serve', '-p', '12345']);
const agent = supertest('http://localhost:12345');
const result = await agent.get('/');
await program.parseAsync(['node', 'vulcan', 'serve']);
const agent = supertest(`http://localhost:${testingServerPort}`);
const result = await agent.get('/doc');
// Assert
expect(result.statusCode).toBe(200);
await runShutdownJobs();
});

it('Start command should build the project and start Vulcan server', async () => {
// Action
await program.parseAsync(['node', 'vulcan', 'start', '-p', '12345']);
const agent = supertest('http://localhost:12345');
const result = await agent.get('/');
await program.parseAsync(['node', 'vulcan', 'start']);
const agent = supertest(`http://localhost:${testingServerPort}`);
const result = await agent.get('/doc');
// Assert
expect(result.statusCode).toBe(200);
await runShutdownJobs();
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/test/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as jsYAML from 'js-yaml';
import * as path from 'path';
import { runShutdownJobs } from '../src/utils';

const projectName = 'test-vulcan-project';
const projectName = 'test-vulcan-project-init';
const testingVersion = '0.1.2-dev.20220913.0';

const workspaceRoot = path.resolve(__dirname, '..', '..', '..');
const projectRoot = path.resolve(workspaceRoot, `${projectName}-with-path`);
Expand All @@ -29,6 +30,8 @@ it('Init command with folder path should create default config in target folder'
'init',
'-p',
projectName,
'-v',
testingVersion,
projectRoot,
]);
// Action
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vulcan-sql/core",
"description": "Core package of VulcanSQL",
"version": "0.1.0-alpha.1",
"version": "0.2.0",
"type": "commonjs",
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node ../../../tools/scripts/publish.mjs {args.tag}",
"command": "node ../../../tools/scripts/publish.mjs {args.tag} {args.version}",
"cwd": "dist/packages/core"
},
"dependsOn": [
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-dbt/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vulcan-sql/extension-dbt",
"description": "Using dbt models form VulcanSQL projects",
"version": "0.1.0-alpha.1",
"version": "0.2.0",
"type": "commonjs",
"publishConfig": {
"access": "public"
Expand All @@ -23,6 +23,6 @@
},
"license": "MIT",
"peerDependencies": {
"@vulcan-sql/core": "0.x"
"@vulcan-sql/core": "~0.2.0-0"
}
}
2 changes: 1 addition & 1 deletion packages/extension-dbt/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node ../../../tools/scripts/publish.mjs {args.tag}",
"command": "node ../../../tools/scripts/publish.mjs {args.tag} {args.version}",
"cwd": "dist/packages/extension-dbt"
},
"dependsOn": [
Expand Down
23 changes: 21 additions & 2 deletions packages/extension-debug-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
{
"name": "@vulcan-sql/extension-debug-tools",
"version": "0.1.0-alpha.1",
"description": "A collection of Vulcan extension debug tools",
"version": "0.2.0",
"type": "commonjs",
"publishConfig": {
"access": "public"
},
"keywords": [
"vulcan",
"vulcan-sql",
"data",
"sql",
"database",
"data-warehouse",
"data-lake",
"api-builder"
],
"repository": {
"type": "git",
"url": "https://github.com/Canner/vulcan.git"
},
"license": "MIT",
"peerDependencies": {
"@vulcan-sql/core": "*"
"@vulcan-sql/core": "~0.2.0-0"
},
"devDependencies": {
"@vulcan-sql/test-utility": "0.1.0-alpha.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-debug-tools/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node ../../../tools/scripts/publish.mjs {args.tag}",
"command": "node ../../../tools/scripts/publish.mjs {args.tag} {args.version}",
"cwd": "dist/packages/extension-debug-tools"
},
"dependsOn": [
Expand Down
4 changes: 2 additions & 2 deletions packages/serve/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vulcan-sql/serve",
"description": "VulcanSQL package for serving projects",
"version": "0.1.0-alpha.1",
"version": "0.2.0",
"type": "commonjs",
"publishConfig": {
"access": "public"
Expand All @@ -22,6 +22,6 @@
},
"license": "MIT",
"peerDependencies": {
"@vulcan-sql/core": "0.1.0-alpha.1"
"@vulcan-sql/core": "~0.2.0-0"
}
}
2 changes: 1 addition & 1 deletion packages/serve/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node ../../../tools/scripts/publish.mjs {args.tag}",
"command": "node ../../../tools/scripts/publish.mjs {args.tag} {args.version}",
"cwd": "dist/packages/serve"
},
"dependsOn": [
Expand Down
Loading