Skip to content

Commit

Permalink
script done
Browse files Browse the repository at this point in the history
  • Loading branch information
ebeaty-cisco committed May 14, 2024
1 parent 32efd5d commit e989625
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 36 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/sa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: version-increment

on:
pull_request:
branches:
- 'main'
- 'preview-[0-9]+\.[0-9]+\.[0-9]+'
paths-ignore:
- '.gitignore'
- '*.md'
push:
branches:
- 'gh-actions*'

jobs:
helm:
runs-on: ubuntu-latest
name: 'version-increment-check'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: '3.7'

- uses: azure/setup-helm@v3
with:
version: '3.10.0'

- uses: helm/chart-testing-action@v2.3.1

- name: Run chart-testing (check-version-increment)
run: ct lint --config .github/config/ct-version-increment.yml --target-branch ${{ github.event.repository.default_branch }}
119 changes: 83 additions & 36 deletions scripts/commit-check
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
#!/bin/bash

# This script runs all commit checks EXCEPT for checking that the version is
# correctly incermented, which is done via a seperate github action on the
# public xrd-helm repository.

set -e

CONTAINER_TOOL="docker"

usage() {
echo "Usage: $0 -t <docker|podman>"
exit 1
}

while getopts ":t:" opt; do
case $opt in
t)
CONTAINER_TOOL="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done

if [ "$CONTAINER_TOOL" != "docker" ] && [ "$CONTAINER_TOOL" != "podman" ]; then
echo "Error: Only 'docker' or 'podman' can be specified as the container tool."
usage
fi

function cleanup()
{
echo
Expand Down Expand Up @@ -34,29 +66,21 @@ if ! ./scripts/check-dependency-version-increment; then
FAILURES=$((FAILURES+1))
fi

# Install ct by pulling docker image

# echo
# echo "Running chart testing (list-changed)"
# DEFAULT_BRANCH="main"
# changed=$(ct list-changed --target-branch $DEFAULT_BRANCH)
# if [[ -n "$changed" ]]; then
# echo "::set-output name=changed::true"
# fi

# echo
# echo "Running chart testing (lint)"
# if ! ct lint --config .github/config/ct.yml --target-branch $DEFAULT_BRANCH; then
# echo "Chart testing (lint) failed, check output and fix issues." >&2
# FAILURES=$((FAILURES+1))
# fi

# echo
# echo "Running chart testing (check-version-increment)"
# if ! ct lint --config .github/config/ct-version-increment.yml --target-branch $DEFAULT_BRANCH; then
# echo "Chart testing (check-version-increment) failed, check output and fix issues." >&2
# FAILURES=$((FAILURES+1))
# fi
echo
echo "Running helm lint..."
args=("--set" "image.repository=repository" "--set" "image.tag=latest")
error=false
for chart in charts/*; do
pushd "$chart"
if ! (helm dependency update && helm lint "${args[@]}"); then
error=true
fi
popd
done
if [ $error = true ]; then
FAILURES=$((FAILURES+1))
echo "helm lint failed, check output and fix errors" >&2
fi

echo
echo "Running shellcheck..."
Expand All @@ -65,21 +89,44 @@ if ! shellcheck scripts/{chart-releaser,commit-check}; then
FAILURES=$((FAILURES+1))
fi

# Build container for UT
docker build tests/ -t helm-tests --network host
# Build container for UT and run tests using docker or podman
if [ "$CONTAINER_TOOL" == "docker" ]; then
docker build tests/ -t helm-tests --network host

echo
echo "Running Control Plane unit tests..."
if ! docker run -v "$PWD/:/charts" helm-tests bats tests/ut/xrd-control-plane; then
echo "Control Plane unit tests failed, check output and fix issues." >&2
FAILURES=$((FAILURES+1))
fi
echo
echo "Running Control Plane unit tests..."
if ! docker run -v "$PWD/:/charts" helm-tests bats tests/ut/xrd-control-plane; then
echo "Control Plane unit tests failed, check output and fix issues." >&2
FAILURES=$((FAILURES+1))
fi

echo
echo "Running vRouter unit tests..."
if ! docker run -v "$PWD/:/charts" helm-tests bats tests/ut/xrd-vrouter; then
echo "vRouter unit tests failed, check output and fix issues." >&2
FAILURES=$((FAILURES+1))
echo
echo "Running vRouter unit tests..."
if ! docker run -v "$PWD/:/charts" helm-tests bats tests/ut/xrd-vrouter; then
echo "vRouter unit tests failed, check output and fix issues." >&2
FAILURES=$((FAILURES+1))
fi
elif [ "$CONTAINER_TOOL" == "podman" ]; then
podman build tests/ -t helm-tests --network host

echo
echo "Running Control Plane unit tests..."
if ! podman run -v "$PWD/:/charts" helm-tests bats tests/ut/xrd-control-plane; then
echo "Control Plane unit tests failed, check output and fix issues." >&2
FAILURES=$((FAILURES+1))
fi

echo
echo "Running vRouter unit tests..."
if ! podman run -v "$PWD/:/charts" helm-tests bats tests/ut/xrd-vrouter; then
echo "vRouter unit tests failed, check output and fix issues." >&2
FAILURES=$((FAILURES+1))
fi
else
echo "Error: Unsupported container tool. Use 'docker' or 'podman'."
usage
# This should never be reached
exit 1
fi

#=====================================================
Expand Down

0 comments on commit e989625

Please sign in to comment.