Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GHA CI workflow #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be independent. Often a reason to make it depend on others is to save on CI costs, but the rename is very cheap. In fact, I would probably turn it around: make the tests depend on renaming.

runs-on: ubuntu-latest

env:
PLUGIN_NAME: foreman_plugin_template
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly the same name as the template, so a rename is not going to do anything.

FILES_TO_CHECK: "README.md,.github/workflows/ci.yml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also check if a file rename worked. For example, you could check that find -name '*foreman_plugin_template*' doesn't show any files and verify the new files do exist.


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also assert that foreman_plugin_template, ForemanPluginTemplate and foremanPluginTemplate do not show up anymore.

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}))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should now fix this issue: #63

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like it if it was at least a separate commit for visibility.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you drop this comment?

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
Loading