Skip to content

Commit

Permalink
feat(ts): implements testing and release
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Apr 10, 2024
1 parent d27ac62 commit b49d468
Show file tree
Hide file tree
Showing 22 changed files with 9,647 additions and 2,652 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ AKASH_DEVCACHE_NODE_MODULES=${AKASH_DEVCACHE}
AKASH_DEVCACHE_NODE_BIN=${AKASH_DEVCACHE_NODE_MODULES}/node_modules/.bin
AKASH_TS_ROOT=${AKASH_ROOT}/ts
AKASH_TS_PACKAGE_FILE=${AKASH_TS_ROOT}/package.json
AKASH_TS_NODE_BIN=${AKASH_TS_ROOT}/node_modules/.bin
AKASH_TS_NODE_MODULES=${AKASH_TS_ROOT}/node_modules
AKASH_TS_NODE_BIN=${AKASH_TS_NODE_MODULES}/.bin
13 changes: 11 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: go mod vendor
run: make modvendor
- name: lint
run: make lint-proto
run: make lint-go
proto:
runs-on: ubuntu-latest
timeout-minutes: 5
Expand All @@ -42,4 +42,13 @@ jobs:
- name: go mod vendor
run: make modvendor
- name: lint-go
run: make lint-go
run: make lint-proto
ts:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Setup env
uses: HatsuneMiku3939/direnv-action@v1
- name: lint-ts
run: make lint-ts
65 changes: 65 additions & 0 deletions .github/workflows/release-ts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release TypeScript NPM Package
on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check for changes
uses: dorny/paths-filter@v2
id: changes
with:
filters: |
ts:
- 'ts/**'
- name: Setup Node.js
if: steps.changes.outputs.ts == 'true'
uses: actions/setup-node@v4
with:
node-version: 20.8.1
cache: npm
cache-dependency-path: ts/package-lock.json

- name: Restore node_modules cache
id: deps-cache
if: steps.changes.outputs.ts == 'true' && steps.deps-cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/restore@v3
with:
path: ts/node_modules
key: ${{ runner.os }}-build-ts-deps-cache-${{ hashFiles('ts/package-lock.json') }}

- name: Setup env
if: steps.changes.outputs.ts == 'true'
uses: HatsuneMiku3939/direnv-action@v1

- name: Run tests
if: steps.changes.outputs.ts == 'true'
run: SUB_TESTS=ts make test

- name: Publish npm package
if: steps.changes.outputs.ts == 'true'
env:
GITHUB_TOKEN: ${{ secrets.AUTH_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: make release-ts

- name: Upload Test Coverage
uses: codecov/codecov-action@v4
with:
files: ./ts/coverage
token: ${{ secrets.CODECOV_TOKEN }}

- name: Cache node modules
if: steps.deps-cache.outputs.cache-hit != 'true' && steps.changes.outputs.ts == 'true'
uses: martijnhols/actions-cache/save@v3
with:
path: ts/node_modules
key: ${{ runner.os }}-build-ts-deps-cache-${{ hashFiles('ts/package-lock.json') }}

13 changes: 11 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: "${{ env.GOVERSION }}"
- run: TEST_RACE=1 make test
- run: SUB_TESTS=go TEST_RACE=1 make test
coverage:
runs-on: ubuntu-latest
steps:
Expand All @@ -34,4 +34,13 @@ jobs:
with:
go-version: "${{ env.GOVERSION }}"
- run: make test-coverage
- uses: codecov/codecov-action@v3
- name: Upload GO Test Coverage
uses: codecov/codecov-action@v4
with:
files: ./coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload TS Test Coverage
uses: codecov/codecov-action@v4
with:
files: ./ts/coverage
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ include $(AKASH_ROOT)/make/mod.mk
include $(AKASH_ROOT)/make/test.mk
include $(AKASH_ROOT)/make/codegen.mk
include $(AKASH_ROOT)/make/lint.mk
include $(AKASH_ROOT)/make/release-ts.mk

.PHONY: clean
clean:
Expand Down
24 changes: 24 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ignore:
- "**/*.pb.go"
- "**/*.pb.gw.go"
- "**/mocks/.*"
- "pkg"
comment: false
codecov:
require_ci_to_pass: true
parsers:
gcov:
branch_detection:
loop: yes
macro: no
method: no
conditional: yes
coverage:
range: 40..100
round: down
precision: 2
status:
project:
default:
if_not_found: success
if_ci_failed: error
2 changes: 1 addition & 1 deletion make/codegen.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: proto-gen
ifeq ($(PROTO_LEGACY), true)
proto-gen: modvendor $(PROTOC) $(PROTOC_GEN_GOCOSMOS) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_DOC) $(AKASH_TS_PACKAGE_FILE) clean-codegen
proto-gen: modvendor $(PROTOC) $(PROTOC_GEN_GOCOSMOS) $(PROTOC_GEN_GRPC_GATEWAY) $(PROTOC_GEN_DOC) $(AKASH_TS_NODE_MODULES) clean-codegen
mkdir -p $(AKASH_TS_ROOT)/src/generated
./script/protocgen-legacy.sh
else
Expand Down
11 changes: 8 additions & 3 deletions make/lint.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
LINT ?= go \
SUB_LINT ?= go \
proto \
shell
shell \
ts

BUF_LINT_PACKAGES ?= provider \
node
Expand Down Expand Up @@ -29,7 +30,7 @@ lint-shell:
-x /shellcheck/script/shellcheck.sh

.PHONY: lint
lint: $(patsubst %, lint-%,$(LINT))
lint: $(patsubst %, lint-%,$(SUB_LINT))

.PHONY: check-breaking
proto-check-breaking: $(BUF)
Expand All @@ -38,3 +39,7 @@ proto-check-breaking: $(BUF)
.PHONY: format
proto-format:
$(DOCKER_CLANG) find ./ ! -path "./vendor/*" -name *.proto -exec clang-format -i {} \;

.PHONY: lint-ts
lint-ts: $(AKASH_TS_NODE_MODULES)
cd ts && npm run lint;
11 changes: 11 additions & 0 deletions make/release-ts.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: release-ts

release-ts: $(AKASH_TS_NODE_MODULES) $(AKASH_TS_ROOT)/dist
if [ -z "$$CI" ]; then \
cd $(AKASH_TS_ROOT) && npx semantic-release --no-ci; \
else \
cd $(AKASH_TS_ROOT) && npx semantic-release; \
fi

$(AKASH_TS_ROOT)/dist: $(shell find $(AKASH_TS_ROOT)/src -type f)
cd $(AKASH_TS_ROOT) && npm run build
2 changes: 1 addition & 1 deletion make/setup-cache.mk
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ else
@echo "swagger-combine already installed; skipping..."
endif

$(AKASH_TS_PACKAGE_FILE): $(AKASH_DEVCACHE)
$(AKASH_TS_NODE_MODULES): $(AKASH_TS_PACKAGE_FILE)
@echo "installing node modules..."
cd $(AKASH_TS_ROOT) && npm install
@echo "node modules installed."
26 changes: 21 additions & 5 deletions make/test.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
TEST_MODULE ?= ./...
SUB_TESTS ?= go \
ts

COVER_PACKAGES = $(shell go list ./... | grep -v mock | paste -sd, -)

Expand All @@ -22,16 +24,30 @@ test_flags += -v
endif

.PHONY: test
test:
$(GO) test $(test_flags) $(TEST_MODULE)
test: $(patsubst %, test-%,$(SUB_TESTS))

.PHONY: test-coverage
test-coverage:
test-coverage: $(patsubst %, test-coverage-%,$(SUB_TESTS))

.PHONY: test-ts
test-ts: $(AKASH_TS_NODE_MODULES)
cd ts && npm run test

.PHONY: test-coverage-ts
test-coverage-ts: $(AKASH_TS_NODE_MODULES)
cd ts && npm run test:cov

.PHONY: test-go
test-go:
$(GO) test $(test_flags) $(TEST_MODULE)

.PHONY: test-coverage-go
test-coverage-go:
$(GO) test -coverprofile=coverage.txt \
-covermode=count \
-coverpkg="$(COVER_PACKAGES)" \
$(TEST_MODULE)

.PHONY: test-vet
test-vet:
.PHONY: test-go-vet
test-go-vet:
$(GO) vet $(TEST_MODULE)
10 changes: 9 additions & 1 deletion ts/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@
]
}
]
}
},
"overrides": [
{
"files": ["*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
16 changes: 16 additions & 0 deletions ts/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Configuration files
.npmrc
.prettierrc
.releaserc
jest.config.js
tsconfig.build.json
tsconfig.json

# Source and test files
src
test

# Miscellaneous directories
.husky
.idea
script
1 change: 1 addition & 0 deletions ts/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
32 changes: 32 additions & 0 deletions ts/.releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"extends": [
"semantic-release-commit-filter"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"tarballDir": "package",
"publish": {
"access": "public"
}
}
],
[
"@semantic-release/github",
{
"assets": "package/*.tgz"
}
]
],
"preset": "angular",
"working_directory": "ts",
"branches": [
{
"name": "main"
}
],
"tagFormat": "ts/v${version}"
}
5 changes: 4 additions & 1 deletion ts/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const common = {
};

module.exports = {
collectCoverageFrom: ['./src/**/*.{js,ts}'],
collectCoverageFrom: [
'<rootDir>/src/**/*.{js,ts}',
'!<rootDir>/src/generated/**/*',
],
projects: [
{
displayName: 'unit',
Expand Down
Loading

0 comments on commit b49d468

Please sign in to comment.