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: Add Circle CI #32

Merged
merged 7 commits into from
Aug 18, 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
118 changes: 118 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
version: 2.1

executors:
node-executor:
working_directory: ~/repo
docker:
# Jest has issues with node > 16.11.0, please stick node version until the issues are resolved
# https://github.com/facebook/jest/issues/11956
- image: cimg/node:16.10.0

# Set some environment variables like the base SHA of PRs ...etc.
set_env: &set_env
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggesting to add a simple comment to hint you will use the set_env variable which defined some steps options in below steps of jobs.

name: Setup Environment Variables
command: |

echo 'Fetching Base Commit from GitHub'
# Get the PR number from env for different kinds of PR
echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV
source $BASH_ENV
# Obtain the SHA via Github API
echo "export CIRCLE_PR_BASE_SHA=`curl -s https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.sha'`" >> $BASH_ENV
# Set the affected args for nx affect xxx commands
echo 'export AFFECTED_ARGS="--base=${CIRCLE_PR_BASE_SHA}"' >> $BASH_ENV
# Set the memory size for node processes
echo 'export NODE_OPTIONS="--max_old_space_size=6144"' >> $BASH_ENV
source $BASH_ENV
echo $AFFECTED_ARGS

# Retrieve node_modules and the module cache from Circle CI storage.
yarn_cache: &yarn_cache
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above set_env suggestion

keys:
- node-deps-node16-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- node-deps-node16-

# Install node modules via yarn with the frozen lock file
yarn_install: &yarn_install
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above set_env suggestion

name: Install Dependencies
command: yarn install --frozen-lockfile --non-interactive

# Install code cov uploader and check the signature
# https://docs.codecov.com/docs/codecov-uploader
codecov_install: &codecov_install
Copy link
Contributor

@kokokuo kokokuo Aug 18, 2022

Choose a reason for hiding this comment

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

Great for adding the codecov for showing code coverage after each PR changed and tested 👍

Maybe you could rename the Install codecov to Upload the code coverage data to codecov to prevent confusion that you show the install codecov, but the command is to upload the code coverage.

NIT: If possible, maybe we could use circleci codecov orb which like GitHub Action, for making it simple

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great for adding the codecov for showing code coverage after each PR changed and tested 👍

Maybe you could rename the Install codecov to Upload the code coverage data to codecov to prevent confusion that you show the install codecov, but the command is to upload the code coverage.

The script here downloads the binary file from codecov and check the signature, It doesn't upload any data~ We upload data in the last step of test job: - run: ./codecov -t ${CODECOV_TOKEN}, I'll add some comment here.

NIT: If possible, maybe we could use circleci codecov orb which like GitHub Action, for making it simple

To use 3rd party orb we need to update our organization security policy, it might affect other projects of Canner, so I download the file manually.

https://app.circleci.com/pipelines/github/Canner/vulcan/53/workflows/eb92a347-0a49-4e3e-bb56-a097d77bbd53/jobs/76

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohoh, got it!
It my misunderstanding, thanks for the explanation, also thanks for telling me the reason why not use the 3rd party and provide tested link too 😺

name: Install codecov
command: |
if [ ! -f ./codecov ]; then
curl -Os https://uploader.codecov.io/v0.1.0_4653/linux/codecov
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import # One-time step
curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM
chmod +x codecov
fi

jobs:
install:
executor: node-executor
steps:
- checkout
- restore_cache:
<<: *yarn_cache
- run:
<<: *yarn_install
- save_cache:
key: node-deps-node16-{{ checksum "yarn.lock" }}
paths:
- ~/.cache
- node_modules
- restore_cache:
keys:
- codecov-0.1.0_4653
- run:
<<: *codecov_install
- save_cache:
key: codecov-0.1.0_4653
paths:
- ./codecov

lint:
executor: node-executor
steps:
- checkout
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- run: yarn nx workspace-lint
- run: yarn nx affected --target=lint --head=HEAD --maxWarnings=0 ${AFFECTED_ARGS}

test:
executor: node-executor
steps:
- checkout
- run:
<<: *set_env
- restore_cache:
<<: *yarn_cache
- restore_cache:
keys:
- codecov-0.1.0_4653
- run: yarn nx affected --target=test --head=HEAD --ci --coverage --maxWorkers=2 --coverageReporters=lcov ${AFFECTED_ARGS}
# --maxWorkers=2 is required because we'll run virtual machine with 32 cores CPU (with actually 4 CPI), jest spawns lots of workers if we don't fix the worker size.
# https://support.circleci.com/hc/en-us/articles/360005442714-Your-test-tools-are-smart-and-that-s-a-problem-Learn-about-when-optimization-goes-wrong-
- run: ./codecov -t ${CODECOV_TOKEN}

workflows:
version: 2
pr-check:
jobs:
- install
- lint:
requires:
- install
- test:
requires:
- install
8 changes: 6 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
],
"allowCircularSelfDependency": true
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why did we add the allowCircularSelfDependency, have our code happen the circular self-dependency, or just to add for preventing it happened in the future, or other reason ?

Copy link
Contributor Author

@oscar60310 oscar60310 Aug 18, 2022

Choose a reason for hiding this comment

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

NX linter blocks the relative imports from ourself if this value = false, e.g. "@vulcan-sql/core/model" from core package.
https://github.com/nrwl/nx/blob/master/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.ts#L184

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see, thanks for sharing the source code 🤣 and replying my question 👍

}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {}
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off"
}
},
{
"files": ["*.js", "*.jsx"],
Expand Down
9 changes: 1 addition & 8 deletions packages/build/src/lib/schema-parser/schemaParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ import {
import * as yaml from 'js-yaml';
import { RawAPISchema, SchemaParserMiddleware } from './middleware';
import * as compose from 'koa-compose';
import {
inject,
injectable,
interfaces,
multiInject,
optional,
} from 'inversify';
import { inject, injectable, multiInject, optional } from 'inversify';
import { TYPES } from '@vulcan-sql/build/containers';
import { SchemaParserOptions } from '@vulcan-sql/build/options';
export interface SchemaParseResult {
schemas: APISchema[];
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/containers/modules/templateEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
TemplateProvider,
} from '@vulcan-sql/core/models';
import {
InMemoryCodeLoader,
NunjucksCompiler,
Compiler,
TemplateEngine,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { promises as fs } from 'fs';
import {
ArtifactBuilderProviderType,
IArtifactBuilderOptions,
PersistentStore,
VulcanExtensionId,
VulcanInternalExtension,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
DataSource,
PreparedQueryParams,
Pagination,
BindParameters,
} from '@vulcan-sql/core/models';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/data-source/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
@VulcanInternalExtension()
@VulcanExtensionId('pg')
export class PGDataSource extends DataSource {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async execute(options: ExecuteOptions): Promise<DataResult> {
return {
getColumns: () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/template-engine/nunjucksCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class NunjucksCompiler implements Compiler {
} else if (extension instanceof FilterBuilder) {
this.compileTimeEnv.addFilter(
extension.filterName,
// eslint-disable-next-line @typescript-eslint/no-empty-function
() => {}, // We don't need to implement transform function in compile time
true
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/utils/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const mergedModules = async <T extends ModuleProperties>(
modules: Array<T>
) => {
const module = modules.reduce(
(merged: ModuleProperties, current: ModuleProperties, _) => {
(merged: ModuleProperties, current: ModuleProperties) => {
for (const extension of Object.keys(current)) {
// if current extension property has been existed in merged module, concat it.
if (extension in merged)
Expand Down
3 changes: 2 additions & 1 deletion packages/serve/src/lib/route/route-component/graphQLRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class GraphQLRoute extends BaseRoute {
return transformed;
}

protected async prepare(ctx: KoaRouterContext) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected async prepare(_ctx: KoaRouterContext) {
/**
* TODO: the graphql need to transform from body.
* Therefore, current request and pagination transformer not suitable (need to provide another graphql transform method or class)
Expand Down
4 changes: 2 additions & 2 deletions packages/serve/test/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Test vulcan server for practicing middleware', () => {
await app.buildRoutes([fakeSchema], [APIProviderType.RESTFUL]);
const server = http
.createServer(app.getHandler())
.listen(faker.internet.port());
.listen(faker.datatype.number({ min: 20000, max: 30000 }));

// arrange expected result
const expected = {
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('Test vulcan server for calling restful APIs', () => {
await app.buildRoutes([schema], [APIProviderType.RESTFUL]);
server = http
.createServer(app.getHandler())
.listen(faker.internet.port());
.listen(faker.datatype.number({ min: 20000, max: 30000 }));

// arrange input api url
const apiUrl = KoaRouter.url(schema.urlPath, ctx.params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Test cors middlewares', () => {
// use middleware in koa app
app.use(middleware.handle.bind(middleware));
// Act
server = app.listen(faker.internet.port());
server = app.listen(faker.datatype.number({ min: 20000, max: 30000 }));
});

afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Test rate limit middlewares', () => {
});
app.use(router.routes());
// Act
server = app.listen(faker.internet.port());
server = app.listen(faker.datatype.number({ min: 20000, max: 30000 }));
});

afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ import {
} from '@vulcan-sql/serve/response-formatter';

class HyperFormatter extends BaseResponseFormatter {
public format(): any {}
public format(): any {
return;
}

public toResponse() {}
public toResponse() {
return;
}
}

it.each([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { VulcanInternalExtension } from '@vulcan-sql/core';
import { BaseRouteMiddleware } from '@vulcan-sql/serve/models';
import { KoaRouterContext, KoaNext } from '@vulcan-sql/serve/route';

Expand Down
4 changes: 3 additions & 1 deletion packages/serve/test/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ it('Vulcan server should work with built artifacts', async () => {
});

// Act, Assert
await expect(server.start(faker.internet.port())).resolves.not.toThrow();
await expect(
server.start(faker.datatype.number({ min: 20000, max: 30000 }))
).resolves.not.toThrow();
});