generated from konveyor-ecosystem/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 27
152 lines (133 loc) · 6 KB
/
testing.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Demo Testing
on:
push:
pull_request:
workflow_call:
inputs:
tag:
type: string
required: true
description: Kantra tag to test
workflow_dispatch:
inputs:
tag:
type: string
required: true
description: Kantra tag to test
jobs:
# run tests by building a specific commit from a PR or a branch
test-branch:
name: Build & test from commit
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Upgrade podman
run: |
sudo apt-get install -y ansible
export DEB=$(curl -s https://passt.top/builds/latest/x86_64/ | grep deb | awk -F '"' '{ print $4}')
sudo ansible -m apt -a deb=https://passt.top/builds/latest/x86_64/${DEB} localhost
sudo apt-get remove podman crun
brew install crun podman
- name: Extract pull request number from inputs or PR description
run: |
echo "${{ github.event.pull_request.body }}"
PULL_REQUEST_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -oP 'Analyzer PR: \K\d+' || true)
if [ -z "$PULL_REQUEST_NUMBER" ]; then
echo "ANALYZER_REF=main" >>$GITHUB_ENV
else
echo "ANALYZER_REF=refs/pull/$PULL_REQUEST_NUMBER/merge" >>$GITHUB_ENV
fi
- uses: actions/checkout@v3
with:
fetch-depth: 0
repository: konveyor/analyzer-lsp
ref: "${{ env.ANALYZER_REF}}"
path: analyzer-lsp
- name: Build analyzer image
working-directory: analyzer-lsp
run: |
podman build -t quay.io/konveyor/analyzer-lsp:latest .
- uses: actions/checkout@v3
- name: Build image and binary
run: |
podman build -t localhost/kantra:latest -f Dockerfile .
go build -o kantra main.go
- name: Run unit tests
run: |
RUNNER_IMG=localhost/kantra:latest go test ./...
- name: Fetch sample applications
run: |
git clone https://github.com/konveyor/example-applications
git clone https://github.com/ivargrimstad/jakartaee-duke
- name: Run analysis test and copy output
run: |
RUNNER_IMG=localhost/kantra:latest ./kantra analyze --input $(pwd)/example-applications/example-1/ --output ./output/ --rules ./test-data/jni-native-code-test.windup.xml --target cloud-readiness --run-local=false
# TODO (pgaikwad): Change this to a yaml test and run `kantra test`
- name: Fail if analysis output does not 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 dependencies output does not 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
# run tests using conainer image / binary already published to quay
test-published:
name: Build & test with published images
if: github.event_name != 'push' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Upgrade podman
run: |
sudo apt-get install -y ansible
export DEB=$(curl -s https://passt.top/builds/latest/x86_64/ | grep deb | awk -F '"' '{ print $4}')
sudo ansible -m apt -a deb=https://passt.top/builds/latest/x86_64/${DEB} localhost
sudo apt-get remove podman crun
brew install crun podman
- uses: actions/checkout@v3
with:
ref: ${{ inputs.tag == 'latest' && 'main' || inputs.tag }}
- 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