Skip to content

Commit

Permalink
feat: Fix resolver for cheqd-node 1.x release on mainnet [DEV-2238] (#94
Browse files Browse the repository at this point in the history
)

* Fix problem with deference resource data with old DID format

* Fix problem with get all APIs resources with old DID

* Update unit tests

* Add integration tests for getting resources API with old DID

* Format integration tests files

* Remove duplicate import

* Add implementation to redirect OLD DID to new DID URL

* Fix golangci-lint mistake

* Update unit tests

* Fix problem with view fragment in URL

* Add integration tests for testing old DID with fragment

* Remove unused functions and variables

* Refactor integration tests

* Fix golangci-lint mistakes

* Remove incorrect file push

* Generate OpenAPI swagger

* Rename command 'docker-compose' to 'docker compose'

* Update swagger openAPI

* Update dead link in README.md

* Fix golangci-lint mistakes

* Update openAPI swagger

* Fix golangci-lint mistakes

* Fix typo

* Refactor main.go

* Move ResolutionResourceMetadata type
from did_doc_metadata.go to resource_metadata.go

* Replace deprecated goreleaser property

* Update .goreleaser.yml

* revert: labstack/echo/v4 bump

* Roll everything back

* rename to production-latest

* Delete production-latest.env

* Delete container.env

* Move variables to Docker Compose file

* Set default variables in Dockerfile

* Create docker-compose.yml

* Delete docker-compose.env

* Delete docker-compose.yml

* Rename Dockerfile

* Update test.yml

* Restore Code of Conduct file

* Update README.md

* Fix environment section format

* Reset go mod to see if it works

* Update field in DIDDoc metadata can be skipped if it's not populated

* Refactor code

* Refactor code

* Fix problem with version_id in snake case, currently It print in camelCase

* /did/metadata: This only outputs the resource metadata. This should be the full contents of the didDocumentMetadata section.

* Refactor unit test

* Add a new API endpoint for fetching metadata for specific version of DIDDoc

* Add integration test for testing a new API:
/:did/version/:version/metadata

* Generate swagger openAPI

* Refactor code

* Fix problem with swagger API

* Add a new API comments for swagger OpenAPI

* Generate swagger OpenAPI by last commit changes

* Generate swagger OpenAPI

* Update package-lock.json

* Create Makefile

* make swagger

* swag fmt

* Update go.mod

* swag general info

* delete docs folder

* swag init

* Update Makefile

* mod tidy

* Update Makefile

* Update .goreleaser.yml

* Add build-binary workflow

* Fix Goreleaser archive rlcp warning

* Update build statement in CodeQL

* Update main.go

* Update main.go

* Update make swagger

* Update Dockerfile

* Update root.go

* Update .golangci.yaml

* Fix gocritic check

* Update main.go

* Disable stylecheck for now

* Fix unlambda check

* Update build.yml

* Update Makefile

---------

Co-authored-by: Ankur Banerjee <ankurdotb@users.noreply.github.com>
  • Loading branch information
abdulla-ashurov and ankurdotb committed Feb 22, 2023
1 parent 1853115 commit 18658ab
Show file tree
Hide file tree
Showing 40 changed files with 1,568 additions and 405 deletions.
45 changes: 40 additions & 5 deletions .github/linters/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
run:
timeout: 5m
timeout: 10m


linters:
enable:
- deadcode
- bodyclose
- depguard
- dogsled
- errcheck
- gosimple
- exportloopref
- goconst
- gocritic
- gofumpt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- nestif
- nolintlint
- staticcheck
- structcheck
# - stylecheck # Disable stylecheck until refactor
- typecheck
- unconvert
- unused
- varcheck


linters-settings:
dogsled:
# Checks assignments with too many blank identifiers.
# Default: 2
max-blank-identifiers: 3

gocritic:
# Which checks should be disabled; can't be combined with 'enabled-checks'.
# See https://go-critic.github.io/overview#checks-overview.
# Default: []
disabled-checks:
- regexpMust
- badCall # Remove this after CI workflow PR

gofumpt:
lang-version: "1.18"

misspell:
ignore-words:
- cheqd
- cheq
- ncheq

stylecheck:
# Select the Go version to target.
go: "1.18"
# STxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
checks: ["all"]
# https://staticcheck.io/docs/configuration/options/#dot_import_whitelist
dot-import-whitelist:
- "github.com/cheqd/cheqd-node/x/did/utils"
- "github.com/onsi/gomega"
# https://staticcheck.io/docs/configuration/options/#initialisms
initialisms: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"]
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ defaults:

jobs:

build-binary:
name: "Build binary"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version-file: ./go.mod
cache: true

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: build --clean --snapshot --single-target

- name: Store artifact
uses: actions/upload-artifact@v3
with:
name: cheqd-noded
path: dist/did-resolver_linux_amd64_v1/did-resolver

build-docker:
name: "Build Docker image"
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ jobs:
queries: security-and-quality

- name: Build
run: |
go build main.go
run: make build

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
with:
distribution: goreleaser
version: latest
args: release --rm-dist
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: docker image load --input did-resolver-build.tar

- name: Set up Docker container for test
run: docker-compose -f tests/docker/docker-compose.yml --env-file tests/docker/docker-compose.env up -d --no-build
run: docker compose -f tests/docker-compose-testing.yml up --detach --no-build

- name: Setup Python environment
working-directory: ./tests/pytest
Expand All @@ -54,4 +54,3 @@ jobs:
run: |
set -euo pipefail
pytest -v -rP ./*.py
29 changes: 18 additions & 11 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,40 @@

project_name: did-resolver

env:
- GO111MODULE=on

before:
hooks:
- go mod tidy
- go mod download
- make clean
- make tidy
- make swagger

builds:
-
env:
- CGO_ENABLED=0
main: .
- CGO_ENABLED=1
main: main.go
binary: did-resolver
goos:
- linux
- darwin
goarch:
- amd64
- arm64

flags:
- -mod=readonly
- -trimpath
ldflags:
- -s -w
- -X github.com/cheqd/did-resolver/cmd.version={{ .Version }}
- -X github.com/cheqd/did-resolver/cmd.Commit={{ .Commit }}

archives:
-
replacements:
darwin: Darwin
linux: Linux
amd64: x86_64
- id: release-archives
rlcp: true
format: tar.gz
wrap_in_directory: true
wrap_in_directory: false
name_template: "{{ .Binary }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
files:
- LICENSE
Expand Down
157 changes: 157 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#!/usr/bin/make -f


export GO111MODULE = on

BUILD_DIR ?= $(CURDIR)/build

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')

ifeq (,$(VERSION))
VERSION := $(shell git describe --exact-match 2>/dev/null)
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif


###############################################################################
### All ###
###############################################################################

all: lint build

###############################################################################
### Build flags ###
###############################################################################

# Process build tags

build_tags :=
empty :=
whitespace := $(empty) $(empty)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

# Process linker flags

ldflags = -X github.com/cheqd/did-resolver/cmd.version=$(VERSION) \
-X github.com/cheqd/did-resolver/cmd.Commit=$(COMMIT)

ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif

ifeq ($(NO_STRIP),false)
ldflags += -w -s
endif

ldflags += $(LD_FLAGS)
ldflags := $(strip $(ldflags))

# Set build flags

BUILD_FLAGS := -tags '$(build_tags)' -ldflags '$(ldflags)'

ifeq ($(NO_STRIP),false)
BUILD_FLAGS += -trimpath
endif

###############################################################################
### Build ###
###############################################################################

build: go.sum go-version
@echo "Building DID Resolver binary..."
@mkdir -p $(BUILD_DIR)
@echo $(BUILD_FLAGS)
@go build -mod=readonly $(BUILD_FLAGS) -o build/did-resolver main.go
.PHONY: build

###############################################################################
### Install ###
###############################################################################

install: go.sum go-version
@echo "Installing DID Resolver binary..."
@go install -mod=readonly $(BUILD_FLAGS)
.PHONY: install

###############################################################################
### Go Version ###
###############################################################################

GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MIN_GO_MAJOR_VERSION = 1
MIN_GO_MINOR_VERSION = 18
GO_VERSION_ERROR = Golang version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, \
please update to at least $(MIN_GO_MAJOR_VERSION).$(MIN_GO_MINOR_VERSION)

go-version:
@echo "Verifying go version..."
@if [ $(GO_MAJOR_VERSION) -gt $(MIN_GO_MAJOR_VERSION) ]; then \
exit 0; \
elif [ $(GO_MAJOR_VERSION) -lt $(MIN_GO_MAJOR_VERSION) ]; then \
echo $(GO_VERSION_ERROR); \
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(MIN_GO_MINOR_VERSION) ]; then \
echo $(GO_VERSION_ERROR); \
exit 1; \
fi

.PHONY: go-version

###############################################################################
### Go Modules ###
###############################################################################

go.sum: go.mod
@echo "Ensuring app dependencies have not been modified..."
go mod verify
go mod tidy

verify:
@echo "Verifying all go module dependencies..."
@find . -name 'go.mod' -type f -execdir go mod verify \;

tidy:
@echo "Cleaning up all go module dependencies..."
@find . -name 'go.mod' -type f -execdir go mod tidy \;

.PHONY: verify tidy

###############################################################################
### Tests & Simulation ###
###############################################################################

lint:
golangci-lint run --out-format=tab

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0
.PHONY: lint lint-fix

format:
find . -name '*.go' -type f -not -path "*.git*" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "*.git*" | xargs misspell -w
find . -name '*.go' -type f -not -path "*.git*" | xargs goimports -w -local github.com/cheqd/bdjuno
.PHONY: format

clean:
rm -rf $(BUILD_DIR)
.PHONY: clean

###############################################################################
### Swagger ###
###############################################################################

swagger:
@echo "Generating Swagger files..."
@go install github.com/swaggo/swag/cmd/swag@latest
@swag fmt
@swag init -g main.go
.PHONY: swagger
Loading

0 comments on commit 18658ab

Please sign in to comment.