Skip to content

Commit

Permalink
Merge branch 'aws:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
t3rryM authored Dec 9, 2024
2 parents 2de3003 + 88f55cd commit 3a9ce10
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 103 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,8 @@ dependencies.xlsx
[Oo]bj/
[Ll]og/

*.jar
*.jar

temp/

.DS_Store
22 changes: 18 additions & 4 deletions Integration-Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,27 @@ $Lines_To_Find = @(
"using dependency library github.com/golang/snappy version 0.0.1. upgrade to at least version 0.0.2"
)

Write-Host "Setting up sample-projects"
# Copy all sample projects to temp directory and rename project manifests to correct format.
# This is done to avoid security scanning them for deprecated/vulnerable library dependancies
# These sample projects are not intended to be used in production, but are used for testing
$sample_projects_dir = Get-Random
Copy-Item -Path "./sample-projects" -Destination "./temp/$sample_projects_dir" -Recurse
Rename-Item -Path "./temp/$sample_projects_dir/dotnet-samples/sample_csproj_PLACEHOLDER" -NewName "sample.csproj"
Rename-Item -Path "./temp/$sample_projects_dir/go-samples/compatible/go_mod_PLACEHOLDER" -NewName "go.mod"
Rename-Item -Path "./temp/$sample_projects_dir/go-samples/incompatible/go_mod_PLACEHOLDER" -NewName "go.mod"
Rename-Item -Path "./temp/$sample_projects_dir/java-samples/pom_xml_PLACEHOLDER" -NewName "pom.xml"
Rename-Item -Path "./temp/$sample_projects_dir/node-samples/package_json_PLACEHOLDER" -NewName "package.json"
Rename-Item -Path "./temp/$sample_projects_dir/python-samples/compatible/requirements_txt_PLACEHOLDER" -NewName "requirements.txt"
Rename-Item -Path "./temp/$sample_projects_dir/python-samples/incompatible/requirements_txt_PLACEHOLDER" -NewName "requirements.txt"
Rename-Item -Path "./temp/$sample_projects_dir/ruby-samples/Gemfile_PLACEHOLDER" -NewName "Gemfile"

Write-Host "Running samples to console"
$ResultConsole = Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects"
$ResultConsole = Invoke-Expression ".\dist\$Filename\$Filename.exe .\temp\$sample_projects_dir"
Test-Report "Console" $ResultConsole $Lines_To_Find

Write-Host "Running samples to HTML report"
Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects --output test.html"
Invoke-Expression ".\dist\$Filename\$Filename.exe .\temp\$sample_projects_dir --output test.html"
$ResultHtml = Get-Content -Path test.html
Test-Report "HTML" $ResultHtml $Lines_To_Find
Remove-Item -Path test.html
Expand All @@ -64,7 +79,6 @@ $Dependencies = @(
"<si><t>coverlet.collector</t></si><si><t>1.2.0</t></si>"
"<si><t>SciPy</t></si>"
"<si><t>NumPy</t></si>"
"<si><t>FakeDependency</t></si><si><t>1.2.3</t></si>"
"<si><t>cors</t></si><si><t>2.8.5</t></si>"
"<si><t>express</t></si><si><t>4.18.1</t></si>"
"<si><t>rxjs</t></si><si><t>7.5.6</t></si>"
Expand All @@ -87,7 +101,7 @@ $Dependencies = @(
"<si><t>httpclient</t></si>"
"<si><t>jruby-openssl</t></si>"
)
Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects --output test.xlsx --output-format dependencies"
Invoke-Expression ".\dist\$Filename\$Filename.exe .\temp\$sample_projects_dir --output test.xlsx --output-format dependencies"
# xlsx files are compressed files, so we need to unzip them and then compare them
Expand-Archive test.xlsx -DestinationPath temp
$ResultXlsx = Get-Content ".\temp\xl\sharedStrings.xml"
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fi

echo "🏗️ Generating executable"
CERT_PATH=$(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
pyinstaller --onefile --clean --noconfirm --distpath dist --add-data 'src/advisor/rules/*.json:advisor/rules' --add-data 'src/advisor/tools/graviton-ready-java/target/*:advisor/tools/graviton-ready-java/target' --add-data 'src/advisor/templates/template.html:advisor/templates' --add-data "$CERT_PATH/certifi/cacert.pem:certifi" --name "$FILE_NAME" "src/porting-advisor.py" --runtime-hook 'src/updater.py' --exclude-module readline
pyinstaller --onefile --clean --noconfirm --distpath dist --add-data 'src/advisor/rules/*.json:advisor/rules' --add-data 'src/advisor/tools/graviton-ready-java/target/*:advisor/tools/graviton-ready-java/target' --add-data 'src/advisor/templates/template.html:advisor/templates' --add-data "$CERT_PATH/certifi/cacert.pem:certifi" --name "$FILE_NAME" "src/porting-advisor.py" --exclude-module readline
if [ $? -ne 0 ]; then
echo "**ERROR**: pyinstaller failed, binary was not created" && exit 1
fi
Expand Down
7 changes: 5 additions & 2 deletions container-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ source ./test-helpers.sh
# This script tests container image build and runs a couple of
# tests against the generated image.

echo "Setting up sample-projects"
sample_project_directory=$(get_sample_projects_relative_path)

docker build -t porting-advisor .
if [ $? -ne 0 ]; then
echo "**ERROR**: building container image" && exit 1
fi

echo "Running container on samples to console"
docker run --rm -v $(pwd)/sample-projects:/source porting-advisor /source > console_test.txt
docker run --rm -v $(pwd)/$sample_project_directory:/source porting-advisor /source > console_test.txt
test_report 'console' 'console_test.txt' "${lines_to_find[@]}"
if [ $? -ne 0 ]; then
echo "**ERROR**: running container to console" && exit 1
fi
rm console_test.txt

echo "Running container on samples to HTML report"
docker run --rm -v $(pwd):/source porting-advisor /source/sample-projects --output /source/test.html
docker run --rm -v $(pwd):/source porting-advisor /source/$sample_project_directory --output /source/test.html
test_report 'html' 'test.html' "${lines_to_find[@]}"
if [ $? -ne 0 ]; then
echo "**ERROR**: running container to html report" && exit 1
Expand Down
11 changes: 7 additions & 4 deletions integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ source ./test-helpers.sh
FILE_NAME=`./getBinaryName.sh`
chmod +x ./dist/$FILE_NAME

echo "Setting up sample-projects"
sample_project_directory=$(get_sample_projects_relative_path)

echo "Running samples to console"
./dist/$FILE_NAME ./sample-projects/ > console_test.txt
./dist/$FILE_NAME $sample_project_directory > console_test.txt
test_report 'console' 'console_test.txt' "${lines_to_find[@]}"
rm console_test.txt


echo "Running samples to HTML report"
./dist/$FILE_NAME ./sample-projects/ --output test.html
./dist/$FILE_NAME $sample_project_directory --output test.html
test_report 'html' 'test.html' "${lines_to_find[@]}"
rm test.html

Expand All @@ -35,7 +38,6 @@ declare -a dependencies=("<si><t>component</t></si><si><t>version</t></si><si><t
"<si><t>coverlet.collector</t></si><si><t>1.2.0</t></si>"
"<si><t>SciPy</t></si>"
"<si><t>NumPy</t></si>"
"<si><t>FakeDependency</t></si><si><t>1.2.3</t></si>"
"<si><t>cors</t></si><si><t>2.8.5</t></si>"
"<si><t>express</t></si><si><t>4.18.1</t></si>"
"<si><t>rxjs</t></si><si><t>7.5.6</t></si>"
Expand All @@ -58,7 +60,7 @@ declare -a dependencies=("<si><t>component</t></si><si><t>version</t></si><si><t
"<si><t>httpclient</t></si>"
"<si><t>jruby-openssl</t></si>"
)
./dist/$FILE_NAME ./sample-projects/ --output test.xlsx --output-format dependencies
./dist/$FILE_NAME $sample_project_directory --output test.xlsx --output-format dependencies
# xlsx files are compressed files, so we need to unzip them and then compare them
mkdir ./temp
unzip -q ./test.xlsx -d ./temp
Expand Down Expand Up @@ -87,3 +89,4 @@ else
echo "**FAILED**: directory not found test" && exit 1
fi
rm directory_not_found_test.txt

2 changes: 1 addition & 1 deletion porting-advisor-win-x64.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a = Analysis(
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=['src\\updater.py'],
runtime_hooks=[],
excludes=['readline', 'pyinstaller', 'pyinstaller-hooks-contrib'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
Expand Down
12 changes: 5 additions & 7 deletions requirements-build.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
altgraph==0.17.3
certifi==2023.7.22
charset-normalizer==3.2.0
certifi==2024.7.4
coverage==7.2.7
idna==3.4
Jinja2==3.1.2
idna==3.7
Jinja2==3.1.4
MarkupSafe==2.1.3
packaging==23.1
progressbar33==2.4
pyinstaller==5.13.0
pyinstaller==5.13.1
pyinstaller-hooks-contrib==2023.6
pyparsing==3.1.1
requests==2.31.0
urllib3==2.0.4
urllib3==2.2.2
XlsxWriter==3.1.2
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
altgraph==0.17.3
Jinja2==3.1.2
Jinja2==3.1.4
MarkupSafe==2.1.3
packaging==23.1
progressbar33==2.4
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Porting Advisor for Graviton test file

SciPy>=1.7.1
NumPy
FakeDependency>=1.2.3
NumPy
File renamed without changes.
1 change: 1 addition & 0 deletions sample-projects/ruby-samples/sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Hello World"
2 changes: 1 addition & 1 deletion src/advisor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

__project__ = 'porting-advisor'
__version__ = '1.1.0'
__version__ = '1.1.1'
__summary__ = 'Produces an aarch64 porting readiness report.'
__webpage__ = 'http://www.gitlab.com/arm-hpc/porting-advisor'

Expand Down
5 changes: 3 additions & 2 deletions src/advisor/rules/go.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"recommendedVersion": "1.18"
},
"libraryRules": [
{ "name": "github.com/golang/snappy", "minVersion": "0.0.2" }
{ "name": "github.com/golang/snappy", "minVersion": "0.0.2" },
{ "name": "github.com/argoproj/argo-cd/v2", "minVersion": "2.4.0" }
]
}
}
2 changes: 1 addition & 1 deletion src/advisor/tools/graviton-ready-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 4 additions & 0 deletions src/porting-advisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
SPDX-License-Identifier: Apache-2.0
"""
import sys

from advisor import main

if __name__ == '__main__':
if sys.version_info < (3, 10):
print("Python 3.10 or newer is required to run this application.")
sys.exit(1)
main()
67 changes: 0 additions & 67 deletions src/updater.py

This file was deleted.

18 changes: 18 additions & 0 deletions test-helpers.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#!/bin/bash

function get_sample_projects_relative_path() {
# Copy all sample projects to temp directory and rename project manifests to correct format.
# This is done to avoid security scanning them for deprecated/vulnerable library dependancies
# These sample projects are not intended to be used in production, but are used for testing
sample_projects_dir=$RANDOM
mkdir -p ./temp/$sample_projects_dir && cp -r ./sample-projects/* ./temp/$sample_projects_dir
mv ./temp/$sample_projects_dir/dotnet-samples/sample_csproj_PLACEHOLDER ./temp/$sample_projects_dir/dotnet-samples/sample.csproj
mv ./temp/$sample_projects_dir/go-samples/compatible/go_mod_PLACEHOLDER ./temp/$sample_projects_dir/go-samples/compatible/go.mod
mv ./temp/$sample_projects_dir/go-samples/incompatible/go_mod_PLACEHOLDER ./temp/$sample_projects_dir/go-samples/incompatible/go.mod
mv ./temp/$sample_projects_dir/java-samples/pom_xml_PLACEHOLDER ./temp/$sample_projects_dir/java-samples/pom.xml
mv ./temp/$sample_projects_dir/node-samples/package_json_PLACEHOLDER ./temp/$sample_projects_dir/node-samples/package.json
mv ./temp/$sample_projects_dir/python-samples/compatible/requirements_txt_PLACEHOLDER ./temp/$sample_projects_dir/python-samples/compatible/requirements.txt
mv ./temp/$sample_projects_dir/python-samples/incompatible/requirements_txt_PLACEHOLDER ./temp/$sample_projects_dir/python-samples/incompatible/requirements.txt
mv ./temp/$sample_projects_dir/ruby-samples/Gemfile_PLACEHOLDER ./temp/$sample_projects_dir/ruby-samples/Gemfile

echo ./temp/$sample_projects_dir
}

function test_line() {
reportType=$1
result_filename=$2
Expand Down
10 changes: 1 addition & 9 deletions unittest/test_manifester.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_get_dependencies_for_pip_returns_array_of_dependencies(self):
self.assertEqual('requirements.txt', dependencies[1].filename)
self.assertEqual('pip', dependencies[1].tool)
self.assertEqual(3, dependencies[1].lineno)
self.assertEqual('3.1.2', dependencies[1].installed_version)

def test_get_dependencies_for_maven_returns_array_of_dependencies(self):
manifester = Manifester()
Expand Down Expand Up @@ -148,11 +147,4 @@ def test_get_dependencies_for_ruby_returns_array_of_dependencies(self):
self.assertEqual('6.1.6.1', dependencies[0].version)
self.assertEqual('Gemfile', dependencies[0].filename)
self.assertEqual('ruby', dependencies[0].tool)

def test_scan_folder_returns_array_of_all_dependencies(self):
manifester = Manifester()
sample_path = path.abspath(path.join(path.dirname(__file__), '..', 'sample-projects'))
dependencies = manifester.scan_folder(sample_path)
self.assertGreater(len(dependencies), 0)
self.assertIsInstance(dependencies, list)
self.assertIsInstance(dependencies[0], Dependency)

0 comments on commit 3a9ce10

Please sign in to comment.