Skip to content

Commit

Permalink
Add project build step in CI - placeholder in build script (#6193)
Browse files Browse the repository at this point in the history
* add scripts

* remove webpack-web-server to avoid node-gyp error

* fix lint errors

* add doc

---------

Co-authored-by: rotorsoft <[email protected]>
  • Loading branch information
Rotorsoft and rotorsoft authored Jan 4, 2024
1 parent 8efbd79 commit a5b8019
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 1,355 deletions.
55 changes: 14 additions & 41 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

- name: Cache browsers
id: playwright-cache
Expand Down Expand Up @@ -154,14 +148,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

- name: Cache browsers
id: playwright-cache
Expand Down Expand Up @@ -250,14 +238,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

- name: Cache browsers
id: playwright-cache
Expand Down Expand Up @@ -360,6 +342,9 @@ jobs:
exit 1
fi
- name: Build libs
run: yarn workspace @hicommonwealth/core build

- name: Run linter
env:
GITHUB_BASE_REF: ${{ github.base_ref }}
Expand All @@ -368,7 +353,7 @@ jobs:
- name: Commonwealth Typecheck
run: yarn --cwd packages/commonwealth check-types

- name: Dicsord-Bot Typecheck
- name: Discord-Bot Typecheck
run: yarn --cwd packages/discord-bot check-types

# These tests run quickly, so run them in a separate job
Expand Down Expand Up @@ -417,14 +402,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

- name: Run unit tests
run: yarn --cwd packages/commonwealth unit-test --forbid-only
Expand Down Expand Up @@ -501,14 +480,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

## EVM Section:
- name: Start EVM Testnet
Expand Down
12 changes: 11 additions & 1 deletion knowledge_base/Package-Scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ If you add a script to the package.json, you must add documentation here, descri

# Build Scripts

## build-project

Definition: `yarn global add node-gyp && yarn --ignore-engines && yarn workspace @hicommonwealth/core build && yarn workspace commonwealth migrate-db`

Description: Temporary placeholder for common script used by the CI pipeline to:

- Install dependencies
- Incrementally build project with references (tsc -b)
- Migrate DB

## build-all

Definition: `NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack/webpack.prod.config.js --progress && yarn build-consumer`
Expand Down Expand Up @@ -521,4 +531,4 @@ Description: Starts existing dormant Cosmos devnet containers.

Definition: `chmod u+x test/util/cosmos-chain-testing/v1/stop.sh && ./test/util/cosmos-chain-testing/v1/stop.sh && chmod u+x test/util/cosmos-chain-testing/v1beta1/stop.sh && ./test/util/cosmos-chain-testing/v1beta1/stop.sh && chmod u+x test/util/cosmos-chain-testing/ethermint/stop.sh && ./test/util/cosmos-chain-testing/ethermint/stop.sh`

Description: Stop all Cosmos devnet containers.
Description: Stop all Cosmos devnet containers.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"scripts": {
"build-project": "yarn global add node-gyp && yarn --ignore-engines && yarn workspace @hicommonwealth/core build && yarn workspace commonwealth migrate-db",
"start": "yarn --cwd packages/commonwealth start",
"build": "chmod u+x scripts/build.sh && ./scripts/build.sh",
"clean": "find . -name node_modules -exec rm -rf {} \\;; yarn --ignore-engines",
Expand All @@ -23,7 +24,7 @@
"lint-branch-warnings": "FAIL_WARNINGS=1 ./scripts/lint-branch.sh",
"stylelint": "stylelint packages/commonwealth/client/styles/*",
"chromatic": "chromatic --exit-zero-on-changes",
"prepare": "husky install & yarn workspace @hicommonwealth/core build",
"prepare": "husky install",
"watch-core": "tsc --watch --project libs/core/tsconfig.json",
"dev-server": "yarn workspace commonwealth start",
"dev": "concurrently -k -c 'auto' -n 'core,server' 'yarn watch-core' 'yarn dev-server'"
Expand Down
32 changes: 16 additions & 16 deletions packages/common-common/src/rabbitmq/mockRabbitMQController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RabbitMQControllerError } from './rabbitMQController';
import type * as Rascal from 'rascal';
import { RabbitMQControllerError } from './rabbitMQController';
import type {
RascalPublications,
RascalSubscriptions,
Expand All @@ -24,7 +24,7 @@ export class MockRabbitMQController extends AbstractRabbitMQController {
public async init(): Promise<void> {
if (this._initialized === true) {
throw new RabbitMQControllerError(
'RabbitMQController is already initialized!'
'RabbitMQController is already initialized!',
);
}

Expand All @@ -49,27 +49,27 @@ export class MockRabbitMQController extends AbstractRabbitMQController {
public async startSubscription(
messageProcessor: (data: TRmqMessages, ...args: any) => Promise<void>,
subscriptionName: RascalSubscriptions,
msgProcessorContext?: { [key: string]: any }
msgProcessorContext?: { [key: string]: any },
): Promise<any> {
if (!this._initialized) {
throw new RabbitMQControllerError(
'RabbitMQController is not initialized!'
'RabbitMQController is not initialized!',
);
}

// process existing messages
await this.runMessageProcessor(
messageProcessor,
this._queuedMessages[subscriptionName],
msgProcessorContext
msgProcessorContext,
);

const checkQueues = async () => {
if (this._queuedMessages[subscriptionName].length > 0) {
await this.runMessageProcessor(
messageProcessor,
this._queuedMessages[subscriptionName],
msgProcessorContext
msgProcessorContext,
);
}
};
Expand All @@ -88,11 +88,11 @@ export class MockRabbitMQController extends AbstractRabbitMQController {

public async publish(
data: TRmqMessages,
publisherName: RascalPublications
publisherName: RascalPublications,
): Promise<any> {
if (!this._initialized) {
throw new RabbitMQControllerError(
'RabbitMQController is not initialized!'
'RabbitMQController is not initialized!',
);
}
const subscription = this.routeMessage(publisherName);
Expand All @@ -104,7 +104,7 @@ export class MockRabbitMQController extends AbstractRabbitMQController {
publishData: TRmqMessages,
objectId: number | string,
publication: RascalPublications,
DB?: any
// DB?: any,
) {
await this.publish(publishData, publication);
}
Expand All @@ -130,12 +130,12 @@ export class MockRabbitMQController extends AbstractRabbitMQController {
const { exchange, routingKey } = config.publications[publication];
const queue = Object.values(config.bindings).find(
(binding) =>
binding.source === exchange && binding.bindingKey === routingKey
binding.source === exchange && binding.bindingKey === routingKey,
).destination;

if (!queue) {
throw new Error(
'Routing Failed: Could not find a queue that matches the given publication'
'Routing Failed: Could not find a queue that matches the given publication',
);
}

Expand All @@ -144,22 +144,22 @@ export class MockRabbitMQController extends AbstractRabbitMQController {
}

throw new Error(
'Routing Failed: Could not find a subscription that matches the given publication'
'Routing Failed: Could not find a subscription that matches the given publication',
);
}

private async runMessageProcessor(
messageProcessor: (data: TRmqMessages, ...args: any) => Promise<void>,
messages: any[],
msgProcessorContext?: { [key: string]: any }
msgProcessorContext?: { [key: string]: any },
) {
const numMessages = messages.length;
for (let i = 0; i < numMessages; i++) {
const message = messages.shift();
try {
await messageProcessor.call(
{ rmqController: this, ...msgProcessorContext },
message
message,
);
} catch (e) {
const errorMsg = `
Expand All @@ -170,11 +170,11 @@ export class MockRabbitMQController extends AbstractRabbitMQController {
// message to avoid re-queuing the message multiple times
if (e instanceof RmqMsgFormatError) {
throw new Error(
`Negative Acknowledgement: Invalid Message Format Error - ${errorMsg}`
`Negative Acknowledgement: Invalid Message Format Error - ${errorMsg}`,
);
} else {
throw new Error(
`Negative Acknowledgement: Unknown Error - Message would be re-queued in production`
`Negative Acknowledgement: Unknown Error - Message would be re-queued in production`,
);
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/commonwealth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@
"webpack-cli": "^4.10.0",
"webpack-deduplication-plugin": "^0.0.8",
"webpack-dev-middleware": "^5.3.3",
"webpack-dev-server": "^3.1.14",
"webpack-hot-middleware": "^2.25.2",
"webpack-merge": "^5.8.0"
},
Expand Down
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# build libs (use tsc -b once project references are enabled)
yarn workspace @hicommonwealth/core build

if [ "$CW_BUILD" = true ]; then
yarn --cwd packages/commonwealth build-all
elif [ "$SL_BUILD" = true ]; then
Expand Down
Loading

0 comments on commit a5b8019

Please sign in to comment.