Skip to content

Commit

Permalink
feat: translate bills in a single web page by wasm (#77)
Browse files Browse the repository at this point in the history
Known issues: 
- Error: total length of command line and environment variables exceeds limit
  Related links: 
    - golang/go#49011
    - https://groups.google.com/g/golang-codereviews/c/-N-Smb0Cfxc

Signed-off-by: TripleZ <me@triplez.cn>
  • Loading branch information
Triple-Z authored Dec 20, 2022
1 parent 1f05eb5 commit 864a4f6
Show file tree
Hide file tree
Showing 37 changed files with 1,678 additions and 181 deletions.
30 changes: 27 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
name: Go Test
name: Go CI
on:
- push
- pull_request
jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: actions/checkout@v3
- name: Cache Go modules
uses: actions/cache@preview
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.OS }}-build-${{ env.cache-name }}-
${{ runner.OS }}-build-
${{ runner.OS }}-
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=5m
version: latest
# Ref https://github.com/golangci/golangci-lint-action/issues/244
skip-pkg-cache: true
test:
name: Test
runs-on: ubuntu-latest
Expand All @@ -28,7 +52,7 @@ jobs:
git diff --cached --exit-code || (echo 'Please run "go mod tidy" to sync Go modules' && exit 1);
- name: Verify gofmt
run: |
make check-format && git add pkg
git diff --cached --exit-code || (echo 'Please run "make format" to verify gofmt' && exit 1);
make check-format && make format && git add pkg
git diff --cached --exit-code || (echo 'Please run "make format" to verify gofmt & goimports' && exit 1);
- name: Run Go test
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

.vscode/
bin/
wasm-dist/

# Alipay records
alipay_records_*.csv
Expand Down
46 changes: 43 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ GOPATH ?= $(shell go env GOPATH)
BIN_DIR := $(GOPATH)/bin
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint

# https://stackoverflow.com/a/14777895
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows
else
detected_OS := $(shell uname) # same as "uname -s"
endif

ifeq ($(detected_OS), Windows)
BROWSER := start
else
ifeq (,$(findstring Drawin,$(detected_OS))) # Mac OS X
BROWSER := open
else # consider as Linux or others
BROWSER := xdg-open
endif
endif

# All targets.
.PHONY: lint test build container push help clean test-go test-wechat test-alipay test-huobi test-htsec format check-format goreleaser-build-test

Expand All @@ -50,12 +67,15 @@ help: ## Display this help

build: build-local ## Build the project

LD_FLAGS := -ldflags "-s -w
LD_FLAGS += -X $(ROOT)/pkg/version.VERSION=$(VERSION)
LD_FLAGS += -X $(ROOT)/pkg/version.REPOROOT=$(ROOT)
LD_FLAGS += -X $(ROOT)/pkg/version.COMMIT=$(GIT_COMMIT)"

build-local:
@for target in $(TARGETS); do \
go build -v -o $(OUTPUT_DIR)/$${target} \
-ldflags "-s -w -X $(ROOT)/pkg/version.VERSION=$(VERSION) \
-X $(ROOT)/pkg/version.REPOROOT=$(ROOT) \
-X $(ROOT)/pkg/version.COMMIT=$(GIT_COMMIT)" \
$(LD_FLAGS) \
$(CMD_DIR)/; \
done

Expand All @@ -68,6 +88,7 @@ clean: ## Clean all the temporary files
@rm -rf ./dist
@rm -rf ./test/output
@rm -rf ./double-entry-generator
@rm -rf ./wasm-dist

test: test-go test-alipay test-wechat test-huobi test-htsec ## Run all tests

Expand All @@ -88,9 +109,28 @@ test-htsec: ## Run tests for htsec provider

format: ## Format code
@gofmt -s -w pkg
@goimports -w pkg

lint: ## Lint GO code
@golangci-lint run

check-format: ## Check if the format looks good.
@go fmt ./...

goreleaser-build-test: ## Goreleaser build for testing
goreleaser build --single-target --snapshot --rm-dist

clean-wasm: ## Clean wasm-dist dir
@rm -rf ./wasm-dist

build-wasm: clean-wasm ## Build WebAssembly's version
@mkdir -p wasm-dist
GOOS=js GOARCH=wasm go build -o wasm-dist/double-entry-generator.wasm $(LD_FLAGS) $(CMD_DIR)/
@cp "$$(go env GOROOT)/misc/wasm/wasm_exec.js" wasm-dist/
@cp wasm/* wasm-dist/
@echo "Build wasm completed! Type \`make run-wasm-server\` to run wasm."

run-wasm-server: ## Run WebAssembly in browser
@cd wasm-dist
# @$(BROWSER) http://127.0.0.1:2000
@python -m http.server --directory wasm-dist --bind 127.0.0.1 2000
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.12
require (
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.4.0
github.com/spf13/viper v1.14.0
github.com/xuri/excelize/v2 v2.5.0
golang.org/x/text v0.3.6
golang.org/x/text v0.4.0
)
Loading

0 comments on commit 864a4f6

Please sign in to comment.