Skip to content

Commit

Permalink
migrate CI to github action (#401)
Browse files Browse the repository at this point in the history
* migrate CI to github action

Signed-off-by: Woojoong Kim <[email protected]>

* fix gomod path

* fix gofmt

Signed-off-by: Woojoong Kim <[email protected]>

* fix license

Signed-off-by: Woojoong Kim <[email protected]>

* fix gofmt

Signed-off-by: Woojoong Kim <[email protected]>

---------

Signed-off-by: Woojoong Kim <[email protected]>
  • Loading branch information
woojoong88 authored Jun 30, 2024
1 parent 332b8aa commit 647db83
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 110 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions .github/workflows/code-scan.yml
Original file line number Diff line number Diff line change
@@ -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
63 changes: 0 additions & 63 deletions .github/workflows/master.yml

This file was deleted.

114 changes: 114 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ dist/

build/build-tools
vendor
venv
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
linters:
enable:
- gofmt
- revive
#- revive
- misspell
- typecheck
- errcheck
- dogsled
- unconvert
#- unconvert
- nakedret
- exportloopref
run:
Expand Down
63 changes: 26 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}; \
'
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.31
0.10.31-dev
Loading

0 comments on commit 647db83

Please sign in to comment.