Skip to content

Commit b421391

Browse files
author
Kevin Paulisse
committed
Merge remote-tracking branch 'origin/master' into kpaulisse-environment
2 parents 330035b + 30eb257 commit b421391

11 files changed

Lines changed: 177 additions & 22 deletions

File tree

doc/advanced-catalog-validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ file { '/usr/local/bin/some-script.sh':
2121

2222
The catalog for this code would build, whether or not the `exec { 'execute /usr/local/bin/some-script.sh': ... }` resource was part of the catalog. However, when the catalog is applied on the Puppet agent, it would fail if this resource is missing.
2323

24-
With the `--validate-references` command line flag (or the `settings[:validate_references]` [configuration setting](/doc/configuration.md), you can instruct `octocatalog-diff` to confirm that any resource targeted by a `before`, `notify`, `require`, and `subscribe` parameter actually exists. If the resource is missing from the catalog, an error will be raised, just as if the catalog failed to compile.
24+
With the `--validate-references` command line flag (or the `settings[:validate_references]` [configuration setting](/doc/configuration.md)), you can instruct `octocatalog-diff` to confirm that any resource targeted by a `before`, `notify`, `require`, and `subscribe` parameter actually exists. If the resource is missing from the catalog, an error will be raised, just as if the catalog failed to compile.
2525

2626
The command line argument is demonstrated here:
2727

doc/dev/releasing.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,47 @@
22

33
The project maintainers are responsible for bumping the version number, regenerating auto-generated documentation, tagging the release, and uploading to rubygems.
44

5-
0. Ensure that all changes have been merged to master.
5+
## Local testing
6+
7+
To test the new version of `octocatalog-diff` in the Puppet repository:
8+
9+
0. In the Puppet checkout, start a new branch based off master.
10+
0. In the `octocatalog-diff` checkout:
11+
- Ensure that the desired branch is checked out.
12+
- Choose a unique internal version number which has never been used in CI. A good guideline is that if you're planning to release a version `0.6.0` then for these tests, use `0.6.0a`, `0.6.0b`, ...
13+
- Build the gem using your internal version number:
14+
15+
```
16+
OCTOCATALOG_DIFF_VERSION=0.6.0a rake gem:force-build
17+
```
18+
- Run the task to install the gem into your Puppet checkout:
19+
20+
```
21+
OCTOCATALOG_DIFF_VERSION=0.6.0a rake gem:localinstall
22+
```
23+
24+
0. Back in the Puppet checkout, ensure that the changes are as expected (updates to Gemfile / Gemfile.lock, addition of new gem). Push the change and build appropriate CI job(s) to validate the changes.
25+
26+
## Merging
27+
628
0. If necessary, complete a Pull Request to update the [version file](/.version).
29+
0. If necessary, auto-generate the build documentation.
30+
31+
```
32+
rake doc:build
33+
```
34+
35+
0. Ensure that CI tests are all passing.
36+
0. Merge and delete the branch.
37+
38+
## Releasing
39+
40+
Generally, a new release will correspond to a merge to master of one or more Pull Requests.
41+
42+
0. Ensure that all changes associated with the release have been merged to master.
43+
- Merge all Pull Requests associated with release.
44+
- If necessary, complete a Pull Request to update the [change log](/doc/CHANGELOG.md).
45+
- If necessary (for significant changes), complete a Pull Request to update the top-level README file.
746
0. Ensure the the master branch is checked out on your system.
847
0. Run the release procedure:
948
@@ -13,7 +52,6 @@ The project maintainers are responsible for bumping the version number, regenera
1352
1453
This rake task handles the following:
1554
16-
- Auto-generates the [options reference](/doc/optionsref.md) (`rake doc:build`)
1755
- Build the gem file (`rake gem:build`)
1856
- Tag the release in the repository (`rake gem:tag`)
1957
- Upload the gem file to rubygems (`rake gem:push`)

doc/dev/run-from-branch.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Running octocatalog-diff from a branch
2+
3+
When we are assisting with troubleshooting, or implementing a feature you've requested, we may ask you to run `octocatalog-diff` from a non-master branch to try it out.
4+
5+
This document is intended for people who may not be familiar with git, GitHub, and/or ruby. If you already know how to do this in another way, feel free!
6+
7+
## Installation
8+
9+
1. Determine the branch name. If there's an open Pull Request, you can see the branch name near the top of the page.
10+
11+
![Pull Request branch](/doc/images/pull-request-identify-branch.png)
12+
13+
2. Clone the `octocatalog-diff` repository in your home directory. From the command line:
14+
15+
```
16+
cd $HOME
17+
git clone https://github.com/github/octocatalog-diff.git
18+
```
19+
20+
3. Change into the directory created by your checkout:
21+
22+
```
23+
cd $HOME/octocatalog-diff
24+
```
25+
26+
4. Check out the branch you wish to use, filling in the branch name you determined in the first step:
27+
28+
```
29+
git checkout BRANCH_NAME_FROM_STEP_1
30+
```
31+
32+
5. Bootstrap the repository to pull in dependencies:
33+
34+
```
35+
./script/bootstrap
36+
```
37+
38+
6. Optional but recommended - run the test suite:
39+
40+
```
41+
rake
42+
```
43+
44+
## Use
45+
46+
Now that you have `octocatalog-diff` checked out and bootstrapped, it's time to use it.
47+
48+
We've created a wrapper script to make this easier for you.
49+
50+
1. Change directories to the location where you ordinarily run `octocatalog-diff` (for example: in your Puppet repository).
51+
52+
```
53+
cd /etc/puppetlabs/code
54+
```
55+
56+
2. Run the `script/octocatalog-diff-wrapper` script from *this* checkout. For example, if you checked out `octocatalog-diff` to your home directory, you could use:
57+
58+
```
59+
$HOME/octocatalog-diff/script/octocatalog-diff-wrapper <options>
60+
```
61+
62+
:warning: Note: If you are requesting our help, please use the debug option (`-d`) to display debugging information.
75.6 KB
Loading

doc/installation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ To install from source, you'll need a git client and internet access.
4747
Note: If tests fail on your machine with a clean checkout of the master branch, we would definitely appreciate if you would report it. Please [open an issue](https://github.com/github/octocatalog-diff/issues/new) with the output and some information about your system (e.g. OS, ruby version, etc.) to let us know.
4848

4949
Once the code is downloaded and bootstrapped, please proceed to [Configuration](/doc/configuration.md).
50+
51+
## Running from an alternate branch
52+
53+
We have prepared specific instructions for running `octocatalog-diff` from a non-master branch, for testing changes that may be requested by the developers.
54+
55+
- [Running octocatalog-diff from a branch](/doc/dev/run-from-branch.md)

lib/octocatalog-diff/catalog-diff/cli.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def self.setup_logger(logger, options, argv_save)
166166
logger.level = Logger::ERROR if options[:quiet]
167167

168168
# Some debugging information up front
169-
logger.debug "Running octocatalog-diff #{VERSION} with ruby #{RUBY_VERSION}"
169+
version_display = ENV['OCTOCATALOG_DIFF_CUSTOM_VERSION'] || VERSION
170+
logger.debug "Running octocatalog-diff #{version_display} with ruby #{RUBY_VERSION}"
170171
logger.debug "Command line arguments: #{argv_save.inspect}"
171172
logger.debug "Running on host #{Socket.gethostname} (#{RUBY_PLATFORM})"
172173
end

lib/octocatalog-diff/catalog.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,11 @@ def validate_references
198198
@options[:validate_references].each do |r|
199199
next unless x.key?('parameters')
200200
next unless x['parameters'].key?(r)
201-
missing_resources = remove_existing_resources(x['parameters'][r])
202-
missing << missing_resources.map { |missing_target| { source: x, target_type: r, target_value: missing_target } }
201+
missing_resources = resources_missing_from_catalog(x['parameters'][r])
202+
next unless missing_resources.any?
203+
missing.concat missing_resources.map { |missing_target| { source: x, target_type: r, target_value: missing_target } }
203204
end
204205
end
205-
missing.flatten!
206-
missing.compact!
207206
return if missing.empty?
208207

209208
# At this point there is at least one broken/missing reference. Format an error message and
@@ -229,20 +228,18 @@ def validate_references
229228

230229
private
231230

232-
# Private method: Determine if a catalog contains resource or resources, which may
233-
# have been passed in as an array or a string. Return the references to resources
234-
# that are missing from the catalog. (An empty array would indicate all references
235-
# are present.)
231+
# Private method: Given a list of resources to check, return the references from
232+
# that list that are missing from the catalog. (An empty array returned would indicate
233+
# all references are present in the catalog.)
236234
# @param resources_to_check [String / Array] Resources to check
237235
# @return [Array] References that are missing from catalog
238-
def remove_existing_resources(resources_to_check)
239-
rtc_array = resources_to_check.is_a?(Array) ? resources_to_check : [resources_to_check]
240-
rtc_array.map do |res|
236+
def resources_missing_from_catalog(resources_to_check)
237+
[resources_to_check].flatten.select do |res|
241238
unless res =~ /\A([\w:]+)\[(.+)\]\z/
242239
raise ArgumentError, "Resource #{res} is not in the expected format"
243240
end
244-
resource(type: Regexp.last_match(1), title: Regexp.last_match(2)).nil? ? res : nil
245-
end.compact
241+
resource(type: Regexp.last_match(1), title: Regexp.last_match(2)).nil?
242+
end
246243
end
247244

248245
# Private method: Choose backend based on passed-in options

rake/gem.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ def self.build(target = GEMFILE)
4343

4444
# Push the gem to rubygems
4545
def self.push
46+
raise 'Cannot push version that does not match .version file' unless version == OctocatalogDiff::Version::VERSION
4647
raise "The gem file doesn't exist: #{FINAL_GEMFILE}" unless File.file?(FINAL_GEMFILE)
4748
exec_command("gem push #{Shellwords.escape(FINAL_GEMFILE)}")
4849
end
4950

5051
# Tag the release on GitHub
5152
def self.tag
53+
raise 'Cannot tag version that does not match .version file' unless version == OctocatalogDiff::Version::VERSION
54+
5255
# Make sure we have not released this version before
5356
exec_command('git fetch -t origin')
5457
tags = exec_command('git tag -l').split(/\n/)

script/octocatalog-diff-wrapper

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# This script exists to make it easier to test alternate branches of octocatalog-diff.
4+
# It is intended as a one-for-one replacement of `octocatalog-diff` as installed by the gem.
5+
6+
CURRENT_PWD="$(pwd)"
7+
CHECKOUT_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
8+
9+
if [ -z "$OCTOCATALOG_DIFF_CONFIG_FILE" ]; then
10+
if [ -f "${CURRENT_PWD}/.octocatalog-diff.cfg.rb" ]; then
11+
export OCTOCATALOG_DIFF_CONFIG_FILE="${CURRENT_PWD}/.octocatalog-diff.cfg.rb"
12+
fi
13+
fi
14+
15+
cd "$CHECKOUT_BASE"
16+
export OCTOCATALOG_DIFF_CUSTOM_VERSION="@$(git rev-parse HEAD)"
17+
bundle exec bin/octocatalog-diff --basedir "$CURRENT_PWD" $*

spec/octocatalog-diff/tests/catalog-diff/cli_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,37 @@
115115
end
116116
end
117117

118+
describe '#setup_logger' do
119+
context 'with custom version specified in environment' do
120+
before(:each) do
121+
ENV['OCTOCATALOG_DIFF_CUSTOM_VERSION'] = '@d05c30152c897219367d586414ccb1f651ab7221'
122+
end
123+
124+
after(:each) do
125+
ENV.delete 'OCTOCATALOG_DIFF_CUSTOM_VERSION'
126+
end
127+
128+
it 'should log custom version' do
129+
logger, logger_str = OctocatalogDiff::Spec.setup_logger
130+
described_class.setup_logger(logger, { debug: true }, nil)
131+
expect(logger_str.string).to match(/Running octocatalog-diff @d05c30152c897219367d586414ccb1f651ab7221 with ruby/)
132+
end
133+
end
134+
135+
context 'with default version' do
136+
before(:each) do
137+
ENV.delete 'OCTOCATALOG_DIFF_CUSTOM_VERSION'
138+
end
139+
140+
it 'should log current version' do
141+
logger, logger_str = OctocatalogDiff::Spec.setup_logger
142+
described_class.setup_logger(logger, { debug: true }, nil)
143+
version = described_class::VERSION
144+
expect(logger_str.string).to match(/Running octocatalog-diff #{version} with ruby/)
145+
end
146+
end
147+
end
148+
118149
describe '#setup_fact_overrides' do
119150
it 'should make no adjustments when there are no fact overrides' do
120151
options = {}

0 commit comments

Comments
 (0)