yokawasa / gitrivy

Trivy with GitHub Actions
MIT License
2 stars 1 forks source link

Fix installation and test failures #16

Closed yokawasa closed 1 year ago

yokawasa commented 1 year ago

Description

This PR is to fix the following 2 issues

Issues

Issue1: installation failure

yarn install

output

yarn install v1.22.19
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] πŸ”  Resolving packages...
warning jest > jest-cli > @jest/core > jest-haste-map > fsevents > node-pre-gyp@0.17.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
warning " > ts-jest@26.5.6" has incorrect peer dependency "jest@>=26 <27".
[4/4] πŸ”¨  Building fresh packages...
warning Error running install script for optional dependency: "/Users/yoichika/dev/github/gitrivy-test/gitrivy.yokawasa/node_modules/fsevents: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /Users/yoichika/dev/github/gitrivy-test/gitrivy.yokawasa/node_modules/fsevents
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@9.3.0
gyp info using node@19.3.0 | darwin | x64
gyp info find Python using Python version 3.9.6 found at \"/Users/yoichika/dev/venv3.8/bin/python3\"
gyp info spawn /Users/yoichika/dev/venv3.8/bin/python3
gyp info spawn args [
gyp info spawn args   '/usr/local/Cellar/node/19.3.0/libexec/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/yoichika/dev/github/gitrivy-test/gitrivy.yokawasa/node_modules/fsevents/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/Cellar/node/19.3.0/libexec/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/yoichika/Library/Caches/node-gyp/19.3.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/yoichika/Library/Caches/node-gyp/19.3.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/Cellar/node/19.3.0/libexec/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/yoichika/Library/Caches/node-gyp/19.3.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/yoichika/dev/github/gitrivy-test/gitrivy.yokawasa/node_modules/fsevents',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
In file included from ../fsevents.cc:6:
In file included from ../../nan/nan.h:174:
../../nan/nan_callbacks.h:55:23: error: no member named 'AccessorSignature' in namespace 'v8'
typedef v8::Local<v8::AccessorSignature> Sig;
                  ~~~~^
In file included from ../fsevents.cc:6:
../../nan/nan.h:2536:8: error: no matching member function for call to 'SetAccessor'
  tpl->SetAccessor(
  ~~~~~^~~~~~~~~~~
/Users/yoichika/Library/Caches/node-gyp/19.3.0/include/node/v8-template.h:814:8: note: candidate function not viable: no known conversion from 'imp::Sig' (aka 'int') to 'v8::SideEffectType' for 7th argument
  void SetAccessor(
       ^
/Users/yoichika/Library/Caches/node-gyp/19.3.0/include/node/v8-template.h:807:8: note: candidate function not viable: no known conversion from 'imp::NativeGetter' (aka 'void (*)(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &)') to 'v8::AccessorGetterCallback' (aka 'void (*)(Local<v8::String>, const PropertyCallbackInfo<v8::Value> &)') for 2nd argument
  void SetAccessor(
       ^
In file included from ../fsevents.cc:6:
In file included from ../../nan/nan.h:2884:
../../nan/nan_typedarray_contents.h:34:43: error: no member named 'GetContents' in 'v8::ArrayBuffer'
      data   = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;
                                  ~~~~~~~~^
3 errors generated.
make: *** [Release/obj.target/fse/fsevents.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/Cellar/node/19.3.0/libexec/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Darwin 22.2.0
gyp ERR! command \"/usr/local/Cellar/node/19.3.0/bin/node\" \"/usr/local/Cellar/node/19.3.0/libexec/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\"
gyp ERR! cwd /Users/yoichika/dev/github/gitrivy-test/gitrivy.yokawasa/node_modules/fsevents
gyp ERR! node -v v19.3.0
gyp ERR! node-gyp -v v9.3.0
gyp ERR! not ok"
info This module is OPTIONAL, you can safely ignore this error
success Saved lockfile.
✨  Done in 10.75s.

Issue2: test failure

yarn run test
# or yarn jest
# or npm run test

output

 FAIL  __tests__/trivy.test.ts (28.551s)
  Platform
    βœ“ is Liniux (2ms)
    βœ“ is Darwin
    βœ“ is not linux and darwin (18ms)
  getDownloadUrl
    βœ“ with latest version and linux (474ms)
    βœ“ with 0.2.0 and macOS (273ms)
    βœ“ with non-supported version (329ms)
    βœ“ with non-supported os (91ms)
  Download trivy command
    βœ“ with valid download URL and save in __tests__ (5199ms)
    βœ“ with invalid download URL (289ms)
  Trivy command
    βœ“ exists (1ms)
    βœ“ does not exist (1ms)
  Trivy scan
    βœ• with valid option (2129ms)
    βœ• without ignoreUnfixed (324ms)
    βœ• with table format (294ms)
    βœ“ with invalid severity
    βœ“ with invalid vulnType (1ms)
  Parse
    βœ“ the result without vulnerabilities (1ms)
    βœ“ the result including vulnerabilities
  Validate trivy option
    βœ“ with a valid severity
    βœ“ with two valid severities
    βœ“ with an invalid severity
    βœ“ with two invalid severities
    βœ“ with an invalid and a valid severities (1ms)
    βœ“ with a valid vuln-type (1ms)
    βœ“ with two valid vuln-types
    βœ“ with an invalid vuln-type
    βœ“ with two invalid vuln-types (1ms)
    βœ“ with a valid and an invalid vuln-types

... snip ...

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |    58.82 |    52.05 |    73.91 |    59.06 |                   |
 index.ts |        0 |        0 |        0 |        0 |... 77,78,81,82,86 |
 issue.ts |        0 |        0 |        0 |        0 |... 62,63,68,70,71 |
 trivy.ts |     89.8 |    67.92 |      100 |    90.53 |... 61,164,166,167 |
 utils.ts |      100 |      100 |      100 |      100 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 failed, 1 passed, 2 total
Tests:       3 failed, 29 passed, 32 total
Snapshots:   0 total
Time:        34.664s
Ran all test suites.

The following 3 unit tests need to be fixed

  Trivy scan
    βœ• with valid option (2129ms)
    βœ• without ignoreUnfixed (324ms)
    βœ• with table format (294ms)

Test after fixes

Installation and build

After updating package.json like this, installation completed successfully!

diff --git a/package.json b/package.json
index 0f5c2b1..97c4311 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,7 @@
     "@actions/github": "^1.1.0",
     "@types/node-fetch": "^2.5.3",
     "@types/tar": "^4.0.3",
-    "axios": "^0.21.1",
+    "axios": "^0.19.1",
     "node-fetch": "^2.6.0",
     "tar": "^5.0.5"
   },
@@ -37,7 +37,7 @@
     "jest": "^24.8.0",
     "jest-circus": "^24.7.1",
     "prettier": "^1.19.1",
-    "ts-jest": "^26.5.6",
+    "ts-jest": "^24.0.2",
     "typescript": "^3.5.1"
   }
 }

After packages installation done, build can be done with the following command

yarn run build

> gitrivy@3.0.5 build
> ncc build src/index.ts

ncc: Version 0.20.5
ncc: Compiling file index.js
ncc: Using typescript@3.9.9 (local user-provided)
737kB  dist/index.js
737kB  [3650ms] - ncc 0.20.5

Test

yarn run test 
# or yarn test
# or yarn jest

output

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |    62.75 |     58.9 |    73.91 |    63.09 |                   |
 index.ts |        0 |        0 |        0 |        0 |... 77,78,81,82,86 |
 issue.ts |        0 |        0 |        0 |        0 |... 62,63,68,70,71 |
 trivy.ts |    95.92 |    77.36 |      100 |    96.84 |       111,161,171 |
 utils.ts |      100 |      100 |      100 |      100 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 2 passed, 2 total
Tests:       32 passed, 32 total
Snapshots:   0 total
Time:        17.908s, estimated 18s
Ran all test suites.
✨  Done in 19.72s.