diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..6d829e0 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,47 @@ +include: + - component: gitlab.com/$CI_PROJECT_PATH@$CI_COMMIT_SHA + +stages: [test, release] + +# ensure-jobs-added: +# image: badouralix/curl-jq +# script: +# - | +# route="https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/jobs" +# count=`curl --silent --header "PRIVATE-TOKEN: $API_TOKEN" $route | jq 'map(select(.name | contains("component-job-"))) | length'` +# if [ "$count" != "2" ]; then +# exit 1 +# fi + +# Ensure that a project description exists, because it will be important to display +# the resource in the catalog. +check-description: + image: badouralix/curl-jq + script: + - | + route="https://gitlab.com/api/v4/projects/$CI_PROJECT_ID" + desc=`curl --silent $route | jq '.description'` + if [ "$desc" = "null" ]; then + echo "Description not set. Please set a projet description" + exit 1 + else + echo "Description set" + fi + +# Ensure that a `README.md` exists in the root directory as it represents the +# documentation for the whole components repository. +check-readme: + image: busybox + script: ls README.md || (echo "Please add a README.md file" && exit 1) + +# If we are tagging a release with a specific convention ("v" + number) and all +# previous checks succeeded, we proceed with creating a release automatically. +create-release: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + rules: + - if: $CI_COMMIT_TAG =~ /\d+/ + script: echo "Creating release $CI_COMMIT_TAG" + release: + tag_name: $CI_COMMIT_TAG + description: "Release $CI_COMMIT_TAG of components repository $CI_PROJECT_PATH" \ No newline at end of file diff --git a/README.md b/README.md index b48acb9..de407fd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## SAST (Static Application Security Testing) +# SAST (Static Application Security Testing) Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/sast/ @@ -40,10 +40,3 @@ include: | `search_max_depth` | `4` | Defines how many directory levels the search for programming languages should span | | `run_kubesec_sast` | `"false"` | Set it to `"true"` to run `kubesec-sast` job | | `include_experimental` | `"false"` | Set it to `"true"` to enable [experimental analyzers](https://docs.gitlab.com/ee/user/application_security/sast/#experimental-features) | - -### Variables - -| Variable | Default value | Description | -| -------- | ------------- | ----------- | - -### ToDos diff --git a/src/ruby_gem/.gitignore b/src/ruby_gem/.gitignore new file mode 100644 index 0000000..b04a8c8 --- /dev/null +++ b/src/ruby_gem/.gitignore @@ -0,0 +1,11 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ + +# rspec failure tracking +.rspec_status diff --git a/src/ruby_gem/.gitlab-ci.yml b/src/ruby_gem/.gitlab-ci.yml new file mode 100644 index 0000000..d21b05e --- /dev/null +++ b/src/ruby_gem/.gitlab-ci.yml @@ -0,0 +1,10 @@ +default: + image: ruby:3.0.5 + + before_script: + - gem install bundler -v 2.4.12 + - bundle install + +example_job: + script: + - bundle exec rake diff --git a/src/ruby_gem/.rspec b/src/ruby_gem/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/src/ruby_gem/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/src/ruby_gem/.rubocop.yml b/src/ruby_gem/.rubocop.yml new file mode 100644 index 0000000..e3462a7 --- /dev/null +++ b/src/ruby_gem/.rubocop.yml @@ -0,0 +1,13 @@ +AllCops: + TargetRubyVersion: 2.6 + +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +Style/StringLiteralsInInterpolation: + Enabled: true + EnforcedStyle: double_quotes + +Layout/LineLength: + Max: 120 diff --git a/src/ruby_gem/Gemfile b/src/ruby_gem/Gemfile new file mode 100644 index 0000000..f83039d --- /dev/null +++ b/src/ruby_gem/Gemfile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# Specify your gem's dependencies in ruby_gem.gemspec +gemspec + +gem "rake", "~> 13.0" + +gem "rspec", "~> 3.0" + +gem "rubocop", "~> 1.21" diff --git a/src/ruby_gem/README.md b/src/ruby_gem/README.md new file mode 100644 index 0000000..927c8c1 --- /dev/null +++ b/src/ruby_gem/README.md @@ -0,0 +1,31 @@ +# RubyGem + +TODO: Delete this and the text below, and describe your gem + +Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruby_gem`. To experiment with that code, run `bin/console` for an interactive prompt. + +## Installation + +TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org. + +Install the gem and add to the application's Gemfile by executing: + + $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG + +If bundler is not being used to manage dependencies, install the gem by executing: + + $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG + +## Usage + +TODO: Write usage instructions here + +## Development + +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. + +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby_gem. diff --git a/src/ruby_gem/Rakefile b/src/ruby_gem/Rakefile new file mode 100644 index 0000000..cca7175 --- /dev/null +++ b/src/ruby_gem/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[spec rubocop] diff --git a/src/ruby_gem/bin/console b/src/ruby_gem/bin/console new file mode 100755 index 0000000..aab7684 --- /dev/null +++ b/src/ruby_gem/bin/console @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "ruby_gem" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +require "irb" +IRB.start(__FILE__) diff --git a/src/ruby_gem/bin/setup b/src/ruby_gem/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/src/ruby_gem/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/src/ruby_gem/lib/ruby_gem.rb b/src/ruby_gem/lib/ruby_gem.rb new file mode 100644 index 0000000..cd7eb13 --- /dev/null +++ b/src/ruby_gem/lib/ruby_gem.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require_relative "ruby_gem/version" + +module RubyGem + class Error < StandardError; end + # Your code goes here... +end diff --git a/src/ruby_gem/lib/ruby_gem/version.rb b/src/ruby_gem/lib/ruby_gem/version.rb new file mode 100644 index 0000000..cb71fc5 --- /dev/null +++ b/src/ruby_gem/lib/ruby_gem/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module RubyGem + VERSION = "0.1.0" +end diff --git a/src/ruby_gem/ruby_gem.gemspec b/src/ruby_gem/ruby_gem.gemspec new file mode 100644 index 0000000..b453646 --- /dev/null +++ b/src/ruby_gem/ruby_gem.gemspec @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require_relative "lib/ruby_gem/version" + +Gem::Specification.new do |spec| + spec.name = "ruby_gem" + spec.version = RubyGem::VERSION + spec.authors = ["Fabio Pitino"] + spec.email = ["fpitino@gitlab.com"] + + spec.summary = "TODO: Write a short summary, because RubyGems requires one." + spec.description = "TODO: Write a longer description or delete this line." + spec.homepage = "TODO: Put your gem's website or public repo URL here." + spec.required_ruby_version = ">= 2.6.0" + + spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." + spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(__dir__) do + `git ls-files -z`.split("\x0").reject do |f| + (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor]) + end + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + # Uncomment to register a new dependency of your gem + # spec.add_dependency "example-gem", "~> 1.0" + + # For more information and examples about making a new gem, check out our + # guide at: https://bundler.io/guides/creating_gem.html +end diff --git a/src/ruby_gem/sig/ruby_gem.rbs b/src/ruby_gem/sig/ruby_gem.rbs new file mode 100644 index 0000000..dd9819b --- /dev/null +++ b/src/ruby_gem/sig/ruby_gem.rbs @@ -0,0 +1,4 @@ +module RubyGem + VERSION: String + # See the writing guide of rbs: https://github.com/ruby/rbs#guides +end diff --git a/src/ruby_gem/spec/ruby_gem_spec.rb b/src/ruby_gem/spec/ruby_gem_spec.rb new file mode 100644 index 0000000..998b0db --- /dev/null +++ b/src/ruby_gem/spec/ruby_gem_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +RSpec.describe RubyGem do + it "has a version number" do + expect(RubyGem::VERSION).not_to be nil + end + + it "does something useful" do + expect(false).to eq(true) + end +end diff --git a/src/ruby_gem/spec/spec_helper.rb b/src/ruby_gem/spec/spec_helper.rb new file mode 100644 index 0000000..ddf610e --- /dev/null +++ b/src/ruby_gem/spec/spec_helper.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "ruby_gem" + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end