Skip to content

Commit

Permalink
init ci
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Nov 6, 2023
1 parent ac8eac3 commit c16420b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: lint

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4

- uses: actions/checkout@v3

- name: format go
run: |
make fmt-go
if !git diff --exit-code; then
echo "Files are not well formatted"
exit 1
fi
- name: lint go
run: make lint-go

- name: lint spell
run: make lint-spell
50 changes: 50 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: test

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
IN_CI: true

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
# Note: the Go toolchain here is only used to provide go env
# To update the go version, please specify the TEST_IMAGE in Makefile
go-version: '1.20'

- name: Build
run: make build-so

- name: Test
run: make unit-test

integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4

- name: Build
run: make build-test-so

- name: Test
run: make integration-test
- name: Upload logs
uses: actions/upload-artifact@v3
if: failure()
with:
# upload artifact can be found in https://github.com/mosn/moe/actions/runs/$id
name: ci-logs
path: ./test-envoy
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SHELL = /bin/bash
OS = $(shell uname)
IN_CI ?=

TARGET_SO = libgolang.so
PROJECT_NAME = mosn.io/moe
Expand All @@ -26,6 +27,15 @@ GO_TARGETS = $(patsubst %.proto,%.pb.go,$(PROTO_FILES))

TEST_OPTION ?= -gcflags="all=-N -l" -v -race

MOUNT_GOMOD_CACHE = -v $(shell go env GOPATH):/go
ifeq ($(IN_CI), true)
# Mount go mod cache in the CI environment will cause 'Permission denied' error
# when accessing files on host in later phase because the mounted directory will
# have files which is created by the root user in Docker.
# Run as low privilege user in the Docker doesn't
# work because we also need root to create /.cache in the Docker.
MOUNT_GOMOD_CACHE =
endif

.PHONY: gen-proto
gen-proto: build-dev-tools $(GO_TARGETS)
Expand All @@ -42,7 +52,7 @@ gen-proto: build-dev-tools $(GO_TARGETS)
# The conclusion is, we prefer easier to write test to easier to run test.
.PHONY: unit-test
unit-test:
docker run --rm -v $(shell go env GOPATH):/go -v $(PWD):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${TEST_IMAGE} make unit-test-local
docker run --rm ${MOUNT_GOMOD_CACHE} -v $(PWD):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${TEST_IMAGE} make unit-test-local

.PHONY: unit-test-local
unit-test-local:
Expand All @@ -60,13 +70,13 @@ build-test-so-local:
# So here we disable the error via git configuration when running inside Docker.
.PHONY: build-test-so
build-test-so:
docker run --rm -v $(shell go env GOPATH):/go -v $(PWD):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} \
docker run --rm ${MOUNT_GOMOD_CACHE} -v $(PWD):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} \
-e GOPROXY \
${BUILD_IMAGE} \
bash -c "git config --global --add safe.directory '*' && make build-test-so-local"

.PHONY: integration-test
integration-test: build-test-so
integration-test:
if ! docker images ${PROXY_IMAGE} | grep envoyproxy/envoy > /dev/null; then \
docker pull ${PROXY_IMAGE}; \
fi
Expand Down
1 change: 1 addition & 0 deletions tests/integration/plugins/control_plane/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (cp *ControlPlane) Start() {
type Resources map[resource.Type][]types.Resource

func (cp *ControlPlane) updateConfig(res Resources) {
logger.Info("update config", "resource", res)
snapshot, err := cache.NewSnapshot(fmt.Sprintf("%v.0", cp.version), res)
if err != nil {
logger.Error(err, "failed to new snapshot")
Expand Down

0 comments on commit c16420b

Please sign in to comment.