From 647db83e4ae00a218b3d041344d8ffa7958f1df6 Mon Sep 17 00:00:00 2001 From: Woojoong Kim Date: Sun, 30 Jun 2024 16:46:42 -0700 Subject: [PATCH] migrate CI to github action (#401) * migrate CI to github action Signed-off-by: Woojoong Kim * fix gomod path * fix gofmt Signed-off-by: Woojoong Kim * fix license Signed-off-by: Woojoong Kim * fix gofmt Signed-off-by: Woojoong Kim --------- Signed-off-by: Woojoong Kim --- .github/workflows/build-test.yml | 31 ++++++++ .github/workflows/code-scan.yml | 43 ++++++++++ .github/workflows/master.yml | 63 --------------- .github/workflows/release.yml | 114 +++++++++++++++++++++++++++ .gitignore | 1 + .golangci.yml | 4 +- Makefile | 63 ++++++--------- VERSION | 2 +- build/bin/version_check.sh | 93 ++++++++++++++++++++++ go/onos/config/device/types.go | 1 + go/onos/config/v2/typedvalue_test.go | 4 +- go/onos/ransim/types/types.go | 5 +- go/onos/uenib/uenib.go | 6 +- 13 files changed, 320 insertions(+), 110 deletions(-) create mode 100644 .github/workflows/build-test.yml create mode 100644 .github/workflows/code-scan.yml delete mode 100644 .github/workflows/master.yml create mode 100644 .github/workflows/release.yml create mode 100755 build/bin/version_check.sh diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 00000000..439fe706 --- /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/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/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..ccf05eda --- /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/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 105da047..00000000 --- a/.github/workflows/master.yml +++ /dev/null @@ -1,63 +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 - defaults: - run: - working-directory: ./go - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: './go/go.mod' - - name: Build - run: go build ./... - - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: './go/go.mod' - - uses: golangci/golangci-lint-action@v6 - with: - version: latest - args: -v --config .golangci.yml --timeout=15m - - unit-tests: - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./go - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: './go/go.mod' - - name: Unit tests - run: go test -race github.com/onosproject/onos-api/go/... - - 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..787c3b6d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,114 @@ +# 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 + }' + - name: create release using REST API with go prefix for go 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": "go/v${{ needs.version-check.outputs.target_version }}", + "target_commitish": "${{ github.event.repository.default_branch }}", + "name": "go/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 eb8cf774..553c6008 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ dist/ build/build-tools vendor +venv diff --git a/.golangci.yml b/.golangci.yml index 0706a068..155698b0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,12 +4,12 @@ linters: enable: - gofmt - - revive + #- revive - misspell - typecheck - errcheck - dogsled - - unconvert + #- unconvert - nakedret - exportloopref run: diff --git a/Makefile b/Makefile index b6b40960..f8510344 100644 --- a/Makefile +++ b/Makefile @@ -7,42 +7,21 @@ ONOS_PROTOC_VERSION := v1.3.0 BUF_VERSION := 1.8.0 -all: protos golang +GOLANG_CI_VERSION := v1.52.2 -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 +all: build -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)" - -golang: # @HELP compile Golang sources - cd go && go build ./... +build: # @HELP compile Golang sources + cd go && go build ./... && gofmt -s -w . test: # @HELP run the unit tests and source code validation -test: protos golang linters-go deps-go license +test: build lint license cd go && go test -race github.com/onosproject/onos-api/go/... -jenkins-test: # @HELP run the unit tests and source code validation producing a junit style report for Jenkins -jenkins-test: jenkins-tools test - export TEST_PACKAGES=github.com/onosproject/onos-api/go/... && cd go && ../build/build-tools/build/jenkins/make-unit - mv go/*.xml . - -deps-go: # @HELP ensure that the required dependencies are in place - cd go && go build -v ./... - bash -c "diff -u <(echo -n) <(git diff go/go.mod)" - bash -c "diff -u <(echo -n) <(git diff go/go.sum)" - -linters-go: golang-ci # @HELP examines Go source code and reports coding problems - cd go && golangci-lint run --timeout 15m - -buflint: #@HELP run the "buf check lint" command on the proto files in 'api' - docker run -v `pwd`:/go/src/github.com/onosproject/onos-api \ - -w /go/src/github.com/onosproject/onos-api \ - bufbuild/buf:${BUF_VERSION} check lint +lint: # @HELP examines all source code and report coding problems + cd ./go; \ + 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 protos: # @HELP compile the protobuf files (using protoc-go Docker) protos: @@ -55,14 +34,24 @@ protos: mocks: ./build/bin/generate-mocks.sh -publish: twine # @HELP publish version on github, dockerhub, abd PyPI - BASEDIR=. PYPI_INDEX=pypi ./build/build-tools/publish-python-version - ./build/build-tools/publish-version ${VERSION} - ./build/build-tools/publish-version go/${VERSION} +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 -jenkins-publish: jenkins-tools # @HELP Jenkins calls this to publish artifacts - ./build/build-tools/release-merge-commit +check-version: # @HELP check version is duplicated + ./build/bin/version_check.sh all -clean:: # @HELP remove all the build artifacts +clean: # @HELP remove all the build artifacts rm -rf ./build/_output ./vendor +help: + @grep -E '^.*: *# *@HELP' $(MAKEFILE_LIST) \ + | sort \ + | awk ' \ + BEGIN {FS = ": *# *@HELP"}; \ + {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \ + ' diff --git a/VERSION b/VERSION index f2ae7df3..215a41ec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.10.31 +0.10.31-dev 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/go/onos/config/device/types.go b/go/onos/config/device/types.go index 734da727..8f8f7448 100644 --- a/go/onos/config/device/types.go +++ b/go/onos/config/device/types.go @@ -20,6 +20,7 @@ type Type string // Role is a device role type Role string + // Version is a device version type Version string diff --git a/go/onos/config/v2/typedvalue_test.go b/go/onos/config/v2/typedvalue_test.go index 215efd13..b3b6ba6d 100644 --- a/go/onos/config/v2/typedvalue_test.go +++ b/go/onos/config/v2/typedvalue_test.go @@ -34,8 +34,8 @@ const ( testPrecision0 = uint8(0) ) const ( - testFloatNeg = -3.4E+38 - testFloatPos = 3.4E+38 + testFloatNeg = -3.4e+38 + testFloatPos = 3.4e+38 ) const ( testStringBytes = "onos rocks!" diff --git a/go/onos/ransim/types/types.go b/go/onos/ransim/types/types.go index da6ce668..8b97ce23 100644 --- a/go/onos/ransim/types/types.go +++ b/go/onos/ransim/types/types.go @@ -24,8 +24,9 @@ type CellID uint16 // NodeID is a general abstraction of a global E2 node identifier. // It holds appropriately bit-shifted concatenation of either: -// - [PLMNID + GnbID] or -// - [PLMNID + EnbID] +// - [PLMNID + GnbID] or +// - [PLMNID + EnbID] +// // To extract the corresponding components, application must use the // appropriate 4G or 5G method provided below. type NodeID uint64 diff --git a/go/onos/uenib/uenib.go b/go/onos/uenib/uenib.go index 542182e2..fcbd394b 100644 --- a/go/onos/uenib/uenib.go +++ b/go/onos/uenib/uenib.go @@ -78,16 +78,16 @@ func (ue *UE) SetAspect(value proto.Message) error { } ue.Aspects[proto.MessageName(value)] = &types.Any{ TypeUrl: proto.MessageName(value), - Value: writer.Bytes(), + Value: writer.Bytes(), } return nil } // SetAspectBytes applies the specified aspect as raw JSON bytes to the given UE. func (ue *UE) SetAspectBytes(aspectType string, jsonValue []byte) error { - any := &types.Any { + any := &types.Any{ TypeUrl: aspectType, - Value: jsonValue, + Value: jsonValue, } if ue.Aspects == nil { ue.Aspects = make(map[string]*types.Any)