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 new commands: execute and push #199

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ca4d190
Remove monkey-patch related to UTF-8 issues on Git::Diff class
neomilium Dec 20, 2020
731b3fd
Remove monkey-patch related to ls-files
neomilium Dec 20, 2020
47e1ae4
Tests: Implement a Puppet module remote repository faker
neomilium Dec 19, 2020
b428d1f
Cucumber: Setup the use of the Faker module
neomilium Dec 19, 2020
7edefbb
Tests: Provide new steps to use PuppetModuleRemoteRepo faker
neomilium Dec 19, 2020
fee8ee7
Tests: Set git identity to "Aruba <aruba@example.com"
neomilium Dec 19, 2020
cb54f08
Tests: Improve behavior tests scenarios by using PuppetModuleRemoteRe…
neomilium Dec 19, 2020
8d814d2
Tests: Remove unused steps
neomilium Dec 19, 2020
b481c94
Tests: Rename maestrodev namespace to fakenamespace
neomilium Dec 19, 2020
1d43994
Tests: Replace cat usage by aruba file matcher
neomilium Dec 19, 2020
02bd978
Tests: Provide a step to setup a msync with one puppet module
neomilium Dec 19, 2020
79c0759
Cucumber: Silent message about publishing results
neomilium Dec 19, 2020
6084765
Refactor ModuleSync#update in order to reuse code base
neomilium Dec 20, 2020
ffffc53
Reuse exception message if available
neomilium Dec 20, 2020
61c8445
FIXUP Refactor
neomilium Dec 20, 2020
c1ae58d
Set default value of remote-branch to branch according to help
neomilium Dec 15, 2020
aae9d88
CLI: Add new command to push a specified branch for each managed module
mtancoigne Dec 15, 2020
ed80a45
README: Add section for "push" command
neomilium Dec 15, 2020
58986c2
Refactor Git#pull for reusability and readability
neomilium Dec 16, 2020
1e29b9d
CLI: Add new command to execute a script on each managed module
neomilium Dec 15, 2020
f44757a
README: Add section for "execute" command
neomilium Dec 15, 2020
5942b00
CLI: Add reset-hard option to "update" command
neomilium Dec 16, 2020
647d9bd
Tests: Add minimal behaviour tests for "execute" command
neomilium Dec 17, 2020
e5f7d6f
RENAME to compute_module_naming_attributes BEFORE execute
neomilium Dec 20, 2020
f0bdbdb
RENAME to compute_module_naming_attributes for PUSH
neomilium Dec 20, 2020
bf891b5
RENAME to compute_module_naming_attributes for EXECUTE
neomilium Dec 20, 2020
19fa8bf
REWORK compute_naming_attrs
neomilium Dec 20, 2020
c81b340
compute_naming_attrs for push
neomilium Dec 20, 2020
e3714a9
compute_naming_attrs for execute
neomilium Dec 20, 2020
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
1 change: 1 addition & 0 deletions .config/cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default: --publish-quiet
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Layout/IndentHeredoc:
# sane line length
Metrics/LineLength:
Max: 120
Exclude:
- 'features/**/*'

Style/FrozenStringLiteralComment:
Enabled: false
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Table of Contents
4. [Installing](#installing)
5. [Workflow](#workflow)
6. [The Templates](#the-templates)
7. [Additional features](#additional-features)

Usage TLDR
----------
Expand Down Expand Up @@ -436,3 +437,38 @@ The Templates

See [Puppet's modulesync\_configs](https://github.com/puppetlabs/modulesync_configs) and [Vox Pupuli's modulesync\_config](https://github.com/voxpupuli/modulesync_config)
repositories for different templates currently in use.

Additional features
-------------------

## Execute a custom script on each module

During puppet modules maintenance, you may want to run a custom script to modify, add or deleted files then commit modifications.

As example, if you want to generate REFERENCES.md, CHANGELOG.md or update your module to be PDK compliant, this command could be useful.

```shell
msync exec /path/to/script --branch my-new-feature
```

**Important**: Please note that it is up to your script to modify correctly the repository (e.g. `git mv old-path new-path`, `git add my-file`) and performs the commits (ie. `git commit -m'Set a smart commit message here'`).

Like `update` command, you can push and submit a PR/MR using the same options:

```shell
msync exec /path/to/script --branch my-new-feature --push --pr --pr-title "Add a new super feature"
```

## Push manually a branch for each module

After a regular `msync update` without push, you may want to add some commits manually then push.

```shell
msync push --branch my-specific-branch
```

Like `update` command, you can submit a PR/MR using the same options:

```shell
msync push --branch my-specific-feature-branch --pr --pr-title "Add a new super feature"
```
19 changes: 6 additions & 13 deletions features/cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@ Feature: CLI
And the output should match /Commands:/

Scenario: When overriding a setting from the config file on the command line
Given a file named "managed_modules.yml" with:
"""
---
- puppet-test
"""
And a file named "modulesync.yml" with:
"""
---
namespace: maestrodev
git_base: 'git@github.com:'
"""
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"
And a directory named "moduleroot"
When I run `msync update --noop --git-base https://github.com/`
When I run `msync update --noop --namespace fakenamespace`
Then the exit status should be 0
And the output should not match /git@github.com:/
And the stdout should contain:
"""
Syncing 'fakenamespace/puppet-test'
"""
25 changes: 25 additions & 0 deletions features/execute.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: execute
Use ModuleSync to execute a custom script on a specified branch for each repos and optionaly push and submit a PR/MR

Scenario: Running command without required 'branch' option
When I run `msync exec`
Then the output should match /^No value provided for required options '--branch'$/

Scenario: Cloning modules before running command when modules/ dir is empty
Given a basic setup with a puppet module "puppet-test" from "awesome"
Then the file "modules/awesome/puppet-test/metadata.json" should not exist
When I run `msync exec -b master /bin/true`
Then the exit status should be 0
And the file "modules/awesome/puppet-test/metadata.json" should exist

@no-clobber
Scenario: Hard-reset on specified branch before running command when modules have already been cloned
Given the file "modules/awesome/puppet-test/metadata.json" should exist
And the file "modules/awesome/puppet-test/hello" should not exist
And the puppet module "puppet-test" from "awesome" have a branch "execute"
And the puppet module "puppet-test" from "awesome" have a file named "hello" on branch "execute" with:
"""
Hello
"""
When I run `msync exec -b master --reset-hard origin/execute /bin/true`
And the file "modules/awesome/puppet-test/hello" should exist
8 changes: 3 additions & 5 deletions features/hook.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: hook
Given a directory named ".git/hooks"
When I run `msync hook activate`
Then the exit status should be 0
Given I run `cat .git/hooks/pre-push`
Then the output should contain "bash"
And the file named ".git/hooks/pre-push" should contain "bash"

Scenario: Deactivating a hook
Given a file named ".git/hooks/pre-push" with:
Expand All @@ -21,8 +20,7 @@ Feature: hook
Given a directory named ".git/hooks"
When I run `msync hook activate -a '--foo bar --baz quux' -b master`
Then the exit status should be 0
Given I run `cat .git/hooks/pre-push`
Then the output should match:
And the file named ".git/hooks/pre-push" should contain:
"""
"\$message" -n puppetlabs -b master --foo bar --baz quux
"$message" -n puppetlabs -b master --foo bar --baz quux
"""
15 changes: 15 additions & 0 deletions features/push.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: push
Use ModuleSync to push a specified branch from each repos and optionaly submit a PR/MR

Scenario: When 'branch' option is missing
When I run `msync push`
Then the output should match /^No value provided for required options '--branch'$/

Scenario: Report the need to clone repositories if puppet module have not been fetch before
Given a basic setup with a puppet module "puppet-test" from "awesome"
When I run `msync push --branch hello`
Then the exit status should be 1
And the stderr should contain:
"""
Repository must be locally available before trying to push
"""
109 changes: 73 additions & 36 deletions features/step_definitions/git_steps.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,85 @@
Given 'a mocked git configuration' do
steps %(
Given a mocked home directory
And I run `git config --global user.name Test`
And I run `git config --global user.email test@example.com`
)
end
require_relative '../../spec/helpers/faker/puppet_module_remote_repo'

Given 'a remote module repository' do
Given 'a basic setup with a puppet module {string} from {string}' do |name, namespace|
steps %(
Given a directory named "sources"
And I run `git clone https://github.com/maestrodev/puppet-test sources/puppet-test`
Given a mocked git configuration
And a puppet module "#{name}" from "#{namespace}"
And a file named "managed_modules.yml" with:
"""
---
- puppet-test
- #{name}
"""
And a file named "modulesync.yml" with:
"""
---
namespace: #{namespace}
"""
And a git_base option appended to "modulesync.yml" for local tests
)
write_file('modulesync.yml', <<~CONFIG)
---
namespace: sources
git_base: file://#{expand_path('.')}/
CONFIG
end

Given Regexp.new(/a remote module repository with "(.+?)" as the default branch/) do |branch|
Given 'a mocked git configuration' do
steps %(
Given a directory named "sources"
And I run `git clone --mirror https://github.com/maestrodev/puppet-test sources/puppet-test`
And a file named "managed_modules.yml" with:
"""
---
- puppet-test
"""
Given a mocked home directory
And I run `git config --global user.name Aruba`
And I run `git config --global user.email aruba@example.com`
)
write_file('modulesync.yml', <<~CONFIG)
---
namespace: sources
git_base: file://#{expand_path('.')}/
CONFIG

cd('sources/puppet-test') do
steps %(
And I run `git branch -M master #{branch}`
And I run `git symbolic-ref HEAD refs/heads/#{branch}`
)
end
end

Given 'a puppet module {string} from {string}' do |name, namespace|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.populate
end

Given 'a git_base option appended to "modulesync.yml" for local tests' do
File.write "#{Aruba.config.working_directory}/modulesync.yml", "\ngit_base: #{Faker::PuppetModuleRemoteRepo.git_base}", mode: 'a'
end

Given 'the puppet module {string} from {string} is read-only' do |name, namespace|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.read_only = true
end

Then 'the puppet module {string} from {string} have no commit between {string} and {string}' do |name, namespace, commit1, commit2|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.commit_count_between(commit1, commit2)).to eq 0
end

Then 'the puppet module {string} from {string} have( only) {int} commit(s) made by {string}' do |name, namespace, commit_count, author|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.commit_count_by(author)).to eq commit_count
end

Then 'the puppet module {string} from {string} have( only) {int} commit(s) made by {string} in branch {string}' do |name, namespace, commit_count, author, branch|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.commit_count_by(author, branch)).to eq commit_count
end

Then 'the puppet module {string} from {string} have no commit made by {string}' do |name, namespace, author|
step "the puppet module \"#{name}\" from \"#{namespace}\" have 0 commit made by \"#{author}\""
end

Given 'the puppet module {string} from {string} have a file named {string} with:' do |name, namespace, filename, content|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.add_file(filename, content)
end

Given 'the puppet module {string} from {string} have a file named {string} on branch {string} with:' do |name, namespace, filename, branch, content|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.add_file(filename, content, branch)
end

Then 'the puppet module {string} from {string} should have a branch {string} with a file named {string} which contains:' do |name, namespace, branch, filename, content|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.read_file(filename, branch)).to include(content)
end

Given 'the puppet module {string} from {string} have the default branch named {string}' do |name, namespace, default_branch|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.default_branch = default_branch
end

Given 'the puppet module {string} from {string} have a branch {string}' do |name, namespace, branch|
pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.create_branch(branch)
end
4 changes: 4 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'aruba/cucumber'

require_relative '../../spec/helpers/faker'

Faker.working_directory = File.expand_path("#{Aruba.config.working_directory}/faker")

Before do
@aruba_timeout_seconds = 5
end
Loading