Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: React Testing

on:
pull_request:
paths:
- 'webpack/**'
- 'package.json'
- '.github/workflows/react.yml'
- '*.js'
push:
branches:
- master

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
Test:
# The type of runner that the job will run on
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [12]
foreman-core-branch: ['develop', '2.5-stable', '2.4-stable']

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: theforeman/foreman
ref: ${{ matrix.foreman-core-branch }}
path: foreman

- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: npm install
run: |
npm install
cd foreman; npm install; cd -

- name: Lint Stylesheets
run: npm run stylelint
- name: Lint Javascript
run: npm run lint
- name: Test
run: npm run test
...
89 changes: 89 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
name: Ruby Testing

# Controls when the action will run.
on:
pull_request:
push:
branches:
- master

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
BUNDLE_WITHOUT: journald:development:console:libvirt
RAILS_ENV: test
DATABASE_URL: postgresql://postgres:@localhost/test
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true

jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
bundler-cache: true
- name: Run rubocop
run: bundle exec rubocop

ruby-test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: rubocop
services:
postgres:
image: postgres:12.1
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

strategy:
fail-fast: false
matrix:
ruby-version: ['2.7']
foreman-core-branch: ['develop', '2.5-stable', '2.4-stable']
proxmox: ['~>0.13.3']

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Install build packages
run: |
sudo apt-get update
sudo apt-get install build-essential libcurl4-openssl-dev zlib1g-dev libpq-dev

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
repository: theforeman/foreman
ref: ${{ matrix.foreman-core-branch }}

- uses: actions/checkout@v2
with:
path: foreman_snapshot_management

- name: Setup Bundler
run: |
echo "gem 'foreman_fog_proxmox', '${{ matrix.proxmox }}'" > bundler.d/proxmox.rb
echo "gem 'foreman_snapshot_management', path: './foreman_snapshot_management'" > bundler.d/foreman_snapshot_mgmt.local.rb

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Prepare test env
if: github.event_name != 'push'
run: |
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:test:prepare

- name: Run plugin tests
if: github.event_name != 'push'
run: |
bundle exec rake test:foreman_snapshot_management
...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ Gemfile.lock
*.gem
locale/*/*.edit.po
locale/*/*.po.time_stamp
node_modules
package-lock.json
108 changes: 59 additions & 49 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,84 @@

require:
- rubocop-performance
- rubocop-rails
- rubocop-minitest

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.5
TargetRailsVersion: 5.2
Exclude:
- 'locale/**/*'
- 'node_modules/**/*'
- 'vendor/**/*'
- '*.spec'
- 'doc/plugins/**'

Rails/Date:
Exclude:
- 'foreman_snapshot_management.gemspec'

Rails:
Enabled: True
Layout/LineLength:
Max: 190

Rails/FindEach:
Exclude:
- 'app/models/foreman_snapshot_management/vmware_extensions.rb'
Metrics/AbcSize:
Enabled: false

# Don't enforce documentation
Style/Documentation:
Metrics/BlockLength:
Enabled: false

Metrics/ClassLength:
Max: 500

Metrics/MethodLength:
Max: 40

Naming/AccessorMethodName:
Metrics/ModuleLength:
Max: 400

Metrics/ParameterLists:
Enabled: false

Style/RedundantSelf:
Metrics/PerceivedComplexity:
Enabled: false

Metrics/ClassLength:
Max: 500
Naming/AccessorMethodName:
Enabled: false

Naming/FileName:
Exclude:
- 'db/seeds.d/*'

Style/WordArray:
Enabled: false
Naming/MethodName:
Exclude:
- 'app/models/concerns/orchestration/*.rb'

Style/BracesAroundHashParameters:
Enabled: false
Rails:
Enabled: True

Style/RescueModifier:
Rails/Date:
Exclude:
- 'foreman_snapshot_management.gemspec'

Rails/FindEach:
Exclude:
- 'app/models/foreman_snapshot_management/vmware_extensions.rb'

Style/CaseEquality:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

# Don't enforce documentation
Style/Documentation:
Enabled: false

Style/EachWithObject:
Enabled: false

Metrics/ParameterLists:
Style/FormatString:
Enabled: false

Style/FormatStringToken:
Enabled: false

Style/GuardClause:
Enabled: false

# Support both ruby19 and hash_rockets
Expand All @@ -60,41 +88,23 @@ Style/HashSyntax:
- ruby19
- hash_rockets

Metrics/LineLength:
Max: 190

# Offense count: 21
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 400

Naming/MethodName:
Exclude:
- 'app/models/concerns/orchestration/*.rb'

Style/SymbolArray:
Enabled: false

Style/FormatString:
Enabled: false

Style/FormatStringToken:
Style/RedundantSelf:
Enabled: false

Style/RegexpLiteral:
Enabled: false

Metrics/AbcSize:
Style/RescueModifier:
Enabled: false

Metrics/BlockLength:
Enabled: false
Style/StringLiterals:
Exclude:
- 'Gemfile'
- '*.gemspec'

Metrics/PerceivedComplexity:
Style/SymbolArray:
Enabled: false

Style/CaseEquality:
Style/WordArray:
Enabled: false

Style/GuardClause:
Enabled: false
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
source 'https://rubygems.org'

gemspec

gem 'rdoc', '~> 5.1'
gem "rubocop", "~> 0.89.0"
gem "rubocop-minitest", "~> 0.10.3"
gem "rubocop-performance", "~> 1.8"
gem "rubocop-rails", "~> 2.8"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/ATIX-AG/foreman_snapshot_management.svg?branch=master)](https://travis-ci.org/ATIX-AG/foreman_snapshot_management)
[![React Testing](https://github.com/ATIX-AG/foreman_snapshot_management/actions/workflows/react.yml/badge.svg)](https://github.com/ATIX-AG/foreman_snapshot_management/actions/workflows/react.yml)
[![Ruby Testing](https://github.com/ATIX-AG/foreman_snapshot_management/actions/workflows/ruby.yml/badge.svg)](https://github.com/ATIX-AG/foreman_snapshot_management/actions/workflows/ruby.yml)

# ForemanSnapshotManagement

Expand All @@ -22,6 +23,7 @@ See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wi

| Foreman Version | Plugin Version |
| --------------- | -------------- |
| 2.3 | >= 2.0.0 |
| 1.24 | >= 1.7.0 |
| 1.23 | >= 1.7.0 |
| 1.22 | >= 1.6.0 |
Expand Down
9 changes: 7 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ rescue LoadError
RDoc::Task = Rake::RDocTask
end

begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue StandardError => _e
puts 'Rubocop not loaded.'
end

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'ForemanSnapshotManagement'
Expand All @@ -22,6 +29,4 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)

Bundler::GemHelper.install_tasks
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def capabilities
# This method creates a Snapshot with a given name and optional description.
def create_snapshot(host, name, description, _include_ram = false)
server = find_vm_by_uuid host.uuid
raise _('Name must contain at least 2 characters starting with alphabet. Valid characters are A-Z a-z 0-9 _') unless name =~ /^[A-Za-z][\w]{1,}$/
raise _('Name must contain at least 2 characters starting with alphabet. Valid characters are A-Z a-z 0-9 _') unless /^[A-Za-z][\w]{1,}$/.match?(name)

snapshot = server.snapshots.create(name: name)
snapshot.description = description
Expand Down
4 changes: 4 additions & 0 deletions app/models/foreman_snapshot_management/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def self.model_name
)
end

def self.any?
true
end

def self.new_for_host(host)
host.compute_resource.new_snapshot(host)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v2/snapshots/base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ object @snapshot

attributes :id, :name

node(:formatted_created_at){|snapshot| snapshot.create_time&.httpdate}
node(:formatted_created_at) { |snapshot| snapshot.create_time&.httpdate }
3 changes: 1 addition & 2 deletions foreman_snapshot_management.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ Gem::Specification.new do |s|
s.files = Dir['{app,config,db,lib,locale,webpack}/**/*'] + ['LICENSE', 'package.json', 'Rakefile', 'README.md']
s.test_files = Dir['test/**/*']

s.add_development_dependency 'rdoc', '~> 5.1'
s.add_development_dependency 'rubocop', '~> 0.75.0'
s.required_ruby_version = '>= 2.5'
end
Loading