Skip to content

Commit

Permalink
👷 refactor build, fix CD (#78)
Browse files Browse the repository at this point in the history
* 👷 refactor build, publish dry-run

* ci: install a 2nd time

* fix readme

* fix monorepo build

* clean build and packages

* run compiler with ts-node

* fix compile

* CI/CD: remove debug

* refactor async functions

* improve error message

* ⬆️ update as-types

Co-authored-by: Pierre Seznec <[email protected]>
  • Loading branch information
Thykof and peterjah authored Jan 5, 2023
1 parent 3fa3790 commit aa918e5
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 92 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:
- name: run test
run: |
npm ci
npm run build --workspace=packages/sc-compiler && npm ci # build and install sc-compiler
npm run build # build all packages
npm run build
npm run fmt:check
toolkit-tests:
Expand All @@ -43,7 +42,7 @@ jobs:
- name: install
run: |
npm ci
npm run build --workspace=packages/sc-compiler && npm ci # build and install sc-compiler
npm run build
- name: run toolkit init
run: npx toolkit init testDir
- name: run target tests
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/npm-publish-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
- name: publish
run: |
npm ci
npm run build --workspace=packages/sc-compiler && npm ci # build and install sc-compiler
npm run build # build all packages
npm run build
./scripts/publish-dev.sh
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
5 changes: 2 additions & 3 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
- name: publish
run: |
npm ci
npm run build --workspace=packages/sc-compiler && npm ci # build and install sc-compiler
npm run build # build all packages
npm run build
npm publish --ws --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ This repository is a monorepo for smart-contract development in AssemblyScript f
## Build

```bash
# Install npm dependencies and packages (massa-sc-toolkit)
# Install npm dependencies
npm install

# Build massa-sc-compiler
npm run build --workspace=packages/sc-compiler

# This will install built massa-sc-compiler binary
npm install

# Build other packages
# Build packages
npm run build
```

Expand Down
107 changes: 70 additions & 37 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
"packages/*"
],
"devDependencies": {
"@massalabs/as-types": "^1.1.1-dev",
"@massalabs/prettier-config-as": "^0.0.2",
"prettier": "^2.8.1",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1"
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"typescript": "^4.8.4"
}
}
4 changes: 1 addition & 3 deletions packages/sc-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"description": "",
"main": "dist/compiler.js",
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc && chmod +x dist/compiler.js",
"prettier": "prettier '**/src/**/*.ts' --check && as-prettier --check assembly",
"prettier:fix": "prettier '**/src/**/*.ts' --write && as-prettier --write assembly",
"lint": "",
Expand All @@ -20,7 +18,7 @@
"dist"
],
"bin": {
"compile": "dist/compiler.js"
"massa-as-compile": "src/compiler.ts"
},
"dependencies": {
"assemblyscript": "^0.25.2"
Expand Down
6 changes: 4 additions & 2 deletions packages/sc-compiler/src/compiler.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env ts-node
import { readdir, readFileSync } from 'fs';
import { join } from 'path';
import asc from 'assemblyscript/dist/asc.js';
Expand Down Expand Up @@ -50,4 +50,6 @@ export async function compileAll() {
);
}

await compileAll();
(async () => {
await compileAll();
})();
8 changes: 3 additions & 5 deletions packages/sc-deployer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"types": "dist/index.d.ts",
"scripts": {
"prebuild": "rimraf dist",
"build": "compile && tsc -d",
"build": "tsc -d",
"postbuild": "massa-as-compile",
"prettier": "prettier '**/src/**/*.ts' --check && as-prettier --check assembly",
"prettier:fix": "prettier '**/src/**/*.ts' --write && as-prettier --write assembly",
"lint": "",
Expand All @@ -22,10 +23,7 @@
"@massalabs/massa-sc-compiler": "0.0.1",
"@massalabs/massa-web3": "^1.12.0",
"@types/node": "^18.11.10",
"assemblyscript": "^0.25.1",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"typescript": "^4.8.4"
"assemblyscript": "^0.25.1"
},
"type": "module",
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Args } from '@massalabs/as-types';

/**
* This function is meant to be called only one time: when the contract is deployed.
*
*
* @param args - Arguments serialized with Args
*/
export function constructor(args: StaticArray<u8>): StaticArray<u8> {
Expand All @@ -18,7 +18,9 @@ export function constructor(args: StaticArray<u8>): StaticArray<u8> {
return [];
}
const argsDeser = new Args(args);
const name = argsDeser.nextString().unwrap();
const name = argsDeser
.nextString()
.expect('Name argument is missing or invalid');
generateEvent(`Constructor called with name ${name}`);
return [];
}
Expand Down
15 changes: 7 additions & 8 deletions packages/sc-project-initializer/commands/init/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sc-project-initializer/commands/init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "asp --summary",
"build": "compile",
"build": "massa-as-compile",
"deploy": "npm run build && ts-node src/deploy.ts",
"lint": "eslint --resolve-plugins-relative-to . \"./**/*.{ts,json}\" \"./*.{ts,json}\" --fix",
"prettier": "prettier '**/src/**/*.ts' --write && as-prettier --write assembly",
Expand All @@ -18,7 +18,7 @@
"@as-pect/cli": "^8.0.1",
"@assemblyscript/loader": "^0.25.0",
"@massalabs/as-transformer": "^0.1.1-dev",
"@massalabs/as-types": "^1.1.1-dev",
"@massalabs/as-types": "^0.0.2-dev",
"@massalabs/massa-as-sdk": "^2.0.1-dev",
"@massalabs/massa-sc-compiler": "0.0.1",
"@massalabs/massa-sc-deployer": "0.0.1",
Expand Down
34 changes: 19 additions & 15 deletions packages/sc-project-initializer/commands/init/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { Args } from '@massalabs/massa-web3';

dotenv.config();

if (!process.env.WALLET_PRIVATE_KEY || !process.env.JSON_RPC_URL_PUBLIC) {
const publicApi = process.env.JSON_RPC_URL_PUBLIC;

if (!process.env.WALLET_PRIVATE_KEY || !publicApi) {
throw new Error('Missing WALLET_PRIVATE_KEY in .env file');
}

Expand All @@ -19,17 +21,19 @@ const __filename = fileURLToPath(import.meta.url);

const __dirname = path.dirname(path.dirname(__filename));

await deploySC(
process.env.JSON_RPC_URL_PUBLIC,
deployerAccount,
[
{
data: readFileSync(path.join(__dirname, 'build', 'main.wasm')),
coins: 0,
args: new Args().addString('Test'),
} as ISCData,
],
0,
4_200_000_000,
true
);
(async () => {
await deploySC(
publicApi,
deployerAccount,
[
{
data: readFileSync(path.join(__dirname, 'build', 'main.wasm')),
coins: 0,
args: new Args().addString('Test'),
} as ISCData,
],
0,
4_200_000_000,
true,
);
})();

0 comments on commit aa918e5

Please sign in to comment.