Skip to content

Commit

Permalink
Add GHA CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
archanaserver committed Oct 18, 2024
1 parent b97f971 commit 58f614d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 17 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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!"
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml.tpl
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions lib/tasks/foreman_plugin_template_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 7 additions & 12 deletions rename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:"
Expand Down

0 comments on commit 58f614d

Please sign in to comment.