diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 00000000..bb2fec5e --- /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 00000000..4ae9ae78 --- /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 322fd221..00000000 --- a/.github/workflows/master.yml +++ /dev/null @@ -1,58 +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 github.com/onosproject/onos-lib-go/pkg/... - - 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.0.1 - with: - version: latest - args: -v --config ./.golangci.yml - - 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-lib-go/pkg/... - - 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 00000000..dde94d79 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,98 @@ +# 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 + +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 + }' + + 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 09d23ded..21df57ce 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,4 @@ # build tools build/build-tools vendor - - +venv diff --git a/.reuse/dep5 b/.reuse/dep5 index e447c174..696460db 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -1,6 +1,6 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Files: VERSION *.so *.gnmi *.png *.gif *.jpg go.mod go.sum *.pb.go *_mock_test.go +Files: VERSION *.so *.gnmi *.png *.gif *.jpg go.mod go.sum *.pb.go *_mock_test.go docs/logging/api/logging.md Copyright: 2021 Open Networking Foundation License: Apache-2.0 diff --git a/Makefile b/Makefile index 89b817cf..f6ca7fac 100644 --- a/Makefile +++ b/Makefile @@ -9,43 +9,45 @@ export GO111MODULE=on ONOS_PROTOC_VERSION := v0.6.9 -build: # @HELP build the Go binaries (default) -build: - go build github.com/onosproject/onos-lib-go/pkg/... - -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 +GOLANG_CI_VERSION := v1.52.2 -mod-update: # @HELP Download the dependencies to the vendor folder - go mod tidy - go mod vendor -mod-lint: mod-update # @HELP ensure that the required dependencies are in place - # dependencies are vendored, but not committed, go.sum is the only thing we need to check - bash -c "diff -u <(echo -n) <(git diff go.sum)" +all: build +build: # @HELP build the Go binaries (default) + go build github.com/onosproject/onos-lib-go/pkg/... test: # @HELP run the unit tests and source code validation producing a golang style report -test: mod-lint build linters license +test: build lint license go test -race github.com/onosproject/onos-lib-go/pkg/... -jenkins-test: # @HELP run the unit tests and source code validation producing a junit style report for Jenkins -jenkins-test: mod-lint build linters license - TEST_PACKAGES=github.com/onosproject/onos-lib-go/pkg/... ./build/build-tools/build/jenkins/make-unit - protos: # @HELP compile the protobuf files (using protoc-go Docker) docker run -it -v `pwd`:/go/src/github.com/onosproject/onos-lib-go \ -w /go/src/github.com/onosproject/onos-lib-go \ --entrypoint build/bin/compile-protos.sh \ onosproject/protoc-go:${ONOS_PROTOC_VERSION} -publish: # @HELP publish version on github and dockerhub - ./build/build-tools/publish-version ${VERSION} +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 -jenkins-publish: jenkins-tools # @HELP Jenkins calls this to publish artifacts - ./build/build-tools/release-merge-commit - ./build/build-tools/build/docs/push-docs +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 -all: test +check-version: # @HELP check version is duplicated + ./build/bin/version_check.sh all clean:: # @HELP remove all the build artifacts - go clean -testcache github.com/onosproject/onos-lib-go/... + go clean github.com/onosproject/onos-lib-go/... + +help: + @grep -E '^.*: *# *@HELP' $(MAKEFILE_LIST) \ + | sort \ + | awk ' \ + BEGIN {FS = ": *# *@HELP"}; \ + {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \ + ' diff --git a/build/bin/compile-protos.sh b/build/bin/compile-protos.sh index aee8d419..29e2fed8 100755 --- a/build/bin/compile-protos.sh +++ b/build/bin/compile-protos.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # SPDX-FileCopyrightText: 2020-present Open Networking Foundation # # SPDX-License-Identifier: Apache-2.0 @@ -9,16 +9,28 @@ protoc -I=$proto_imports --doc_out=docs/logging/api --doc_opt=markdown,logging. protoc -I=$proto_imports --go_out=../../.. api/asn1/v1/asn1.proto # Remove the license header copied over by protoc -sed -i "1,4d" api/asn1/v1/asn1/asn1.pb.go +cp api/asn1/v1/asn1/asn1.pb.go api/asn1/v1/asn1/asn1.pb.go_tmp +tail -n +5 api/asn1/v1/asn1/asn1.pb.go_tmp > api/asn1/v1/asn1/asn1.pb.go +rm -rf api/asn1/v1/asn1/asn1.pb.go_tmp +# old one for above: not working on Mac +#sed -i -e "1,4d" api/asn1/v1/asn1/asn1.pb.go protoc -I=$proto_imports:api --go_out=. pkg/asn1/test/aper-test.proto # Remove the license header copied over by protoc -sed -i "1,6d" pkg/asn1/test/aper-test.pb.go +cp pkg/asn1/test/aper-test.pb.go pkg/asn1/test/aper-test.pb.go_tmp +tail -n +5 pkg/asn1/test/aper-test.pb.go_tmp > pkg/asn1/test/aper-test.pb.go +rm -rf pkg/asn1/test/aper-test.pb.go_tmp +# old one for above: not working on Mac +#sed -i "1,6d" pkg/asn1/test/aper-test.pb.go protoc-go-inject-tag -input=pkg/asn1/test/aper-test.pb.go protoc -I=$proto_imports:api --go_out=. pkg/asn1/testsm/test_sm.proto # Remove the license header copied over by protoc -sed -i "1,8d" pkg/asn1/testsm/test_sm.pb.go +cp pkg/asn1/testsm/test_sm.pb.go pkg/asn1/testsm/test_sm.pb.go_tmp +tail -n +5 pkg/asn1/testsm/test_sm.pb.go_tmp > pkg/asn1/testsm/test_sm.pb.go +rm -rf pkg/asn1/testsm/test_sm.pb.go_tmp +# old one for above: not working on Mac +#sed -i "1,8d" pkg/asn1/testsm/test_sm.pb.go protoc-go-inject-tag -input=pkg/asn1/testsm/test_sm.pb.go diff --git a/build/bin/version_check.sh b/build/bin/version_check.sh new file mode 100755 index 00000000..feabddbd --- /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/docs/logging/api/logging.md b/docs/logging/api/logging.md index 2c434ad2..417d423f 100644 --- a/docs/logging/api/logging.md +++ b/docs/logging/api/logging.md @@ -1,8 +1,3 @@ - - # Protocol Documentation diff --git a/pkg/asn1/test/aper-test.pb.go b/pkg/asn1/test/aper-test.pb.go index f1863475..cd228a42 100644 --- a/pkg/asn1/test/aper-test.pb.go +++ b/pkg/asn1/test/aper-test.pb.go @@ -1,3 +1,5 @@ +////////////////////// aper-test.proto ////////////////////// + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.26.0-devel diff --git a/pkg/asn1/testsm/test_sm.pb.go b/pkg/asn1/testsm/test_sm.pb.go index 02b5ff68..58b4aab8 100644 --- a/pkg/asn1/testsm/test_sm.pb.go +++ b/pkg/asn1/testsm/test_sm.pb.go @@ -1,3 +1,7 @@ +////////////////////// test-sm-ies.proto ////////////////////// +// Protobuf generated from /tes_sm.asn1 by asn1c-0.9.29 +// TEST-SM-IEs { iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(0) e2(1) version1(1) e2sm(1) test-sm-IEs(0) } + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.26.0-devel