Skip to content

Commit

Permalink
github action version check fix (#1152)
Browse files Browse the repository at this point in the history
* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

* github action version check fix

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

---------

Signed-off-by: Woojoong Kim <[email protected]>
  • Loading branch information
woojoong88 authored Jul 1, 2024
1 parent 7b13e97 commit d0dd0c3
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 60 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: latest
token: ${{ secrets.GH_ONOS_PAT }}
- name: build
run: make deps
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Unit tests
run: make test
48 changes: 48 additions & 0 deletions .github/workflows/code-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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
with:
fetch-depth: 0
- name: check version
run: |
sudo snap install yq
export COMPARISON_BRANCH=origin/master
git branch -a
make check-version
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: helm-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
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: chrisdickinson/setup-yq@latest
- name: check version
run: |
sudo snap install yq
export COMPARISON_BRANCH=${{ github.event.before }}
make check-version
tag_versions:
runs-on: ubuntu-latest
needs: version-check
if: github.repository_owner == 'onosproject'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: create release using REST API
run: |
sudo snap install yq
target_charts=$(./build/bin/version_check.sh get_changed_charts)
for tc in $target_charts)
do
tc_ver=$(yq e '.version' ${tc}/Chart.yaml)
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": "$tc-$tc_ver",
"target_commitish": "${{ github.event.repository.default_branch }}",
"name": "$tc-$tc_ver",
"draft": false,
"prerelease": false,
"generate_release_notes": true
}'
done
publish-charts:
runs-on: ubuntu-latest
needs: version-check
if: (github.repository_owner == 'onosproject') && (needs.version-check.outputs.valid_version == 'true')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: latest
token: ${{ secrets.GH_ONOS_PAT }}
- name: build
run: make deps
- name: publish charts
run: |
export COMPARISON_BRANCH=${{ github.event.before }}
sudo snap install yq rsync
target_charts=$(./build/bin/version_check.sh get_changed_charts)
rm -rf staging && mkdir -p staging/onos-helm-charts
while IFS= read -r tc
do
mkdir -p staging/onos-helm-charts/$tc
tc_ver=$(yq e '.version' $tc/Chart.yaml)
helm package $tc --destination staging/onos-helm-charts/$tc
done <<< $target_charts
cd staging
curl -o current-index.yaml https://sdrancharts.onosproject.org/index.yaml
helm repo index onos-helm-charts --url https://sdrancharts.onosproject.org/onos-helm-charts --merge current-index.yaml
rm -rf current-index.yaml
mv onos-helm-charts/index.yaml .
cd ..
chmod -R g+r staging/
- name: rsync deployments
uses: burnett01/[email protected]
with:
switches: -rvzh
path: staging/
remote_path: /srv/sites/sdrancharts.onosproject.org
remote_host: static.opennetworking.org
remote_user: ${{ secrets.JENKINS_USERNAME }}
remote_key: ${{ secrets.JENKINS_SSHKEY }}
remote_key_pass: ${{ secrets.JENKINS_PASSPHRASE }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
build/release
build/_output
build/build-tools

venv
*.tgz
staging
45 changes: 24 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@
#
# SPDX-License-Identifier: Apache-2.0

.PHONY: all test clean
.PHONY: all test clean version-check

all: test
COMPARISON_BRANCH ?= master

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: dep

jenkins-test: jenkins_version_check license deps # @HELP run the jenkins verification tests
docker pull quay.io/helmpack/chart-testing:v2.4.0
docker run --rm --name ct --volume `pwd`:/charts quay.io/helmpack/chart-testing:v3.0.0-beta.1 sh -c "ct lint --charts charts/onos-e2t,charts/ran-simulator,charts/onos-kpimon --debug --validate-maintainers=false"
lint: # @HELP run helm lint
./build/bin/helm_lint.sh

jenkins_version_check: # @HELP run the version checker on the charts
export COMPARISON_BRANCH=origin/master && export WORKSPACE=`pwd` && ./build/build-tools/chart_version_check

version_check: # @HELP run the version checker on the charts
COMPARISON_BRANCH=master ./build/build-tools/chart_version_check
check-version: # @HELP run the version checker on the charts
COMPARISON_BRANCH=${COMPARISON_BRANCH} ./build/bin/version_check.sh all

test: # @HELP run the integration tests
test: license version_check deps
./build/bin/run-sd-ran-test

publish: # @HELP publish version on sdrancharts.onosproject.org
./build/build-tools/publish-version ${VERSION}

jenkins-publish: # @HELP publish version on github
cd .. && GO111MODULE=on go install github.com/mikefarah/yq/[email protected]
./build/build-tools/release-chart-merge-commit https://sdrancharts.onosproject.org ${WEBSITE_USER} ${WEBSITE_PASSWORD}
test: deps license lint

clean:: # @HELP clean up temporary files for SD-RAN umbrella.
rm -rf sd-ran/charts sd-ran/Chart.lock

deps: # @HELP build dependencies for SD-RAN Umbrella local charts.
deps: clean
helm dep build sd-ran

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


publish: # @HELP publish version on sdrancharts.onosproject.org
./build/build-tools/publish-version ${VERSION}

jenkins-publish: # @HELP publish version on github
cd .. && GO111MODULE=on go install github.com/mikefarah/yq/[email protected]
./build/build-tools/release-chart-merge-commit https://sdrancharts.onosproject.org ${WEBSITE_USER} ${WEBSITE_PASSWORD}
16 changes: 16 additions & 0 deletions build/bin/helm_lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation

exit_code=0

for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
if [[ -f "$dir/Chart.yaml" ]]; then
helm lint "$dir"
if [ $? == 1 ]
then
exit_code=2
fi
fi
done
exit $exit_code
36 changes: 0 additions & 36 deletions build/bin/run-sd-ran-test

This file was deleted.

81 changes: 81 additions & 0 deletions build/bin/version_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation

INPUT=$1

COMPARISON_BRANCH="${COMPARISON_BRANCH:-master}"

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 [[ ! $(echo $1 | tr -d '\n' | sed s/-dev//) =~ $VER_REGEX ]]
then
echo Version $1 is not in SemVer
return 1
fi
return 0
}

function get_changed_charts() {
while IFS= read -r -d '' chart
do
chart_dir=$(dirname $chart)
chart_dir=$(basename $chart_dir)
chart_diff=$(git diff -p $COMPARISON_BRANCH --name-only ./$chart_dir)
if [ -n "$chart_diff" ]
then
echo $chart_dir
fi
done < <(find . -name Chart.yaml -print0)
}

function is_unique_version() {
echo "comparison branch $COMPARISON_BRANCH"

while IFS= read -r -d '' chart
do
chart_dir=$(dirname $chart)
chart_dir=$(basename $chart_dir)
chart_diff=$(git diff -p $COMPARISON_BRANCH --name-only ./$chart_dir)

if [ -n "$chart_diff" ]
then
chart_ver=$(yq e '.version' ${chart_dir}/Chart.yaml)

is_valid_format $chart_ver
if [ $? == 1 ]
then
echo $chart_dir does not have SemVer formatted version $chart_ver
return 1
fi

for t in $(git tag | grep $chart_dir | cat)
do
pure_t=$(echo $t | sed s/$chart_dir-//)
if [ "$pure_t" == "$chart_ver" ]
then
echo Chart $chart_dir version duplicated $chart_ver=$pure_t
return 1
fi
done
fi
done < <(find . -name Chart.yaml -print0)
return 0
}

case $INPUT in
all)
is_unique_version
;;

get_changed_charts)
get_changed_charts
;;

*)
echo -n "unknown input"
exit 2
;;
esac

Loading

0 comments on commit d0dd0c3

Please sign in to comment.