diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..bb2fec5 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2024 Intel Corporation + +name: Build and test workflow +on: + pull_request: + branches: + - master + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - name: build + run: make build + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - name: Unit tests + run: make test diff --git a/.github/workflows/code-scan.yml b/.github/workflows/code-scan.yml new file mode 100644 index 0000000..4ae9ae7 --- /dev/null +++ b/.github/workflows/code-scan.yml @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2024 Intel Corporation + +name: Code scan workflow + +on: + pull_request: + branches: + - master + push: + branches: + - master + +jobs: + version-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: check version + run: make check-version + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - name: golang-lint + run: make lint + license: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: check license + run: make license + fossa-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: FOSSA scan + uses: fossa-contrib/fossa-action@v3 + with: + fossa-api-key: 6d304c09a3ec097ba4517724e4a4d17d diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml deleted file mode 100644 index 3fd2f5a..0000000 --- a/.github/workflows/master.yml +++ /dev/null @@ -1,74 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# Copyright 2024 Intel Corporation - -name: Master workflow -on: - push: - branches: - - master - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - - name: Build - run: go build -o build/_output/onos-mlb ./cmd/onos-mlb - - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - - uses: golangci/golangci-lint-action@v6 - with: - version: latest - args: -v --config .golangci.yml --timeout=15m - - unit-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - - name: Unit tests - run: | - go test -race github.com/onosproject/onos-mlb/pkg/... - go test -race github.com/onosproject/onos-mlb/cmd/... - - docker-build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - - name: Build Docker image - run: | - git clone https://github.com/onosproject/build-tools.git build/build-tools - go mod vendor - docker build . -f build/onos-mlb/Dockerfile -t onosproject/onos-mlb:latest - rm -rf vendor - - license-check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: reuse lint - uses: fsfe/reuse-action@v3 - - fossa-check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: FOSSA scan - uses: fossa-contrib/fossa-action@v3 - with: - fossa-api-key: 6d304c09a3ec097ba4517724e4a4d17d diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ae6d768 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,135 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2024 Intel Corporation +# Copyright 2024 Kyunghee University +name: Publish image and tag/release code + +on: + push: + branches: + - master + tags: + - '*' + +jobs: + version-check: + if: (github.repository_owner == 'onosproject') + runs-on: ubuntu-latest + outputs: + valid_version: ${{ steps.version-check-step.outputs.valid_version }} + dev_version: ${{ steps.dev-version-check-step.outputs.dev_version }} + target_version: ${{ steps.get-target-version-step.outputs.target_version }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: check version + id: version-check-step + run: | + make check-version; if [[ $? == 0 ]]; then echo "valid_version=true" >> $GITHUB_OUTPUT; else echo "valid_version=false" >> $GITHUB_OUTPUT; fi + cat $GITHUB_OUTPUT + + - name: check dev version + id: dev-version-check-step + run: | + f_dev=$(./build/bin/version_check.sh is_dev) + if [[ $f_dev == "true" ]]; then echo "dev_version=true" >> $GITHUB_OUTPUT; else echo "dev_version=false" >> $GITHUB_OUTPUT; fi + cat $GITHUB_OUTPUT + + - name: get target version + id: get-target-version-step + run: | + echo "target_version=$(cat VERSION)" >> $GITHUB_OUTPUT + cat $GITHUB_OUTPUT + + tag_versions: + runs-on: ubuntu-latest + needs: version-check + if: (github.repository_owner == 'onosproject') && (needs.version-check.outputs.valid_version == 'true') && (needs.version-check.outputs.dev_version == 'false') + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: create release using REST API + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GH_ONOS_PAT }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ github.repository }}/releases \ + -d '{ + "tag_name": "v${{ needs.version-check.outputs.target_version }}", + "target_commitish": "${{ github.event.repository.default_branch }}", + "name": "v${{ needs.version-check.outputs.target_version }}", + "draft": false, + "prerelease": false, + "generate_release_notes": true + }' + + publish-images: + runs-on: ubuntu-latest + needs: version-check + if: (github.repository_owner == 'onosproject') && (needs.version-check.outputs.valid_version == 'true') + env: + REGISTRY: docker.io + DOCKER_REPOSITORY: onosproject/ + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - uses: docker/login-action@v3.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push Docker image with tag latest + env: + DOCKER_TAG: latest + run: | + ONOS_MLB_VERSION=${{ env.DOCKER_TAG }} make docker-build + ONOS_MLB_VERSION=${{ env.DOCKER_TAG }} make docker-push + - name: Build and push Docker image with tag + if: needs.version-check.outputs.dev_version == 'false' + env: + DOCKER_TAG: v${{ needs.version-check.outputs.target_version }} + run: | + ONOS_MLB_VERSION=${{ env.DOCKER_TAG }} make docker-build + ONOS_MLB_VERSION=${{ env.DOCKER_TAG }} make docker-push + + bump-up-version: + runs-on: ubuntu-latest + needs: version-check + if: (github.repository_owner == 'onosproject') && (needs.version-check.outputs.valid_version == 'true') && (needs.version-check.outputs.dev_version == 'false') + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: increment version + run: | + IFS='.' read -r major minor patch <<< ${{ needs.version-check.outputs.target_version }} + patch_update=$((patch+1)) + NEW_VERSION="$major.$minor.$patch_update-dev" + echo $NEW_VERSION > VERSION + echo "Updated version: $NEW_VERSION" + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GH_ONOS_PAT }} + commit-message: Update version + committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com> + signoff: true + branch: version-update + delete-branch: true + title: Update version + body: | + Update VERSION file + add-paths: | + VERSION \ No newline at end of file diff --git a/.gitignore b/.gitignore index 34f2258..e12e108 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ coverage.txt .eclipse .settings/ vendor +venv # Jenkins report files *report*.xml diff --git a/Makefile b/Makefile index f559e34..29ed1b3 100644 --- a/Makefile +++ b/Makefile @@ -7,75 +7,60 @@ export GO111MODULE=on .PHONY: build -ONOS_MLB_VERSION := latest +ONOS_MLB_VERSION ?= latest ONOS_BUILD_VERSION := v0.6.6 ONOS_PROTOC_VERSION := v0.6.6 BUF_VERSION := 0.27.1 +all: build images + build: # @HELP build the Go binaries and run all validations (default) build: GOPRIVATE="github.com/onosproject/*" go build -o build/_output/onos-mlb ./cmd/onos-mlb -build-tools:=$(shell if [ ! -d "./build/build-tools" ]; then cd build && git clone https://github.com/onosproject/build-tools.git; fi) -include ./build/build-tools/make/onf-common.mk - test: # @HELP run the unit tests and source code validation -test: build deps linters license +test: build lint license go test -race github.com/onosproject/onos-mlb/pkg/... go test -race github.com/onosproject/onos-mlb/cmd/... -jenkins-test: # @HELP run the unit tests and source code validation producing a junit style report for Jenkins -jenkins-test: deps license linters - TEST_PACKAGES=github.com/onosproject/onos-mlb/... ./build/build-tools/build/jenkins/make-unit - -buflint: #@HELP run the "buf check lint" command on the proto files in 'api' - docker run -it -v `pwd`:/go/src/github.com/onosproject/onos-mlb \ - -w /go/src/github.com/onosproject/onos-mlb/api \ - bufbuild/buf:${BUF_VERSION} check lint - -protos: # @HELP compile the protobuf files (using protoc-go Docker) -protos: - docker run -it -v `pwd`:/go/src/github.com/onosproject/onos-mlb \ - -w /go/src/github.com/onosproject/onos-mlb \ - --entrypoint build/bin/compile-protos.sh \ - onosproject/protoc-go:${ONOS_PROTOC_VERSION} - -helmit-overload: integration-test-namespace # @HELP run overload tests locally - helmit test -n test ./cmd/onos-mlb-test --timeout 30m --no-teardown --suite overload - -helmit-underload: integration-test-namespace # @HELP run underload tests locally - helmit test -n test ./cmd/onos-mlb-test --timeout 30m --no-teardown --suite underload - -helmit-targetload: integration-test-namespace # @HELP run underload tests locally - helmit test -n test ./cmd/onos-mlb-test --timeout 30m --no-teardown --suite targetload - -integration-tests: helmit-overload helmit-underload helmit-targetload - -onos-mlb-docker: # @HELP build onos-mlb Docker image -onos-mlb-docker: +docker-build-onos-mlb: # @HELP build onos-mlb Docker image @go mod vendor docker build . -f build/onos-mlb/Dockerfile \ -t onosproject/onos-mlb:${ONOS_MLB_VERSION} @rm -rf vendor -images: # @HELP build all Docker images -images: build onos-mlb-docker - -kind: # @HELP build Docker images and add them to the currently configured kind cluster -kind: images - @if [ "`kind get clusters`" = '' ]; then echo "no kind cluster found" && exit 1; fi - kind load docker-image onosproject/onos-mlb:${ONOS_MLB_VERSION} - -all: build images - -publish: # @HELP publish version on github and dockerhub - ./build/build-tools/publish-version ${VERSION} onosproject/onos-mlb - -jenkins-publish: jenkins-tools # @HELP Jenkins calls this to publish artifacts - ./build/bin/push-images - ./build/build-tools/release-merge-commit - -clean:: # @HELP remove all the build artifacts - rm -rf ./build/_output ./vendor ./cmd/onos-mlb/onos-mlb ./cmd/onos/onos - go clean -testcache github.com/onosproject/onos-mlb/... - +docker-build: # @HELP build all Docker images +docker-build: build docker-build-onos-mlb + +docker-push-onos-mlb: # @HELP push onos-mlb Docker image + docker push onosproject/onos-mlb:${ONOS_MLB_VERSION} + +docker-push: # @HELP push docker images +docker-push: docker-push-onos-mlb + +lint: # @HELP examines Go source code and reports coding problems + golangci-lint --version | grep $(GOLANG_CI_VERSION) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b `go env GOPATH`/bin $(GOLANG_CI_VERSION) + golangci-lint run --timeout 15m + +license: # @HELP run license checks + rm -rf venv + python3 -m venv venv + . ./venv/bin/activate;\ + python3 -m pip install --upgrade pip;\ + python3 -m pip install reuse;\ + reuse lint + +check-version: # @HELP check version is duplicated + ./build/bin/version_check.sh all + +clean: # @HELP remove all the build artifacts + rm -rf ./build/_output ./vendor ./cmd/onos-mlb/onos-mlb ./cmd/onos/onos venv + go clean github.com/onosproject/onos-mlb/... + +help: + @grep -E '^.*: *# *@HELP' $(MAKEFILE_LIST) \ + | sort \ + | awk ' \ + BEGIN {FS = ": *# *@HELP"}; \ + {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \ + ' \ No newline at end of file diff --git a/build/bin/compile-protos.sh b/build/bin/compile-protos.sh deleted file mode 100644 index b697b14..0000000 --- a/build/bin/compile-protos.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# SPDX-FileCopyrightText: 2019-present Open Networking Foundation -# -# SPDX-License-Identifier: Apache-2.0 - -proto_imports=".:${GOPATH}/src/github.com/gogo/protobuf/protobuf:${GOPATH}/src/github.com/gogo/protobuf:${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate:${GOPATH}/src":"${GOPATH}/src/github.com/onosproject/onos-mlb/api" - -# samples below -# admin.proto cannot be generated with fast marshaler/unmarshaler because it uses gnmi.ModelData -#protoc -I=$proto_imports --doc_out=docs/api --doc_opt=markdown,admin.md --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api/admin,plugins=grpc:. api/admin/v1/*.proto -#protoc -I=$proto_imports --doc_out=docs/api --doc_opt=markdown,diags.md --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mconfig/admin/admin.proto=github.com/onosproject/onos-e2t/api/admin,import_path=github.com/onosproject/onos-e2t/api/diags,plugins=grpc:. api/diags/*.proto - -#protoc -I=$proto_imports --doc_out=docs/api --doc_opt=markdown,headers.md --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api,plugins=grpc:. api/ricapi/e2/headers/v1beta1/headers.proto -#protoc -I=$proto_imports --doc_out=docs/api --doc_opt=markdown,ricapi.md --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api,plugins=grpc:. api/ricapi/e2/v1beta1/ricapi_e2.proto -#protoc -I=$proto_imports --doc_out=docs/api --doc_opt=markdown,subscription.md --gogofaster_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api/subscription/v1beta1,plugins=grpc:. api/subscription/v1beta1/subscription.proto - - -#protoc -I=$proto_imports --validate_out=lang=go:. --proto_path=api --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api:. api/e2ap/v1beta1/e2ap_commondatatypes.proto -#protoc -I=$proto_imports --validate_out=lang=go:. --proto_path=api --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api:. api/e2ap/v1beta1/e2ap_constants.proto -#protoc -I=$proto_imports --validate_out=lang=go:. --proto_path=api --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api:. api/e2ap/v1beta1/e2ap_containers.proto -#protoc -I=$proto_imports --validate_out=lang=go:. --proto_path=api --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api:. api/e2ap/v1beta1/e2ap_ies.proto -#protoc -I=$proto_imports --validate_out=lang=go:. --proto_path=api --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api:. api/e2ap/v1beta1/e2ap_pdu_contents.proto -#protoc -I=$proto_imports --validate_out=lang=go:. --proto_path=api --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,import_path=github.com/onosproject/onos-e2t/api:. api/e2ap/v1beta1/e2ap_pdu_descriptions.proto - -cp -r github.com/onosproject/onos-mlb/* . -rm -rf github.com diff --git a/build/bin/push-images b/build/bin/push-images deleted file mode 100755 index 2542185..0000000 --- a/build/bin/push-images +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# SPDX-FileCopyrightText: 2019-present Open Networking Foundation -# -# SPDX-License-Identifier: Apache-2.0 - -set -e - -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USER" --password-stdin -make images -docker push onosproject/onos-mlb:latest diff --git a/build/bin/version_check.sh b/build/bin/version_check.sh new file mode 100755 index 0000000..feabddb --- /dev/null +++ b/build/bin/version_check.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2024 Intel Corporation + +set +x + +# input should be all, is_valid_format, is_dev, and is_unique +INPUT=$1 + +function is_valid_format() { + # check if version format is matched to SemVer + VER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$' + if [[ ! $(cat VERSION | tr -d '\n' | sed s/-dev//) =~ $VER_REGEX ]] + then + return 1 + fi + return 0 +} + +function is_dev_version() { + # check if version has '-dev' + # if there is, no need to check version + if [[ $(cat VERSION | tr -d '\n' | tail -c 4) =~ "-dev" ]] + then + return 0 + fi + return 1 +} + +function is_unique_version() { + # check if the version is already tagged in GitHub repository + for t in $(git tag | cat) + do + if [[ $t == $(echo v$(cat VERSION | tr -d '\n')) ]] + then + return 1 + fi + done + return 0 +} + +case $INPUT in + all) + is_valid_format + f_valid=$? + if [[ $f_valid == 1 ]] + then + echo "ERROR: Version $(cat VERSION) is not in SemVer format" + exit 2 + fi + + is_dev_version + f_dev=$? + if [[ $f_dev == 0 ]] + then + echo "This is dev version" + exit 0 + fi + + is_unique_version + f_unique=$? + if [[ $f_unique == 1 ]] + then + echo "ERROR: duplicated tag $(cat VERSION)" + exit 2 + fi + ;; + + is_valid_format) + is_valid_format + ;; + + is_dev) + is_dev_version + f_dev=$? + if [[ $f_dev == 0 ]] + then + echo "true" + exit 0 + fi + echo "false" + ;; + + is_unique) + is_unique_version + ;; + + *) + echo -n "unknown input" + exit 2 + ;; + +esac diff --git a/build/onos-mlb/Dockerfile b/build/onos-mlb/Dockerfile index fd40172..3fbf703 100644 --- a/build/onos-mlb/Dockerfile +++ b/build/onos-mlb/Dockerfile @@ -14,7 +14,7 @@ COPY cmd/ /go/src/github.com/onosproject/onos-mlb/cmd/ COPY pkg/ /go/src/github.com/onosproject/onos-mlb/pkg/ COPY vendor/ /go/src/github.com/onosproject/onos-mlb/vendor/ COPY api/ /go/src/github.com/onosproject/onos-mlb/api -COPY build/build-tools /go/src/github.com/onosproject/onos-mlb/build/build-tools/ +COPY build/ /go/src/github.com/onosproject/onos-mlb/build/ RUN cd /go/src/github.com/onosproject/onos-mlb && GOFLAGS=-mod=vendor make ${ONOS_MAKE_TARGET}