diff --git a/.github/actions/nix/action.yml b/.github/actions/nix/action.yml new file mode 100644 index 00000000000..9f008ad0f9d --- /dev/null +++ b/.github/actions/nix/action.yml @@ -0,0 +1,27 @@ +name: Setup Nix +description: Installs and setups Nix components + +inputs: + github-token: + description: 'Github Access Token' + required: true + nix-cache-name: + description: 'Name of the Cachix cache to use' + required: true + cachix-auth-token: + description: 'Cachix Auth Token' + required: true + + +runs: + using: composite + steps: + - uses: cachix/install-nix-action@v22 + with: + nix_path: nixpkgs=channel:nixos-23.05 + github_access_token: ${{ inputs.github-token }} + + - uses: cachix/cachix-action@v12 + with: + name: ${{ inputs.nix-cache-name }} + authToken: ${{ inputs.cachix-auth-token }} diff --git a/.github/workflows/publish-es-packages.yml b/.github/workflows/publish-es-packages.yml new file mode 100644 index 00000000000..7eec3939f8d --- /dev/null +++ b/.github/workflows/publish-es-packages.yml @@ -0,0 +1,82 @@ +name: Publish Noir ES Packages + +on: + workflow_dispatch: + +jobs: + build-noir_wasm: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Setup Nix + uses: ./.github/actions/nix + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + nix-cache-name: ${{ vars.NIX_CACHE_NAME }} + cachix-auth-token: ${{ secrets.CACHIXAUTHTOKEN }} + + - name: Build wasm package + run: | + nix build -L .#noir_wasm + + build-noirc_abi_wasm: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Setup Nix + uses: ./.github/actions/nix + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + nix-cache-name: ${{ vars.NIX_CACHE_NAME }} + cachix-auth-token: ${{ secrets.CACHIXAUTHTOKEN }} + + - name: Build wasm package + run: | + nix build -L .#noirc_abi_wasm + + build-acvm_js: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Setup Nix + uses: ./.github/actions/nix + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + nix-cache-name: ${{ vars.NIX_CACHE_NAME }} + cachix-auth-token: ${{ secrets.CACHIXAUTHTOKEN }} + + - name: Build wasm package + run: | + nix build -L .#acvm_js + + publish-es-packages: + runs-on: ubuntu-latest + needs: [build-acvm_js, build-noirc_abi_wasm, build-noir_wasm] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Setup Nix + uses: ./.github/actions/nix + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + nix-cache-name: ${{ vars.NIX_CACHE_NAME }} + cachix-auth-token: ${{ secrets.CACHIXAUTHTOKEN }} + + - name: Install Yarn dependencies + run: yarn install + + - name: Build ES Packages + run: yarn prepare:publish + + - name: Authenticate with npm + run: "echo npmAuthToken: ${{ secrets.NPM_TOKEN }} > ~/.yarnrc.yml" + + - name: Publish ES Packages + run: yarn publish:all --access public \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5a1aba712f2..b579061779f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,8 +65,8 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} inputs: '{ "tag": "${{ needs.release-please.outputs.tag-name }}", "publish": true }' - publish-wasm: - name: Publish noir_wasm package + publish-es-packages: + name: Publish ES packages needs: [release-please] if: ${{ needs.release-please.outputs.tag-name }} runs-on: ubuntu-latest @@ -74,72 +74,6 @@ jobs: - name: Dispatch to noir_wasm uses: benc-uk/workflow-dispatch@v1 with: - workflow: publish-noir-wasm.yml + workflow: publish-es-packages.yml ref: master token: ${{ secrets.NOIR_REPO_TOKEN }} - - publish-noir-js: - name: Publish noir_js package - needs: [release-please] - if: ${{ needs.release-please.outputs.tag-name }} - runs-on: ubuntu-latest - steps: - - name: Dispatch to noir_wasm - uses: benc-uk/workflow-dispatch@v1 - with: - workflow: publish-noir-js.yml - ref: master - token: ${{ secrets.NOIR_REPO_TOKEN }} - - publish-source-resolver: - name: Publish source resolver package - needs: [release-please] - if: ${{ needs.release-please.outputs.tag-name }} - runs-on: ubuntu-latest - steps: - - name: Dispatch to source resolver - uses: benc-uk/workflow-dispatch@v1 - with: - workflow: publish-source-resolver.yml - ref: master - token: ${{ secrets.NOIR_REPO_TOKEN }} - - publish-abi-wasm: - name: Dispatch to publish-abi_wasm workflow - needs: [release-please] - if: ${{ needs.release-please.outputs.tag-name }} - runs-on: ubuntu-latest - steps: - - name: Trigger publish-abi_wasm.yml workflow - uses: benc-uk/workflow-dispatch@v1 - with: - workflow: publish-abi_wasm.yml - repo: ${{ github.repository }} - token: ${{ secrets.GITHUB_TOKEN }} - inputs: '{ "noir-ref": "${{ needs.release-please.outputs.tag-name }}" }' - - publish-acvm: - name: Publish crates - needs: [release-please] - if: ${{ needs.release-please.outputs.tag-name }} - runs-on: ubuntu-latest - steps: - - name: Dispatch to publish workflow - uses: benc-uk/workflow-dispatch@v1 - with: - workflow: publish-acvm.yml - ref: master - inputs: '{ "acvm-ref": "${{ needs.release-please.outputs.tag-name }}" }' - - publish-acvm-js: - name: Dispatch to publish-acvm-js workflow - needs: [release-please] - if: ${{ needs.release-please.outputs.tag-name }} - runs-on: ubuntu-latest - steps: - - name: Trigger publish-acvm-js.yml workflow - uses: benc-uk/workflow-dispatch@v1 - with: - workflow: publish-acvm-js.yml - ref: master - inputs: '{ "acvm-ref": "${{ needs.release-please.outputs.tag-name }}" }' diff --git a/acvm-repo/acvm_js/package.json b/acvm-repo/acvm_js/package.json index 2ec8e8333a8..f7d2bf08a1a 100644 --- a/acvm-repo/acvm_js/package.json +++ b/acvm-repo/acvm_js/package.json @@ -27,7 +27,8 @@ "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha", "test:browser": "web-test-runner", "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0", - "clean": "chmod u+w web nodejs && rm -rf web nodejs" + "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", + "clean": "chmod u+w web nodejs || true && rm -rf web nodejs" }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", diff --git a/compiler/source-resolver/package.json b/compiler/source-resolver/package.json index a198914849c..2e44246beab 100644 --- a/compiler/source-resolver/package.json +++ b/compiler/source-resolver/package.json @@ -24,6 +24,7 @@ "test": "ava", "generate-types": "tsc src/*.ts --declaration --emitDeclarationOnly --outDir types", "clean": "rm -rf ./lib ./lib-node", + "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "devDependencies": { diff --git a/compiler/wasm/package.json b/compiler/wasm/package.json index e56a43c331e..4bc4ddc8288 100644 --- a/compiler/wasm/package.json +++ b/compiler/wasm/package.json @@ -23,7 +23,8 @@ "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha", "test:node": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha", "test:browser": "web-test-runner", - "clean": "chmod u+w web nodejs && rm -rf ./nodejs ./web ./target ./result", + "clean": "chmod u+w web nodejs || true && rm -rf ./nodejs ./web ./target ./result", + "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "peerDependencies": { diff --git a/flake.nix b/flake.nix index 0a9bf65322d..4334cb8a3f0 100644 --- a/flake.nix +++ b/flake.nix @@ -81,7 +81,7 @@ # Custom filter with various file extensions that we rely upon to build packages # Currently: `.nr`, `.sol`, `.sh`, `.json`, `.md` filter = path: type: - (builtins.match ".*\.(nr|sol|sh|json|md)$" path != null) || (craneLib.filterCargoSources path type); + (builtins.match ".*\.(sh|json|md)$" path != null) || (craneLib.filterCargoSources path type); }; # TODO(#1198): It'd be nice to include these flags when running `cargo clippy` in a devShell. diff --git a/package.json b/package.json index b80ea662798..e8985ff4088 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,17 @@ "clean": "yarn clean:workspaces && yarn clean:root", "lint": "yarn workspaces foreach --verbose run lint", "build:with:nix": "nix build -L .#all_wasm", - "install:from:nix:noirc_abi_wasm": "cp -r ./result/noirc_abi_wasm/nodejs ./tooling/noirc_abi_wasm && cp -r ./result/noirc_abi_wasm/web ./tooling/noirc_abi_wasm", - "install:from:nix:noir_wasm": "cp -r ./result/noir_wasm/nodejs ./compiler/wasm && cp -r ./result/noir_wasm/web ./compiler/wasm", - "install:from:nix:acvm_js": "cp -rf ./result/acvm_js/nodejs ./acvm-repo/acvm_js && cp -rf ./result/acvm_js/web ./acvm-repo/acvm_js", - "install:from:nix": "yarn build:with:nix && yarn install:from:nix:noirc_abi_wasm && yarn install:from:nix:noir_wasm && yarn install:from:nix:acvm_js" + "install:from:nix:noirc_abi_wasm": "cp -rL ./result/noirc_abi_wasm/nodejs ./tooling/noirc_abi_wasm && cp -rL ./result/noirc_abi_wasm/web ./tooling/noirc_abi_wasm", + "install:from:nix:noir_wasm": "cp -rL ./result/noir_wasm/nodejs ./compiler/wasm && cp -rL ./result/noir_wasm/web ./compiler/wasm", + "install:from:nix:acvm_js": "cp -rL ./result/acvm_js/nodejs ./acvm-repo/acvm_js && cp -rL ./result/acvm_js/web ./acvm-repo/acvm_js", + "install:from:nix": "yarn build:with:nix && yarn install:from:nix:noirc_abi_wasm && yarn install:from:nix:noir_wasm && yarn install:from:nix:acvm_js", + "build:types": "yarn workspace @noir-lang/types run build", + "build:source-resolver": "yarn workspace @noir-lang/source-resolver run build", + "build:backend_barretenberg": "yarn workspace @noir-lang/backend_barretenberg run build", + "build:noir_js": "yarn workspace @noir-lang/noir_js run build", + "build:js:only": "yarn build:types && yarn build:source-resolver && yarn build:backend_barretenberg && yarn build:noir_js", + "prepare:publish": "yarn clean && yarn install:from:nix && yarn build:js:only", + "publish:all": "yarn install && yarn workspaces foreach run publish" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^6.7.3", @@ -38,7 +45,7 @@ "ts-node": "^10.9.1", "typescript": "^5.0.4" }, - "packageManager": "yarn@3.6.3", + "packageManager": "yarn@3.6.4", "dependencies": { "tslog": "^4.9.2" } diff --git a/tooling/noir_js/package.json b/tooling/noir_js/package.json index 9063d013599..2bd7570830a 100644 --- a/tooling/noir_js/package.json +++ b/tooling/noir_js/package.json @@ -35,6 +35,7 @@ "prettier": "prettier 'src/**/*.ts'", "prettier:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts'", "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0", + "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", "clean": "rm -rf ./lib" }, "devDependencies": { diff --git a/tooling/noir_js_backend_barretenberg/fixup.sh b/tooling/noir_js_backend_barretenberg/fixup.sh index 7749034d5ca..80bd7ec71a5 100755 --- a/tooling/noir_js_backend_barretenberg/fixup.sh +++ b/tooling/noir_js_backend_barretenberg/fixup.sh @@ -1,15 +1,18 @@ +#!/usr/bin/env bash + # Put these package.json files in the cjs and # mjs directory respectively, so that -# tools can recognise that the .js files are either +# tools can recognise that the .js files are either # commonjs or ESM files. -cat >lib/cjs/package.json <lib/esm/package.json < $self_path/lib/cjs/package.json +echo "$esm_package" > $self_path/lib/esm/package.json \ No newline at end of file diff --git a/tooling/noir_js_backend_barretenberg/package.json b/tooling/noir_js_backend_barretenberg/package.json index f34b5c56b0c..4bac7cb4ccd 100644 --- a/tooling/noir_js_backend_barretenberg/package.json +++ b/tooling/noir_js_backend_barretenberg/package.json @@ -16,12 +16,18 @@ "default": "./lib/esm/index.js" }, "types": "lib/esm/index.d.ts", + "files": [ + "lib", + "package.json" + ], "scripts": { "dev": "tsc --watch", - "build": "yarn clean && tsc && tsc -p ./tsconfig.cjs.json && ./fixup.sh", + "generate:package": "bash ./fixup.sh", + "build": "yarn clean && tsc && tsc -p ./tsconfig.cjs.json && yarn generate:package", "clean": "rm -rf ./lib", "prettier": "prettier 'src/**/*.ts'", "prettier:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts'", + "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "dependencies": { diff --git a/tooling/noir_js_types/package.json b/tooling/noir_js_types/package.json index 179f71e2196..73bab16d92e 100644 --- a/tooling/noir_js_types/package.json +++ b/tooling/noir_js_types/package.json @@ -17,6 +17,7 @@ "build:esm": "tsc", "build:cjs": "tsc --module CommonJS --outDir lib/cjs", "build": "yarn run build:cjs && yarn run build:esm", + "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "exports": { diff --git a/tooling/noirc_abi_wasm/package.json b/tooling/noirc_abi_wasm/package.json index 488c29b243d..584539ddbe4 100644 --- a/tooling/noirc_abi_wasm/package.json +++ b/tooling/noirc_abi_wasm/package.json @@ -25,7 +25,8 @@ "build": "bash ./build.sh", "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha", "test:browser": "web-test-runner", - "clean": "chmod u+w web nodejs && rm -rf ./nodejs ./web ./target ./result", + "clean": "chmod u+w web nodejs || true && rm -rf ./nodejs ./web ./target ./result", + "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "devDependencies": {