Skip to content

Commit

Permalink
Merge pull request #751 from rainlanguage/2024-08-03-npm-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
hardyjosh authored Aug 5, 2024
2 parents 0f0ac7b + 6a75be5 commit dee5639
Show file tree
Hide file tree
Showing 17 changed files with 6,874 additions and 8 deletions.
27 changes: 27 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
/crates
/.vscode
/.github
/cache
/lib
/meta
/out
/script
/subgraph
/src
/tauri-app
/test
target

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
package.json
yarn.lock
35 changes: 35 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @type { import("eslint").Linter.Config } */
module.exports = {
root: true,
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
extraFileExtensions: [".ts"],
},
env: {
browser: true,
es2017: true,
node: true,
commonjs: true,
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
"no-trailing-spaces": "error",
"no-undef": "off",
"no-cond-assign": "off",
"no-empty-function": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
},
};
107 changes: 107 additions & 0 deletions .github/workflows/manual-package-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Manual Packages Release
on:
workflow_dispatch:
inputs:
version-level:
description: 'Select Version Level'
required: true
type: choice
options:
- alpha # Increase the alpha pre-version (x.y.z-alpha.M)
- beta # Increase the beta pre-version (x.y.z-beta.M)
- patch # Increase the patch version (x.y.z)
- minor # Increase the minor version (x.y.0)
- major # Increase the major version (x.0.0)
- release # Remove the pre-version, ie remove alpha/beta/rc (x.y.z)
- rc # Increase the rc pre-version (x.y.z-rc.M)

jobs:
release:
runs-on: ubuntu-latest
outputs:
version: ${{ env.NEW_VERSION }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
ssh-key: ${{ secrets.PUBLISH_PRIVATE_KEY }}

- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2

- name: Install NodeJS v22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'

- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-sol-prelude
- run: nix develop -c rainix-rs-prelude
- run: nix develop -c raindex-prelude

- name: Test JS/TS Binding
run: nix develop -c test-js-bindings

- name: Git Config
run: |
git config --global user.email "${{ secrets.CI_GIT_EMAIL }}"
git config --global user.name "${{ secrets.CI_GIT_USER }}"
- name: Publish to crates.io
run: nix develop -c cargo release --no-confirm --execute --no-tag --workspace ${{ inputs.version-level }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

# set npm version to rust crate version
- name: Set Version
run: echo "NEW_VERSION=$(nix develop -c npm version $(node ./scripts/version.js) --no-git-tag-version)" >> $GITHUB_ENV

# Commit changes and tag
- name: Commit And Tag
run: |
git add "package.json"
git add "package-lock.json"
git commit -m "Release ${{ env.NEW_VERSION }}"
git tag ${{ env.NEW_VERSION }}
# Push the commit to remote
- name: Push Changes To Remote
run: |
git push origin
git push -u origin ${{ env.NEW_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Create npm package tarball to put in release files
- name: Create NPM Package Tarball
run: echo "NPM_PACKAGE=$(nix develop -c npm pack --silent)" >> $GITHUB_ENV

- name: Rename NPM Package Tarball
run: mv ${{ env.NPM_PACKAGE }} orderbook_npm_package_${{ env.NEW_VERSION }}.tgz

# publish to npm
- name: Publish To NPM
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
access: public

# Create gitHub release with npm tarball
- name: Create GitHub Release
id: gh_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.NEW_VERSION }}
name: Release ${{ env.NEW_VERSION }}
files: orderbook_npm_package_${{ env.NEW_VERSION }}.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .github/workflows/rainix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
# Wasm target doesnt need to run on multiple platforms
- os: ubuntu-latest
task: rainix-wasm-artifacts
# Testing JS/TS bindings doesnt need to run on multiple platforms
- os: ubuntu-latest
task: test-js-bindings
fail-fast: false
runs-on: ${{ matrix.os }}
env:
Expand Down
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ target
.DS_Store
.env
subgraph/tests/.docker
subgraph/tests/.latest.json
subgraph/tests/.latest.json
node_modules
temp
dist
/cjs.js
/cjs.d.ts
/esm.js
/esm.d.ts
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/common/src/js_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum Error {

impl From<Error> for JsValue {
fn from(value: Error) -> Self {
serde_wasm_bindgen::to_value(&value.to_string()).unwrap_or(JsValue::NULL)
JsError::new(&value.to_string()).into()
}
}

Expand Down
29 changes: 29 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,42 @@
'';
};

js-install = rainix.mkTask.${system} {
name = "js-install";
body = ''
set -euxo pipefail
npm install --no-check
'';
};

build-js-bindings = rainix.mkTask.${system} {
name = "build-js-bindings";
body = ''
set -euxo pipefail
npm run build
'';
};

test-js-bindings = rainix.mkTask.${system} {
name = "test-js-bindings";
body = ''
set -euxo pipefail
npm install --no-check
npm run build
npm test
'';
};

} // rainix.packages.${system};

devShells.default = pkgs.mkShell {
packages = [
packages.raindex-prelude
packages.ob-rs-test
packages.rainix-wasm-artifacts
packages.js-install
packages.build-js-bindings
packages.test-js-bindings
rain.defaultPackage.${system}
];

Expand Down
Loading

0 comments on commit dee5639

Please sign in to comment.