diff --git a/.github/config/ct.yml b/.github/config/ct.yml deleted file mode 100644 index 8af18d9f..00000000 --- a/.github/config/ct.yml +++ /dev/null @@ -1,6 +0,0 @@ -# ct.yml - Chart-testing configuration. ---- -check-version-increment: false -excluded-charts: xrd-common -lint-conf: .github/config/yamllint.yml -validate-maintainers: false diff --git a/.github/config/yamllint.yml b/.github/config/yamllint.yml deleted file mode 100644 index 95acc918..00000000 --- a/.github/config/yamllint.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -rules: - braces: enable - brackets: enable - colons: enable - commas: enable - comments: - require-starting-space: false - min-spaces-from-content: 2 - comments-indentation: - level: warning - document-end: disable - document-start: disable - empty-lines: enable - hyphens: enable - indentation: - spaces: consistent - indent-sequences: whatever - check-multi-line-strings: false - key-duplicates: enable - new-line-at-end-of-file: enable - new-lines: enable - trailing-spaces: enable - truthy: - level: warning diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml new file mode 100644 index 00000000..4f1bf592 --- /dev/null +++ b/.github/workflows/commit-check.yml @@ -0,0 +1,26 @@ +name: commit-checks + +on: + pull_request: + branches: + - 'main' + - 'preview-[0-9]+\.[0-9]+\.[0-9]+' + paths-ignore: + - '.gitignore' + - '*.md' + push: + branches: + - 'main' + - 'gh-actions*' + +jobs: + all_tests: + runs-on: ubuntu-latest + name: 'commit-checks' + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Run all tests + run: scripts/commit-check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae849ac1..6994bd69 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - 'preview-[0-9]+\.[0-9]+\.[0-9]+' paths-ignore: - '.gitignore' - '*.md' diff --git a/.github/workflows/sa.yml b/.github/workflows/sa.yml deleted file mode 100644 index 132a48fa..00000000 --- a/.github/workflows/sa.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: static-analysis - -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: 'helm-sa' - 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 (list-changed) - run: | - changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }}) - if [[ -n "$changed" ]]; then - echo "::set-output name=changed::true" - fi - - - name: Run chart-testing (lint) - run: ct lint --config .github/config/ct.yml --target-branch ${{ github.event.repository.default_branch }} - - - name: Run chart-testing (check-version-increment) - run: ct lint --config .github/config/ct-version-increment.yml --target-branch ${{ github.event.repository.default_branch }} - - - name: Run check-dependency-version-increment - run: | - python3 -m pip install --upgrade pip - python3 -m pip install PyYAML - scripts/check-dependency-version-increment - - shellcheck: - runs-on: ubuntu-latest - name: 'bash-sa (shellcheck)' - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: ludeeus/action-shellcheck@1.1.0 - with: - scandir: 'scripts/' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 7d32fa95..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: tests - -on: - pull_request: - branches: - - "main" - paths: - - "charts/**" - push: - branches: - - "main" - - "gh-actions" - -jobs: - tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: docker/setup-buildx-action@v3 - - - uses: docker/build-push-action@v5 - with: - context: "tests" - load: true - tags: tests:latest - - - name: "Build container" - run: | - docker build tests/ -t helm-tests - - - name: "Run Control Plane unit tests" - run: | - docker run -v "$PWD/:/charts" helm-tests bats tests/ut/xrd-control-plane - - - name: "Run vRouter unit tests" - run: | - docker run -v "$PWD/:/charts" helm-tests bats tests/ut/xrd-vrouter diff --git a/.github/workflows/version-increment.yml b/.github/workflows/version-increment.yml new file mode 100644 index 00000000..96c9c446 --- /dev/null +++ b/.github/workflows/version-increment.yml @@ -0,0 +1,26 @@ +name: version-increment + +on: + pull_request: + branches: + - 'main' + 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: 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 }} diff --git a/scripts/commit-check b/scripts/commit-check index a36ce7ea..cdc6ed4b 100755 --- a/scripts/commit-check +++ b/scripts/commit-check @@ -1,16 +1,47 @@ #!/usr/bin/env bash -# commit-check - Pre-commit checks -set -e -o pipefail +# This script runs all commit checks EXCEPT for checking that the version is +# correctly incermented, which is done via a seperate github action. +set -e + +function cleanup() +{ + echo + echo "Cleaning up..." + if [[ -d $TMP_VENV ]]; then + rm -r "$TMP_VENV" + fi +} + +trap cleanup EXIT + +#===================================================== +# Run checks +#===================================================== FAILURES=0 +echo "Setting up python venv..." +TMP_VENV=$(mktemp -d -t venv.XXXXXX) +python3 -m venv "$TMP_VENV" +"$TMP_VENV"/bin/pip install --upgrade pip +"$TMP_VENV"/bin/pip install PyYAML +echo +echo "Running version-increment dependency check" +if ! ./scripts/check-dependency-version-increment; then + echo "Version-increment dependency check failed, check output and fix issues." >&2 + FAILURES=$((FAILURES+1)) +else + echo "Version-increment dependency check passed." +fi + +echo echo "Running helm lint..." args=("--set" "image.repository=repository" "--set" "image.tag=latest") error=false -for chart in charts/*; do +for chart in charts/{xrd-vrouter,xrd-control-plane}; do pushd "$chart" if ! (helm dependency update && helm lint "${args[@]}"); then error=true @@ -19,17 +50,43 @@ for chart in charts/*; do done if [ $error = true ]; then FAILURES=$((FAILURES+1)) - echo "helm lint failed, check output and fix errors" >&2 + echo "Helm lint failed, check output and fix errors" >&2 +else + echo "Helm lint passed." fi - echo echo "Running shellcheck..." if ! shellcheck scripts/{chart-releaser,commit-check}; then - echo "shellcheck failed, check output and fix issues." >&2 + echo "Shellcheck failed, check output and fix issues." >&2 FAILURES=$((FAILURES+1)) +else + echo "Shellcheck passed." fi +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)) +else + echo "Control Plane unit tests passed." +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)) +else + echo "vRouter unit tests passed." +fi + +#===================================================== +# Final steps +#===================================================== echo if ((FAILURES > 0)); then @@ -38,4 +95,4 @@ if ((FAILURES > 0)); then else echo "SUCCESS: All passed!" exit 0 -fi +fi \ No newline at end of file