-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also assert that |
||
echo "Expected content not found in $file" | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "All files renamed successfully and content verified!" |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should now fix this issue: #63 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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:" | ||
|
There was a problem hiding this comment.
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.