image: "ruby:3.2.2"

stages:
  - release
  - test

before_script:
  - gem install bundler --no-document
  - bundle install --jobs $(nproc)  "${FLAGS[@]}"

rspec:
  script:
    - bundle exec rspec

rubocop:
  script:
    - bundle exec rubocop

release:
  stage: release
  rules:
    - if: '$CI_COMMIT_TAG'
  script:
    - mkdir -p ~/.gem
    - cp $RUBYGEMS_CREDENTIALS ~/.gem/credentials
    - chmod 0600 ~/.gem/credentials
    - gem update --system
    - ruby --version
    - gem env version
    - sed -i "s/0.0.0/$CI_COMMIT_TAG/g" lib/nexus_semantic_logger/version.rb
    - gem build nexus_semantic_logger.gemspec
    - gem push nexus_semantic_logger*.gem
  artifacts:
    paths:
      - nexus_semantic_logger*.gem
    expire_in: 30 days
