From 4d049ca2b84848c73c72dce6b7ca0931a529022b Mon Sep 17 00:00:00 2001 From: Pranav Gaikwad Date: Wed, 1 May 2024 11:15:07 -0400 Subject: [PATCH] :ghost: add workflow to run sanity tests on branches Signed-off-by: Pranav Gaikwad --- .github/workflows/nightly.yaml | 20 +++++++++++++ .github/workflows/testing.yaml | 55 ++++++++++++++++++++++++++++++++-- README.md | 2 ++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/nightly.yaml diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml new file mode 100644 index 0000000..2ea642e --- /dev/null +++ b/.github/workflows/nightly.yaml @@ -0,0 +1,20 @@ +name: Nightly tests + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + inputs: + tag: + type: string + default: latest + description: Container image tag to use for testing + +jobs: + run_test: + uses: pranavgaikwad/kantra/.github/workflows/testing.yaml@main + with: + tag: ${{ github.ref_name == 'main' && 'latest' || github.ref_name }} + + + diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 9cea3c3..d910dc8 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -1,9 +1,18 @@ name: Demo Testing -on: ["push", "pull_request", "workflow_dispatch"] +on: + push: + pull_request: + workflow_call: + inputs: + tag: + type: string + required: true jobs: - test: + test-branch: + name: Run tests using image built from current branch + if: github.event_name == 'push' || github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - name: Setup Homebrew @@ -34,7 +43,7 @@ jobs: ref: "${{ env.ANALYZER_REF}}" path: analyzer-lsp - - name: Build anaylzer and save image + - name: Build analyzer image working-directory: analyzer-lsp run: | podman build -t quay.io/konveyor/analyzer-lsp:latest . @@ -81,3 +90,43 @@ jobs: sed 's/^[ \t-]*//' $expected_file | sort -s > /tmp/expected_file sed 's/^[ \t-]*//' $actual_file | sort -s > /tmp/actual_file diff /tmp/expected_file /tmp/actual_file || diff $expected_file $actual_file + + test-published: + name: Run tests using published images + if: github.event_name != 'push' && github.event_name != 'pull_request' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: download kantra and run test + run: | + git clone https://github.com/konveyor/example-applications + podman cp $(podman create --name kantra-download quay.io/konveyor/kantra:${{ inputs.tag }}):/usr/local/bin/kantra . + podman rm kantra-download + ./kantra analyze --input $(pwd)/example-applications/example-1/ \ + --output ./output/ --target cloud-readiness \ + --rules ./test-data/jni-native-code-test.windup.xml + + - name: fail if analysis output doesn't match expected + run: | + expected_file=./test-data/analysis-output.yaml + actual_file=./output/output.yaml + function filter_and_sort() { + yq e 'del(.[].skipped) | del(.[].unmatched)' $1 \ + | yq e '.[]?.violations |= (. | to_entries | sort_by(.key) | from_entries)' \ + | yq e '.[]?.violations[]?.incidents |= sort_by(.uri)' \ + | yq e '.[] | (.tags // []) |= sort' + } + filter_and_sort $expected_file > $expected_file + filter_and_sort $actual_file > $actual_file + diff $expected_file $actual_file + + - name: fail if deps output doesn't match expected + run: | + expected_file=./test-data/deps-output.yaml + actual_file=./output/dependencies.yaml + sed 's/^[ \t-]*//' $expected_file | sort -s > /tmp/expected_file + sed 's/^[ \t-]*//' $actual_file | sort -s > /tmp/actual_file + diff /tmp/expected_file /tmp/actual_file || diff $expected_file $actual_file + + \ No newline at end of file diff --git a/README.md b/README.md index f0be1c4..ae5f7f6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![Test](https://github.com/konveyor/kantra/actions/workflows/nightly.yml/badge.svg?branch=main) + # Kantra Kantra is a CLI that unifies analysis and transformation capabilities of Konveyor. It is available for Linux, Mac and Windows.