diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..850601e --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,15 @@ +{ + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], + "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + "env": { + "node": true, + "jest": true + }, + "rules": { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], + "@typescript-eslint/no-var-requires": "off", + "no-constant-condition": "warn" + } +} diff --git a/.github/workflows/lint-test-build.yml b/.github/workflows/lint-test-build.yml new file mode 100644 index 0000000..e130c0a --- /dev/null +++ b/.github/workflows/lint-test-build.yml @@ -0,0 +1,29 @@ +name: Lint, Test, and Build + +on: + release: + types: [created] + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20] + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm install + - name: Lint + run: npm run lint + - name: Test + run: npm run test + - name: Build + run: npm run build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f0b06c6..28b304b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,7 +1,4 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages - -name: Publish Mesh SDK Contract +name: Publish Package on: pull_request: @@ -13,6 +10,7 @@ on: jobs: build: runs-on: ubuntu-latest + if: github.event.pull_request.merged == true strategy: matrix: node-version: [20] @@ -20,6 +18,8 @@ jobs: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} - name: Install dependencies run: npm install - name: Lint @@ -29,6 +29,7 @@ jobs: check-version: runs-on: ubuntu-latest + needs: [build] if: github.event.pull_request.merged == true outputs: version-updated: ${{ steps.compare-versions.outputs.version-updated }} @@ -38,7 +39,7 @@ jobs: with: ref: ${{ github.event.pull_request.base.sha }} - - name: Get package version from main branch before merge + - name: Get version before merge id: pre-merge-version run: | PRE_MERGE_VERSION=$(node -p "require('./package.json').version") @@ -47,9 +48,9 @@ jobs: - name: Checkout main branch at commit after merge uses: actions/checkout@v4 with: - ref: "main" + ref: main - - name: Get package version from main branch after merge + - name: Get version after merge id: post-merge-version run: | POST_MERGE_VERSION=$(node -p "require('./package.json').version") @@ -64,7 +65,7 @@ jobs: echo "version-updated=false" >> "$GITHUB_OUTPUT" fi - publish-meshsdk-contract: + publish: needs: [build, check-version] if: needs.check-version.outputs.version-updated == 'true' runs-on: ubuntu-latest @@ -74,7 +75,8 @@ jobs: with: node-version: 20 registry-url: https://registry.npmjs.org/ - - run: npm install && npm run build + - run: npm install + - run: npm run build - run: npm publish --access public env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} + NODE_AUTH_TOKEN: ${{ secrets.npm_token }} diff --git a/jest.config.ts b/jest.config.ts index 9229656..a37d449 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -4,7 +4,7 @@ const jestConfig: Config = { clearMocks: true, maxWorkers: 1, testEnvironment: "node", - testMatch: ["**/packages/**/*.test.ts"], + testMatch: ["**/src/**/*.test.ts"], setupFiles: ["dotenv/config"], preset: "ts-jest", moduleNameMapper: { diff --git a/package.json b/package.json index 006aed8..7dd5129 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@meshsdk/contract", - "version": "1.9.0-beta.87", + "version": "1.9.0-beta.103", "description": "List of open-source smart contracts, complete with documentation, live demos, and end-to-end source code. https://meshjs.dev/smart-contracts", "main": "./dist/index.cjs", "browser": "./dist/index.js", @@ -28,7 +28,14 @@ "test": "jest" }, "devDependencies": { + "@types/jest": "^29.5.12", + "@typescript-eslint/eslint-plugin": "^7.1.0", + "@typescript-eslint/parser": "^7.1.0", + "dotenv": "^16.4.5", "eslint": "^8.57.0", + "jest": "^29.7.0", + "ts-jest": "^29.1.2", + "ts-node": "^10.9.2", "tsup": "^8.0.2", "typescript": "^5.3.3" },