summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCan Eldem <celdem@gitlab.com>2020-05-15 09:29:48 +0000
committerCan Eldem <celdem@gitlab.com>2020-05-15 09:29:48 +0000
commitf91ef2e9f1ac7c2a1fc2e71423b0f09ba89a63cd (patch)
treed23111e4a7390583f4e4de17fbe916a85f56da05
parente97cd3ea94883f487317bd1f8e6289448b9d7fe1 (diff)
parent972f990b336ed2f3feaa2f043dec4f919f17f34c (diff)
Merge branch 'dev-docs' into 'master'
Update README instructions to run tests in docker container See merge request gitlab-org/security-products/license-management!149
-rw-r--r--.gitignore1
-rw-r--r--.gitlab/test.yml4
-rw-r--r--.simplecov4
-rw-r--r--Gemfile.lock9
-rw-r--r--README.md60
-rwxr-xr-xbin/docker-test18
-rw-r--r--license-management.gemspec2
-rw-r--r--spec/spec_helper.rb5
8 files changed, 49 insertions, 54 deletions
diff --git a/.gitignore b/.gitignore
index 74bd0df..87241ef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
Dockerfile.env
pkg
tmp
+coverage
diff --git a/.gitlab/test.yml b/.gitlab/test.yml
index 52ec662..d5c3d7d 100644
--- a/.gitlab/test.yml
+++ b/.gitlab/test.yml
@@ -16,7 +16,7 @@ size:
- export CURRENT_SIZE=$(docker image inspect $TMP_IMAGE --format='{{.Size}}')
- echo $MAX_SIZE
- echo $CURRENT_SIZE
- - test $MAX_SIZE" -gt "$CURRENT_SIZE
+ - test "$MAX_SIZE" -gt "$CURRENT_SIZE"
lint:
stage: test
@@ -41,8 +41,10 @@ lint:
- vendor/bundle
artifacts:
paths:
+ - coverage/coverage.xml
- rspec.xml
reports:
+ cobertura: coverage/coverage.xml
junit: rspec.xml
unit:
diff --git a/.simplecov b/.simplecov
new file mode 100644
index 0000000..e33b0a1
--- /dev/null
+++ b/.simplecov
@@ -0,0 +1,4 @@
+require 'simplecov-cobertura'
+
+SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
+SimpleCov.start
diff --git a/Gemfile.lock b/Gemfile.lock
index e8631b7..e8e1023 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -11,6 +11,7 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.0)
diff-lcs (1.3)
+ docile (1.3.2)
gitlab-styles (3.1.0)
rubocop (~> 0.74.0)
rubocop-gitlab-security (~> 0.1.0)
@@ -67,6 +68,12 @@ GEM
rubocop (>= 0.68.1)
ruby-progressbar (1.10.1)
rubyzip (2.3.0)
+ simplecov (0.18.5)
+ docile (~> 1.1)
+ simplecov-html (~> 0.11)
+ simplecov-cobertura (1.3.1)
+ simplecov (~> 0.8)
+ simplecov-html (0.12.2)
thor (1.0.1)
toml (0.2.0)
parslet (~> 1.8.0)
@@ -83,6 +90,8 @@ DEPENDENCIES
license-management!
rspec (~> 3.9)
rspec_junit_formatter (~> 0.4)
+ simplecov (~> 0.18)
+ simplecov-cobertura (~> 1.3)
BUNDLED WITH
2.1.4
diff --git a/README.md b/README.md
index 2d48099..72e6473 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
[![coverage report](https://gitlab.com/gitlab-org/security-products/license-management/badges/master/coverage.svg)](https://gitlab.com/gitlab-org/security-products/license-management/commits/master)
GitLab tool for detecting licenses of the dependencies used by the provided source.
-It is currently based on [License Finder](https://gitlab.com/gitlab-org/security-products/license-management)
+It is currently based on [License Finder][license_finder]
only, but this may change in the future.
## How to use
@@ -25,48 +25,41 @@ only, but this may change in the future.
### Running the application
-License Management is a Docker image, you can build it like any Docker image like so in the
-project root:
+License Management is a Docker image. You can build it like this from the project root:
```sh
-docker build -t license-management .
+$ ./bin/docker-build
```
You can then run License Management on some target directory:
```sh
-docker run --rm --volume "/path/to/my/project":/code license-management analyze /code
+$ docker run --rm --volume "/path/to/my/project":/code license-management analyze /code
```
-You can run the tests from your host machine using the following command:
+You can run the tests from inside a docker container:
```sh
-./bin/test
-```
-
-It is much more efficient to run the tests from inside the docker container:
-
-```sh
-./bin/docker-build
-./bin/docker-shell
-cd /opt/license-management/
-./bin/test
+$ ./bin/docker-build
+$ ./bin/docker-shell
+$ cd /opt/license-management/
+$ ./bin/test
```
If you need to debug any specific issues you can do this from within the docker container by
following these steps:
```sh
-./bin/docker-build
-./bin/docker-shell
-cd /opt/license-management/
-enable_dev_mode
-bundle open license_finder
+$ ./bin/docker-build
+$ ./bin/docker-shell
+$ cd /opt/license-management/
+$ enable_dev_mode
+$ bundle open license_finder
```
The `docker-shell` script will mount the current project as a volume into `/opt/license-management`.
-This allows you edit code from your host machine using your preferred editor and
-see the affects of those changes from within the running docker container.
+This allows you to edit code from your host machine using your preferred editor and
+see the affect of those changes from within the running docker container.
### Updating the SPDX index
@@ -119,12 +112,6 @@ The License Management tool can be customized with environments variables for so
Inject the required environment variables to the docker command using the [`--env` option flag](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file)
or its shorthand form (`--env MY_SETTING_VAR`) if the configuration comes from an external environment.
-
-*Caution:* if you supply the `MAVEN_CLI_OPTS` for a Maven project, don't forget to append `-DskipTests` to save time by skipping the test suite.
-
-*Tip:* in case you still need to run tests during license management check, supply `MAVEN_CLI_OPTS=-DskipTests=false`
-to the docker command.
-
## Versioning and release process
1. Create a new entry in the `.gitlab/release.yml` file for the new version to release.
@@ -147,19 +134,24 @@ Please check the [Release Process documentation](https://gitlab.com/gitlab-org/s
## Upgrading to the latest version of LicenseFinder
-1. Check for the latest version of `LicenseFinder` at [https://rubygems.org/gems/license_finder](https://rubygems.org/gems/license_finder)
-1. Check the version of the `license_finder` gem that is currently being used in the [`Gemfile.lock`](https://gitlab.com/gitlab-org/security-products/license-management/-/blob/master/Gemfile.lock)
+1. Check for the latest version of `LicenseFinder` at [https://rubygems.org/gems/license_finder][license_finder]
+1. Check the version of the `license_finder` gem that is currently being used in the [`Gemfile.lock`][gemfile_lock]
1. If an update is available, create a new branch
-1. Bump the license management version in [CHANGELOG.md](https://gitlab.com/gitlab-org/security-products/license-management/-/blob/master/CHANGELOG.md) and in [version.rb](https://gitlab.com/gitlab-org/security-products/license-management/-/blob/master/lib/license/management/version.rb)
-1. Update the `license_finder` version constraint in the [gemspec](https://gitlab.com/gitlab-org/security-products/license-management/-/blob/master/license-management.gemspec).
+1. Bump the license management version in [CHANGELOG.md][changelog] and in [version.rb][version_rb]
+1. Update the `license_finder` version constraint in the [gemspec][gemspec]
1. Run `bundle update license_finder`
1. Test the changes locally using the `bin/test` script.
1. Submit a merge request.
-
# Contributing
If you want to help, read the [contribution guidelines](CONTRIBUTING.md).
If an unknown license is detected, please consider updating the mapping defined
in [normalized-licenses.yml](https://gitlab.com/gitlab-org/security-products/license-management/blob/master/normalized-licenses.yml). A mapping can be for a detected name or url and must correspond to an SDPX identifier found in [spdx-licenses.json](https://gitlab.com/gitlab-org/security-products/license-management/blob/master/spdx-licenses.json).
+
+[license_finder]: https://rubygems.org/gems/license_finder
+[changelog]: https://gitlab.com/gitlab-org/security-products/license-management/-/blob/master/CHANGELOG.md
+[version_rb]: https://gitlab.com/gitlab-org/security-products/license-management/-/blob/master/lib/license/management/version.rb
+[gemspec]: https://gitlab.com/gitlab-org/security-products/license-management/-/blob/master/license-management.gemspec
+[gemfile_lock]: https://gitlab.com/gitlab-org/security-products/license-management/-/blob/master/Gemfile.lock
diff --git a/bin/docker-test b/bin/docker-test
index 6fac5d7..c5b0ba1 100755
--- a/bin/docker-test
+++ b/bin/docker-test
@@ -6,19 +6,5 @@ cd "$(dirname "$0")/.."
export CI_PROJECT_DIR="$1"
-if [ -n "${LM_HOME:-}" ]; then
- mkdir -p pkg/ && gem build --silent -o pkg/license-management-test.gem ./*.gemspec
- ./run.sh analyze "$CI_PROJECT_DIR"
-else
- export IMAGE_NAME=${IMAGE_NAME:-$(basename "$PWD"):latest}
-
- docker run --rm \
- --env GRADLE_CLI_OPTS \
- --env LICENSE_FINDER_CLI_OPTS \
- --env LM_JAVA_VERSION \
- --env LM_PYTHON_VERSION \
- --env LM_REPORT_VERSION \
- --env MAVEN_CLI_OPTS \
- --volume "$CI_PROJECT_DIR":/code \
- "$IMAGE_NAME" analyze /code
-fi
+mkdir -p pkg/ && gem build --silent -o pkg/license-management-test.gem ./*.gemspec
+./run.sh analyze "$CI_PROJECT_DIR"
diff --git a/license-management.gemspec b/license-management.gemspec
index 0372991..58ec211 100644
--- a/license-management.gemspec
+++ b/license-management.gemspec
@@ -32,4 +32,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'json-schema', '~> 2.8'
spec.add_development_dependency 'rspec', '~> 3.9'
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
+ spec.add_development_dependency 'simplecov', '~> 0.18'
+ spec.add_development_dependency 'simplecov-cobertura', '~> 1.3'
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 88382dc..fab8418 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,5 @@
+require 'simplecov'
+
require 'license/management'
require 'json'
require 'securerandom'
@@ -13,9 +15,6 @@ RSpec.configure do |config|
config.define_derived_metadata(file_path: %r{/spec/integration}) do |metadata|
metadata[:type] = :integration
end
- config.before(:suite) do
- system('./bin/docker-build') unless ENV['LM_HOME']
- end
config.after(:example, type: :integration) do
runner.cleanup
end