diff options
-rw-r--r-- | .expeditor/config.yml | 9 | ||||
-rw-r--r-- | .expeditor/habitat-test.pipeline.yml | 34 | ||||
-rw-r--r-- | .expeditor/verify.habitat.pipeline.yml | 20 | ||||
-rw-r--r-- | .expeditor/verify.pipeline.yml | 35 | ||||
-rw-r--r-- | CHANGELOG.md | 14 | ||||
-rw-r--r-- | Gemfile.lock | 24 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | chef-bin/lib/chef-bin/version.rb | 2 | ||||
-rw-r--r-- | chef-config/lib/chef-config/version.rb | 2 | ||||
-rw-r--r-- | chef-utils/lib/chef-utils/version.rb | 2 | ||||
-rw-r--r-- | cspell.json | 6 | ||||
-rw-r--r-- | habitat/plan.sh | 137 | ||||
-rw-r--r-- | habitat/tests/spec.ps1 | 2 | ||||
-rwxr-xr-x | habitat/tests/test.sh | 35 | ||||
-rw-r--r-- | lib/chef/provider/git.rb | 16 | ||||
-rw-r--r-- | lib/chef/version.rb | 2 | ||||
-rwxr-xr-x | scripts/ci/install-hab.sh | 23 | ||||
-rwxr-xr-x | scripts/ci/verify-plan.sh | 37 | ||||
-rw-r--r-- | spec/functional/resource/git_spec.rb | 22 | ||||
-rw-r--r-- | spec/functional/shell_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_upload_spec.rb | 11 | ||||
-rw-r--r-- | spec/unit/provider/package/dnf/python_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/package/windows_spec.rb | 21 | ||||
-rw-r--r-- | spec/unit/win32/security_spec.rb | 7 | ||||
-rw-r--r-- | tasks/spellcheck.rb | 20 |
25 files changed, 340 insertions, 155 deletions
diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 090a31808a..ea7fba193e 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -26,14 +26,6 @@ docker_images: pipelines: - verify: public: true - - verify/habitat: - description: > - A temporary pipeline to verify the habitat plans. Performs a local build, - tests it, then throws it away. Its steps should eventually move into the - "verify" pipeline (if fast enough) or this pipeline should be removed in - favor of learning about packaging problems after merge. - definition: .expeditor/verify.habitat.pipeline.yml - trigger: default - habitat/build - habitat/test: definition: .expeditor/habitat-test.pipeline.yml @@ -106,6 +98,7 @@ subscriptions: - bash:.expeditor/update_dockerfile.sh - built_in:tag_docker_image - built_in:publish_rubygems + - built_in:promote_habitat_packages - built_in:notify_chefio_slack_channels # the habitat chain diff --git a/.expeditor/habitat-test.pipeline.yml b/.expeditor/habitat-test.pipeline.yml index 8a71df9c17..7d2cc8f653 100644 --- a/.expeditor/habitat-test.pipeline.yml +++ b/.expeditor/habitat-test.pipeline.yml @@ -9,12 +9,36 @@ expeditor: steps: +- label: ":linux: Validate Linux" + commands: + - sudo ./scripts/ci/install-hab.sh x86_64-linux + - 'echo "--- :hammer_and_wrench: Installing $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64LINUX"' + - sudo hab pkg install $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64LINUX + - sudo ./habitat/tests/test.sh $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64LINUX + expeditor: + executor: + linux: + privileged: true + single-use: true + +- label: ":linux: Validate Linux (kernel2)" + commands: + - sudo ./scripts/ci/install-hab.sh x86_64-linux-kernel2 + - 'echo "--- :hammer_and_wrench: Installing $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64LINUXKERNEL2"' + - sudo hab pkg install $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64LINUXKERNEL2 + - sudo ./habitat/tests/test.sh $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64LINUXKERNEL2 + expeditor: + executor: + linux: + privileged: true + single-use: true + - label: ":windows: Validate Habitat Builds of Chef Infra" commands: - - powershell -File "./scripts/ci/ensure-minimum-viable-hab.ps1" + - powershell -File ./scripts/ci/ensure-minimum-viable-hab.ps1 - 'Write-Host "--- :hammer_and_wrench: Installing $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS"' - - hab pkg install "$EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS" - - powershell -File "./habitat/tests/test.ps1" -PackageIdentifier "$EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS" + - hab pkg install $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS + - powershell -File ./habitat/tests/test.ps1 -PackageIdentifier $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS expeditor: executor: windows: @@ -26,7 +50,9 @@ steps: - label: ":habicat: Promoting packages to the current channel." commands: - - hab pkg promote "$EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS" current x86_64-windows + - hab pkg promote $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64LINUX current x86_64-linux + - hab pkg promote $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64LINUXKERNEL2 current x86_64-linux-kernel2 + - hab pkg promote $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS current x86_64-windows expeditor: executor: docker: diff --git a/.expeditor/verify.habitat.pipeline.yml b/.expeditor/verify.habitat.pipeline.yml deleted file mode 100644 index 9c50312db5..0000000000 --- a/.expeditor/verify.habitat.pipeline.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -expeditor: - defaults: - buildkite: - timeout_in_minutes: 60 - retry: - automatic: - limit: 1 - -steps: - -- label: "Windows plan" - commands: - - scripts/ci/verify-plan.ps1 - expeditor: - executor: - windows: - privileged: true - single-use: true - shell: ["powershell", "-Command"] diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 60142e9928..34a2dee47d 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -573,10 +573,41 @@ steps: - label: "Spellcheck" commands: - - ruby -rjson -e "JSON.parse(File.read('cspell.json'))" 2>/dev/null || (echo "Failed to parse config file 'cspell.json', skipping spellcheck" && exit 1) - npm install -g cspell - - cspell "**/*" + - rake -f tasks/spellcheck.rb spellcheck soft_fail: true expeditor: executor: docker: + +- label: ":habicat: Linux plan" + commands: + - sudo ./scripts/ci/install-hab.sh 'x86_64-linux' + - sudo ./scripts/ci/verify-plan.sh + timeout_in_minutes: 60 + expeditor: + executor: + linux: + privileged: true + single-use: true + +- label: ":habicat: Linux plan (kernel2)" + commands: + - sudo ./scripts/ci/install-hab.sh 'x86_64-linux-kernel2' + - sudo ./scripts/ci/verify-plan.sh + timeout_in_minutes: 60 + expeditor: + executor: + linux: + privileged: true + single-use: true + +- label: ":habicat: Windows plan" + commands: + - ./scripts/ci/verify-plan.ps1 + expeditor: + executor: + windows: + privileged: true + single-use: true + shell: ["powershell", "-Command"] diff --git a/CHANGELOG.md b/CHANGELOG.md index 8345dd53e4..0343a672fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,23 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release 16.2.96 --> -## [v16.2.96](https://github.com/chef/chef/tree/v16.2.96) (2020-07-09) +<!-- latest_release 16.3.4 --> +## [v16.3.4](https://github.com/chef/chef/tree/v16.3.4) (2020-07-14) #### Merged Pull Requests -- Fix openssl config tests on Windows [#10138](https://github.com/chef/chef/pull/10138) ([phiggins](https://github.com/phiggins)) +- Fix extra quote in habitat test pipeline config [#10156](https://github.com/chef/chef/pull/10156) ([christopher-snapp](https://github.com/christopher-snapp)) <!-- latest_release --> <!-- release_rollup since=16.2.73 --> ### Changes not yet released to stable #### Merged Pull Requests +- Fix extra quote in habitat test pipeline config [#10156](https://github.com/chef/chef/pull/10156) ([christopher-snapp](https://github.com/christopher-snapp)) <!-- 16.3.4 --> +- Test and Promote Habitat builds on Linux [#10102](https://github.com/chef/chef/pull/10102) ([christopher-snapp](https://github.com/christopher-snapp)) <!-- 16.3.3 --> +- Fix two warnings in tests. [#10150](https://github.com/chef/chef/pull/10150) ([phiggins](https://github.com/phiggins)) <!-- 16.3.2 --> +- Don't run the dnf test that Windows doesn't like on Windows. [#10149](https://github.com/chef/chef/pull/10149) ([phiggins](https://github.com/phiggins)) <!-- 16.3.2 --> +- Fix some windows unit tests [#10144](https://github.com/chef/chef/pull/10144) ([phiggins](https://github.com/phiggins)) <!-- 16.3.1 --> +- Minor chefstyle fixes in the spellcheck task [#10145](https://github.com/chef/chef/pull/10145) ([tas50](https://github.com/tas50)) <!-- 16.3.0 --> +- Fix spellcheck CI task [#10142](https://github.com/chef/chef/pull/10142) ([phiggins](https://github.com/phiggins)) <!-- 16.2.98 --> +- Fix git sync if the local branch already exist [#9998](https://github.com/chef/chef/pull/9998) ([lotooo](https://github.com/lotooo)) <!-- 16.2.97 --> - Fix openssl config tests on Windows [#10138](https://github.com/chef/chef/pull/10138) ([phiggins](https://github.com/phiggins)) <!-- 16.2.96 --> - Disable Naming/AsciiIdentifiers in our specs [#10139](https://github.com/chef/chef/pull/10139) ([tas50](https://github.com/tas50)) <!-- 16.2.95 --> - Support legacy DSS host keys with knife-ssh [#10133](https://github.com/chef/chef/pull/10133) ([tas50](https://github.com/tas50)) <!-- 16.2.94 --> diff --git a/Gemfile.lock b/Gemfile.lock index 24706e31a8..b54dc9ff45 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,12 +28,12 @@ GIT PATH remote: . specs: - chef (16.2.96) + chef (16.3.4) addressable bcrypt_pbkdf (= 1.1.0.rc1) bundler (>= 1.10) - chef-config (= 16.2.96) - chef-utils (= 16.2.96) + chef-config (= 16.3.4) + chef-utils (= 16.3.4) chef-vault chef-zero (>= 14.0.11) diff-lcs (>= 1.2.4, < 1.4.0) @@ -62,12 +62,12 @@ PATH train-winrm (>= 0.2.5) tty-screen (~> 0.6) uuidtools (~> 2.1.5) - chef (16.2.96-universal-mingw32) + chef (16.3.4-universal-mingw32) addressable bcrypt_pbkdf (= 1.1.0.rc1) bundler (>= 1.10) - chef-config (= 16.2.96) - chef-utils (= 16.2.96) + chef-config (= 16.3.4) + chef-utils (= 16.3.4) chef-vault chef-zero (>= 14.0.11) diff-lcs (>= 1.2.4, < 1.4.0) @@ -112,15 +112,15 @@ PATH PATH remote: chef-bin specs: - chef-bin (16.2.96) - chef (= 16.2.96) + chef-bin (16.3.4) + chef (= 16.3.4) PATH remote: chef-config specs: - chef-config (16.2.96) + chef-config (16.3.4) addressable - chef-utils (= 16.2.96) + chef-utils (= 16.3.4) fuzzyurl mixlib-config (>= 2.2.12, < 4.0) mixlib-shellout (>= 2.0, < 4.0) @@ -129,7 +129,7 @@ PATH PATH remote: chef-utils specs: - chef-utils (16.2.96) + chef-utils (16.3.4) GEM remote: https://rubygems.org/ @@ -257,7 +257,7 @@ GEM mixlib-shellout (3.0.9-universal-mingw32) win32-process (~> 0.8.2) wmi-lite (~> 1.0) - multi_json (1.14.1) + multi_json (1.15.0) multipart-post (2.1.1) necromancer (0.5.1) net-scp (3.0.0) @@ -1 +1 @@ -16.2.96
\ No newline at end of file +16.3.4
\ No newline at end of file diff --git a/chef-bin/lib/chef-bin/version.rb b/chef-bin/lib/chef-bin/version.rb index 5ca13c207d..11d9692024 100644 --- a/chef-bin/lib/chef-bin/version.rb +++ b/chef-bin/lib/chef-bin/version.rb @@ -21,7 +21,7 @@ module ChefBin CHEFBIN_ROOT = File.expand_path("..", __dir__) - VERSION = "16.2.96".freeze + VERSION = "16.3.4".freeze end # diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index dcfc6c7073..4230df129b 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -15,5 +15,5 @@ module ChefConfig CHEFCONFIG_ROOT = File.expand_path("..", __dir__) - VERSION = "16.2.96".freeze + VERSION = "16.3.4".freeze end diff --git a/chef-utils/lib/chef-utils/version.rb b/chef-utils/lib/chef-utils/version.rb index 7470d9069e..026ece80a4 100644 --- a/chef-utils/lib/chef-utils/version.rb +++ b/chef-utils/lib/chef-utils/version.rb @@ -15,5 +15,5 @@ module ChefUtils CHEFUTILS_ROOT = File.expand_path("..", __dir__) - VERSION = "16.2.96".freeze + VERSION = "16.3.4".freeze end diff --git a/cspell.json b/cspell.json index a6be972552..30f26af8b0 100644 --- a/cspell.json +++ b/cspell.json @@ -635,6 +635,7 @@ "gettype", "gids", "Gilles", + "gitkeep", "glibc", "globalstate", "globbing", @@ -1606,6 +1607,7 @@ "rpmvercmp", "rquery", "rsakey", + "RSAT", "rspec", "rstrip", "rsync", @@ -1660,6 +1662,7 @@ "scutil", "secedit", "secoption", + "secopts", "secp", "securerandom", "SECURITYPOLICY", @@ -2178,7 +2181,8 @@ "zolo", "zombiejs", "Zuazo", - "Zygmuntowicz" + "Zygmuntowicz", + "zypp" ], // flagWords - list of words to be always considered incorrect // This is useful for offensive words and common spelling errors. diff --git a/habitat/plan.sh b/habitat/plan.sh index 6e113e8a95..967cdd334e 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -1,10 +1,13 @@ -pkg_name=chef-infra-client -pkg_origin=chef +_chef_client_ruby="core/ruby27" +pkg_name="chef-infra-client" +pkg_origin="chef" pkg_maintainer="The Chef Maintainers <humans@chef.io>" pkg_description="The Chef Infra Client" pkg_license=('Apache-2.0') -pkg_bin_dirs=(bin) -_chef_client_ruby="core/ruby27" +pkg_bin_dirs=( + bin + vendor/bin +) pkg_build_deps=( core/make core/gcc @@ -52,10 +55,34 @@ do_verify() { return 0 } +do_setup_environment() { + push_runtime_env GEM_PATH "${pkg_prefix}/vendor" + + set_runtime_env APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH + set_runtime_env SSL_CERT_FILE "$(pkg_path_for cacerts)/ssl/cert.pem" + set_runtime_env LANG "en_US.UTF-8" + set_runtime_env LC_CTYPE "en_US.UTF-8" +} + do_prepare() { - export OPENSSL_LIB_DIR=$(pkg_path_for openssl)/lib - export OPENSSL_INCLUDE_DIR=$(pkg_path_for openssl)/include - export SSL_CERT_FILE=$(pkg_path_for cacerts)/ssl/cert.pem + export GEM_HOME="${pkg_prefix}/vendor" + export OPENSSL_LIB_DIR="$(pkg_path_for openssl)/lib" + export OPENSSL_INCLUDE_DIR="$(pkg_path_for openssl)/include" + export SSL_CERT_FILE="$(pkg_path_for cacerts)/ssl/cert.pem" + export CPPFLAGS="${CPPFLAGS} ${CFLAGS}" + + ( cd "$CACHE_PATH" + bundle config --local build.nokogiri "--use-system-libraries \ + --with-zlib-dir=$(pkg_path_for zlib) \ + --with-xslt-dir=$(pkg_path_for libxslt) \ + --with-xml2-include=$(pkg_path_for libxml2)/include/libxml2 \ + --with-xml2-lib=$(pkg_path_for libxml2)/lib" + bundle config --local jobs "$(nproc)" + bundle config --local without server docgen maintenance pry travis integration ci chefstyle + bundle config --local shebang "$(pkg_path_for "$_chef_client_ruby")/bin/ruby" + bundle config --local retry 5 + bundle config --local silence_root_warning 1 + ) build_line "Setting link for /usr/bin/env to 'coreutils'" if [ ! -f /usr/bin/env ]; then @@ -64,58 +91,46 @@ do_prepare() { } do_build() { - local _libxml2_dir - local _libxslt_dir - local _zlib_dir - export CPPFLAGS - export GEM_HOME - export GEM_PATH - export NOKOGIRI_CONFIG - - _libxml2_dir=$(pkg_path_for libxml2) - _libxslt_dir=$(pkg_path_for libxslt) - _zlib_dir=$(pkg_path_for zlib) - - CPPFLAGS="${CPPFLAGS} ${CFLAGS}" - GEM_HOME=${pkg_prefix}/bundle - GEM_PATH=${GEM_HOME} - NOKOGIRI_CONFIG="--use-system-libraries \ - --with-zlib-dir=${_zlib_dir} \ - --with-xslt-dir=${_libxslt_dir} \ - --with-xml2-include=${_libxml2_dir}/include/libxml2 \ - --with-xml2-lib=${_libxml2_dir}/lib" - - build_line "Executing bundle install inside hab-cache path. ($CACHE_PATH/chef-config)" - ( cd "$CACHE_PATH/chef-config" || exit_with "unable to enter hab-cache directory" 1 - bundle config --local build.nokogiri "${NOKOGIRI_CONFIG}" - bundle config --local silence_root_warning 1 - _bundle_install "${pkg_prefix}/bundle" + ( cd "$CACHE_PATH" || exit_with "unable to enter hab-cache directory" 1 + build_line "Installing gem dependencies ..." + bundle install + build_line "Installing this project's gems ..." + bundle exec rake install + for gem in $GEM_HOME/bundler/gems/*; do + ( cd $gem + build_line "Installing gems from git repos properly ..." + rake install + ) + done ) - - build_line "Executing bundle install inside source path. ($SRC_PATH)" - _bundle_install "${pkg_prefix}/bundle" } do_install() { - build_line "Copying directories from source to pkg_prefix" - mkdir -p "${pkg_prefix}/chef" - for dir in bin chef-bin chef-config chef-utils lib chef.gemspec Gemfile Gemfile.lock; do - cp -rv "${SRC_PATH}/${dir}" "${pkg_prefix}/chef/" - done - - # If we generated them on install, bundler thinks our source is in $HAB_CACHE_SOURCE_PATH - build_line "Generating binstubs with the correct path" - ( cd "$pkg_prefix/chef" || exit_with "unable to enter pkg prefix directory" 1 - _bundle_install \ - "${pkg_prefix}/bundle" \ - --local \ - --quiet \ - --binstubs "${pkg_prefix}/bin" + ( cd "$pkg_prefix" || exit_with "unable to enter pkg prefix directory" 1 + export BUNDLE_GEMFILE="${CACHE_PATH}/Gemfile" + build_line "** fixing binstub shebangs" + fix_interpreter "${pkg_prefix}/vendor/bin/*" "$_chef_client_ruby" bin/ruby + export BUNDLE_GEMFILE="${CACHE_PATH}/Gemfile" + for gem in chef-bin chef inspec-core-bin ohai; do + build_line "** generating binstubs for $gem with precise version pins" + appbundler $CACHE_PATH $pkg_prefix/bin $gem + done ) +} - build_line "Fixing bin/ruby and bin/env interpreters" - fix_interpreter "${pkg_prefix}/bin/*" core/coreutils bin/env - fix_interpreter "${pkg_prefix}/bin/*" "$_chef_client_ruby" bin/ruby +do_after() { + build_line "Trimming the fat ..." + + # We don't need the cache of downloaded .gem files ... + rm -r "$pkg_prefix/vendor/cache" + # ... or bundler's cache of git-ref'd gems + rm -r "$pkg_prefix/vendor/bundler" + # We don't need the gem docs. + rm -r "$pkg_prefix/vendor/doc" + # We don't need to ship the test suites for every gem dependency, + # only Chef's for package verification. + find "$pkg_prefix/vendor/gems" -name spec -type d | grep -v "chef-${pkg_version}" \ + | while read spec_dir; do rm -r "$spec_dir"; done } do_end() { @@ -128,19 +143,3 @@ do_end() { do_strip() { return 0 } - -# Helper function to wrap up some repetitive bundle install flags -_bundle_install() { - local path - path="$1" - shift - - bundle install ${*:-} \ - --jobs "$(nproc)" \ - --without development:test:docgen \ - --path "$path" \ - --shebang="$(pkg_path_for "$_chef_client_ruby")/bin/ruby" \ - --no-clean \ - --retry 5 \ - --standalone -} diff --git a/habitat/tests/spec.ps1 b/habitat/tests/spec.ps1 index 0229ac487f..6cbdd406c2 100644 --- a/habitat/tests/spec.ps1 +++ b/habitat/tests/spec.ps1 @@ -18,7 +18,7 @@ try { SETX GEM_PATH $($gemPath.Split("=")[1]) /m hab pkg binlink --force $PackageIdentifier - /hab/bin/rspec --format progress --tag ~executables --tag ~choco_installed spec/functional + /hab/bin/rspec --format documentation --tag ~executables --tag ~choco_installed spec/functional if (-not $?) { throw "functional testing failed"} } finally { Pop-Location diff --git a/habitat/tests/test.sh b/habitat/tests/test.sh new file mode 100755 index 0000000000..0882313c8e --- /dev/null +++ b/habitat/tests/test.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +set -euo pipefail + +export CHEF_LICENSE="accept-no-persist" +export HAB_LICENSE="accept-no-persist" + +project_root="$(git rev-parse --show-toplevel)" +pkg_ident="$1" + +# print error message followed by usage and exit +error () { + local message="$1" + + echo -e "\nERROR: ${message}\n" >&2 + + exit 1 +} + +[[ -n "$pkg_ident" ]] || error 'no hab package identity provided' + +package_version=$(awk -F / '{print $3}' <<<"$pkg_ident") + +cd "${project_root}" + +echo "--- :mag_right: Testing ${pkg_ident} executables" +[[ "$package_version" = "$(hab pkg exec "${pkg_ident}" chef-client --version | sed 's/.*: //')" ]] || error "chef-client is not the expected version" + +for executable in 'chef-client' 'ohai' 'chef-shell' 'chef-apply' 'knife' 'chef-solo'; do + echo -en "\t$executable = " + hab pkg exec "${pkg_ident}" "${executable}" --version || error "${executable} failed to execute properly" +done + +echo "--- :mag_right: Testing ${pkg_ident} functionality" +hab pkg exec "${pkg_ident}" rspec -f documentation --tag ~executables spec/functional || error 'failures during rspec tests' diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index c8b48f5602..6f5a129820 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -154,6 +154,11 @@ class Chef sha_hash?(result) ? result : nil end + def already_on_target_branch? + current_branch = git("rev-parse", "--abbrev-ref", "HEAD", cwd: cwd, returns: [0, 128]).stdout.strip + current_branch == (new_resource.checkout_branch || new_resource.revision) + end + def add_remotes if new_resource.additional_remotes.length > 0 new_resource.additional_remotes.each_pair do |remote_name, remote_url| @@ -193,6 +198,9 @@ class Chef # detached head git("checkout", target_revision, cwd: cwd) logger.info "#{new_resource} checked out reference: #{target_revision}" + elsif already_on_target_branch? + # we are already on the proper branch + git("reset", "--hard", target_revision, cwd: cwd) else # need a branch with a tracking branch git("branch", "-f", new_resource.revision, target_revision, cwd: cwd) @@ -222,13 +230,13 @@ class Chef logger.trace "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}" git("fetch", "--prune", new_resource.remote, cwd: cwd) git("fetch", new_resource.remote, "--tags", cwd: cwd) - if new_resource.checkout_branch + if sha_hash?(new_resource.revision) || is_tag? || already_on_target_branch? + # detached head or if we are already on the proper branch + git("reset", "--hard", target_revision, cwd: cwd) + elsif new_resource.checkout_branch # check out to a local branch git("branch", "-f", new_resource.checkout_branch, target_revision, cwd: cwd) git("checkout", new_resource.checkout_branch, cwd: cwd) - elsif sha_hash?(new_resource.revision) || is_tag? - # detached head - git("reset", "--hard", target_revision, cwd: cwd) else # need a branch with a tracking branch git("branch", "-f", new_resource.revision, target_revision, cwd: cwd) diff --git a/lib/chef/version.rb b/lib/chef/version.rb index 9bae256480..d9bffa48fc 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -23,7 +23,7 @@ require_relative "version_string" class Chef CHEF_ROOT = File.expand_path("..", __dir__) - VERSION = Chef::VersionString.new("16.2.96") + VERSION = Chef::VersionString.new("16.3.4") end # diff --git a/scripts/ci/install-hab.sh b/scripts/ci/install-hab.sh new file mode 100755 index 0000000000..b65a89d706 --- /dev/null +++ b/scripts/ci/install-hab.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -euo pipefail + +export HAB_LICENSE="accept" + +hab_target="$1" + +# print error message followed by usage and exit +error () { + local message="$1" + + echo -e "\nERROR: ${message}\n" >&2 + + exit 1 +} + +[[ -n "$hab_target" ]] || error 'no hab target provided' + +echo "--- :habicat: Installing latest version of Habitat" +rm -rf /hab +curl https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh | bash -s -- -t "$hab_target" +hab license accept diff --git a/scripts/ci/verify-plan.sh b/scripts/ci/verify-plan.sh new file mode 100755 index 0000000000..71aac8d767 --- /dev/null +++ b/scripts/ci/verify-plan.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -euo pipefail + +export HAB_ORIGIN='ci' +export PLAN='chef-infra-client' +export CHEF_LICENSE="accept-no-persist" +export HAB_LICENSE="accept-no-persist" + +# print error message followed by usage and exit +error () { + local message="$1" + + echo -e "\nERROR: ${message}\n" >&2 + + exit 1 +} + +echo "--- :8ball: :linux: Verifying $PLAN" +project_root="$(git rev-parse --show-toplevel)" + +echo "--- :key: Generating fake origin key" +hab origin key generate "$HAB_ORIGIN" + +echo "--- :construction: Building $PLAN (solely for verification testing)" +( + cd "$project_root" || error 'cannot change directory to project root' + DO_CHECK=true hab pkg build . || error 'unable to build' +) + +source "${project_root}/results/last_build.env" || error 'unable to determine details about this build' + +echo "--- :hammer_and_wrench: Installing $pkg_ident" +hab pkg install "${project_root}/results/$pkg_artifact" || error 'unable to install this build' + +echo "--- :mag_right: Testing $PLAN" +${project_root}/habitat/tests/test.sh "$pkg_ident" || error 'failures during test of executables' diff --git a/spec/functional/resource/git_spec.rb b/spec/functional/resource/git_spec.rb index f8064fef20..25e5c6da4a 100644 --- a/spec/functional/resource/git_spec.rb +++ b/spec/functional/resource/git_spec.rb @@ -239,6 +239,28 @@ describe Chef::Resource::Git, requires_git: true do end end + context "when updating a branch that's already checked out out" do + it "checks out master, commits to the repo, and checks out the latest changes" do + git deploy_directory do + repository origin_repo + revision "master" + action :sync + end.should_be_updated + + # We don't have a way to test a commit in the git bundle + # Revert to a previous commit in the same branch and make sure we can still sync. + shell_out!("git", "reset", "--hard", rev_foo, cwd: deploy_directory) + + git deploy_directory do + repository origin_repo + revision "master" + action :sync + end.should_be_updated + expect_revision_to_be("HEAD", rev_head) + expect_branch_to_be("master") + end + end + context "when dealing with a repo with a degenerate tag named 'HEAD'" do before do shell_out!("git", "tag", "-m\"degenerate tag\"", "HEAD", "ed181b3419b6f489bedab282348162a110d6d3a1", cwd: origin_repo) diff --git a/spec/functional/shell_spec.rb b/spec/functional/shell_spec.rb index 583440d2b6..2289df3ef1 100644 --- a/spec/functional/shell_spec.rb +++ b/spec/functional/shell_spec.rb @@ -97,13 +97,13 @@ describe Shell do [output, e.status] end - it "boots correctly with -lauto" do + it "boots correctly with -lauto", :executables do output, exitstatus = run_chef_shell_with("-lauto") expect(output).to include("done") expect(exitstatus).to eq(0) end - it "sets the log_level from the command line" do + it "sets the log_level from the command line", :executables do output, exitstatus = run_chef_shell_with("-lfatal") do |out, keyboard| show_log_level_code = %q[puts "===#{Chef::Log.level}==="] keyboard.puts(show_log_level_code) @@ -114,13 +114,13 @@ describe Shell do end context "on solo mode" do - it "starts correctly" do + it "starts correctly", :executables do output, exitstatus = run_chef_shell_with("--solo") expect(output).to include("done") expect(exitstatus).to eq(0) end - it "should be able to use the API" do + it "should be able to use the API", :executables do output, exitstatus = run_chef_shell_with("-s") do |out, keyboard| simple_api_get = "api.get('data')" keyboard.puts(simple_api_get) @@ -131,7 +131,7 @@ describe Shell do end end - it "sets the override_runlist from the command line" do + it "sets the override_runlist from the command line", :executables do output, exitstatus = run_chef_shell_with("-o 'override::foo,override::bar'") do |out, keyboard| show_recipes_code = %q[puts "#{node["recipes"].inspect}"] keyboard.puts(show_recipes_code) diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb index 661eb779ea..bc13ce834c 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -323,19 +323,18 @@ describe Chef::Knife::CookbookUpload do context "when cookbook path is an array" do it "should warn users that no cookbooks exist" do - knife.config[:cookbook_path] = ["/chef-repo/cookbooks", "/home/user/cookbooks"] - expect(knife.ui).to receive(:warn).with( - /Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path].join(', ')}'\. Use --cookbook-path to specify the desired path\./ - ) + cookbook_path = windows? ? "C:/chef-repo/cookbooks" : "/chef-repo/cookbooks" + knife.config[:cookbook_path] = [cookbook_path, "/home/user/cookbooks"] + expect(knife.ui).to receive(:warn).with("Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path].join(", ")}'. Use --cookbook-path to specify the desired path.") knife.run end end context "when cookbook path is a string" do it "should warn users that no cookbooks exist" do - knife.config[:cookbook_path] = "/chef-repo/cookbooks" + knife.config[:cookbook_path] = windows? ? "C:/chef-repo/cookbooks" : "/chef-repo/cookbooks" expect(knife.ui).to receive(:warn).with( - /Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path]}'\. Use --cookbook-path to specify the desired path\./ + "Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path]}'. Use --cookbook-path to specify the desired path." ) knife.run end diff --git a/spec/unit/provider/package/dnf/python_helper_spec.rb b/spec/unit/provider/package/dnf/python_helper_spec.rb index c22e0f6bee..1f94147273 100644 --- a/spec/unit/provider/package/dnf/python_helper_spec.rb +++ b/spec/unit/provider/package/dnf/python_helper_spec.rb @@ -22,7 +22,7 @@ require "spec_helper" describe Chef::Provider::Package::Dnf::PythonHelper do let(:helper) { Chef::Provider::Package::Dnf::PythonHelper.instance } - it "propagates stacktraces on stderr from the forked subprocess" do + it "propagates stacktraces on stderr from the forked subprocess", :rhel do allow(helper).to receive(:dnf_command).and_return("ruby -e 'raise \"your hands in the air\"'") expect { helper.package_query(:whatprovides, "tcpdump") }.to raise_error(/your hands in the air/) end diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb index b9a32ffd66..6531d9c5ec 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -70,16 +70,18 @@ describe Chef::Provider::Package::Windows, :windows_only do end end - context "when the source is a uri" do - let(:resource_source) { "https://foo.bar/calculator.msi" } - - context "when the source has not been downloaded" do + context "when the source is not present it loads from cache" do + context "when the package is not installed" do before(:each) do - allow(provider).to receive(:downloadable_file_missing?).and_return(true) + allow(provider).to receive(:uri_scheme?).and_return(false) + allow(provider.package_provider).to receive(:get_product_property).and_return(nil) + allow(provider.package_provider).to receive(:get_installed_version).and_return(nil) + allow(provider.package_provider).to receive(:package_version).and_return(nil) end - it "sets the current version to unknown" do + + it "sets the current version nil" do provider.load_current_resource - expect(provider.current_resource.version).to eql("unknown") + expect(provider.current_resource.version).to eql(nil) end end @@ -312,7 +314,10 @@ describe Chef::Provider::Package::Windows, :windows_only do let(:resource_source) { "https://foo.bar/calculator.exe" } it "downloads the http resource" do - allow(File).to receive(:exist?).with('c:\cache\calculator.exe').and_return(false) + allow(provider).to receive(:uri_scheme?).and_return(true) + allow(provider).to receive(:installer_type).and_return(nil) + allow(File).to receive(:exist?).with("https\\foo.bar\\calculator.exe").and_return(false) + allow(provider).to receive(:compile_and_converge_action) expect(provider).to receive(:download_source_file) provider.run_action(:install) end diff --git a/spec/unit/win32/security_spec.rb b/spec/unit/win32/security_spec.rb index d90951c3e2..ed4c033aa3 100644 --- a/spec/unit/win32/security_spec.rb +++ b/spec/unit/win32/security_spec.rb @@ -81,9 +81,10 @@ describe "Chef::Win32::Security", :windows_only do context "when the user has admin privileges" do it "returns true" do - allow(Chef::ReservedNames::Win32::Security).to receive(:open_current_process_token) - token = Chef::ReservedNames::Win32::Security.open_current_process_token + token = double(:process_token) allow(token).to receive_message_chain(:handle, :handle) + + allow(Chef::ReservedNames::Win32::Security).to receive(:open_current_process_token).and_return(token) allow(Chef::ReservedNames::Win32::Security).to receive(:get_token_information_elevation_type) allow(Chef::ReservedNames::Win32::Security).to receive(:GetTokenInformation).and_return(true) allow_any_instance_of(FFI::Buffer).to receive(:read_ulong).and_return(1) @@ -128,7 +129,7 @@ describe "Chef::Win32::Security", :windows_only do context "when FFI::LastError.error result is not ERROR_INSUFFICIENT_BUFFER and not NO_ERROR" do it "raises Chef::ReservedNames::Win32::Error.raise! exception" do expect(FFI::LastError).to receive(:error).and_return(123).at_least(:once) - expect { security_class.lookup_account_name "system" }.to raise_error + expect { security_class.lookup_account_name "system" }.to raise_error(Chef::Exceptions::Win32APIError) end end end diff --git a/tasks/spellcheck.rb b/tasks/spellcheck.rb index 002518d9ee..076173fa1d 100644 --- a/tasks/spellcheck.rb +++ b/tasks/spellcheck.rb @@ -17,17 +17,31 @@ namespace :spellcheck do task :fetch_common do - sh "wget https://raw.githubusercontent.com/chef/chef_dictionary/master/chef.txt -O chef_dictionary.txt" + sh "wget -q https://raw.githubusercontent.com/chef/chef_dictionary/master/chef.txt -O chef_dictionary.txt" end - task run: :fetch_common do + task run: %i{config_check fetch_common} do sh 'cspell "**/*"' end desc "List the unique unrecognized words in the project." - task unknown_words: :fetch_common do + task unknown_words: %i{config_check fetch_common} do sh 'cspell "**/*" --wordsOnly --no-summary | sort | uniq' end + + task :config_check do + require "json" + + config_file = "cspell.json" + + unless File.readable?(config_file) + abort "Spellcheck config file '#{config_file}' not found, skipping spellcheck" + end + + unless (JSON.parse(File.read(config_file)) rescue false) + abort "Failed to parse config file '#{config_file}', skipping spellcheck" + end + end end desc "Run spellcheck on the project." |