diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..aa084a8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +on: + pull_request: + push: + branches: + - master + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + rubocop: + name: Rubocop + uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + with: + command: bundle exec rubocop --parallel --format github + + test: + name: Ruby Tests + needs: rubocop + uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0 + with: + plugin: foreman_plugin_template + + rename_test: + name: Rename Script Test + needs: [rubocop, test] + runs-on: ubuntu-latest + + env: + PLUGIN_NAME: foreman_plugin_template + FILES_TO_CHECK: "README.md,.github/workflows/ci.yml" + + steps: + - name: Run rename.rb + run: | + ./rename.rb $PLUGIN_NAME + + - name: Verify Renaming + run: | + IFS=',' read -r -a files <<< "$FILES_TO_CHECK" + + for file in "${files[@]}"; do + if [ ! -f "$file" ]; then + echo "$file not found!" + exit 1 + fi + + if ! grep -q "$PLUGIN_NAME" "$file"; then + echo "Expected content not found in $file" + exit 1 + fi + done + + echo "All files renamed successfully and content verified!" diff --git a/.github/workflows/ci.yml.tpl b/.github/workflows/ci.yml.tpl new file mode 100644 index 0000000..a9c824f --- /dev/null +++ b/.github/workflows/ci.yml.tpl @@ -0,0 +1,25 @@ +name: CI + +on: + pull_request: + push: + branches: + - master + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + rubocop: + name: Rubocop + uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + with: + command: bundle exec rubocop --parallel --format github + + test: + name: Ruby + needs: rubocop + uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0 + with: + plugin: foreman_plugin_template diff --git a/lib/tasks/foreman_plugin_template_tasks.rake b/lib/tasks/foreman_plugin_template_tasks.rake index 48c73c8..35cb619 100644 --- a/lib/tasks/foreman_plugin_template_tasks.rake +++ b/lib/tasks/foreman_plugin_template_tasks.rake @@ -41,8 +41,3 @@ namespace :foreman_plugin_template do end Rake::Task[:test].enhance ['test:foreman_plugin_template'] - -load 'tasks/jenkins.rake' -if Rake::Task.task_defined?(:'jenkins:unit') - Rake::Task['jenkins:unit'].enhance ['test:foreman_plugin_template', 'foreman_plugin_template:rubocop'] -end diff --git a/rename.rb b/rename.rb index 029923f..3967e75 100755 --- a/rename.rb +++ b/rename.rb @@ -29,26 +29,20 @@ def usage exit 1 end -old_dirs = [] Find.find('.') do |path| - next unless File.file?(path) - next if path =~ /\.git/ - next if path == './rename.rb' - - # Change content on all files - tmp_file = "#{path}.tmp" - system(%(sed 's/foreman_plugin_template/#{snake}/g' #{path} > #{tmp_file})) - system(%(sed 's/ForemanPluginTemplate/#{camel}/g' #{tmp_file} > #{path})) - system(%(sed 's/foremanPluginTemplate/#{camel_lower}/g' #{tmp_file} > #{path})) - system(%(rm #{tmp_file})) + if File.basename(path) == '.git' + Find.prune + elsif File.file?(path) + system(%(sed -i 's/foreman_plugin_template/#{snake}/g; s/ForemanPluginTemplate/#{camel}/g; s/foremanPluginTemplate/#{camel_lower}/g' #{path})) + end end +old_dirs = [] Find.find('.') do |path| # Change all the paths to the new snake_case name if path =~ /foreman_plugin_template/i new = path.gsub('foreman_plugin_template', snake) # Recursively copy the directory and store the original for deletion - # Check for $ because we don't need to copy template/hosts for example if File.directory?(path) && path =~ /foreman_plugin_template$/i FileUtils.cp_r(path, new) old_dirs << path @@ -63,6 +57,7 @@ def usage FileUtils.rm_rf(old_dirs) FileUtils.mv('README.plugin.md', 'README.md') +FileUtils.mv('.github/workflows/ci.yml.tpl', '.github/workflows/ci.yml') puts 'All done!' puts "Add this to Foreman's bundler configuration:"