diff --git a/.circleci/config.yml b/.circleci/config.yml index eed549727..68d947aaa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,128 @@ version: 2 +reference: + environment: &ENVIRONMENT + SLACK_TITLE: Vagrant CI + RELEASE_TARGET_REPONAME: vagrant-installers + images: + ruby23: &ruby23 + docker: + - image: circleci/ruby:2.3 + ruby24: &ruby24 + docker: + - image: circleci/ruby:2.4 + ruby25: &ruby25 + docker: + - image: circleci/ruby:2.5 + ruby26: &ruby26 + docker: + - image: circleci/ruby:2.6 + builder: &builder + environment: + <<: *ENVIRONMENT + docker: + - image: $BUILDER_IMAGE + auth: + username: $BUILDER_USERNAME + password: $BUILDER_PASSWORD + workflows: + public: &PUBLIC_WORKFLOW + filters: + branches: + only: /^pull\/.*/ + master: &MASTER_WORKFLOW + filters: + branches: + only: master + private_build: &PRIVATE_WORKFLOW_BUILD + context: vagrant + filters: + branches: + only: + - /^build-.*/ + tags: + only: /.*/ + jobs: + private_failure: &PRIVATE_FAILURE + run: + name: Failure handler + command: | + if [ -f .output ]; then + slack -m "Vagrant job has failed: *${CIRCLE_JOB}*" -s error -f .output -T 5 + else + slack -m "Vagrant job has failed: *${CIRCLE_JOB}*" -s error + fi + when: on_fail + unit_tests: &unit_tests + steps: + - run: sudo apt-get update ; sudo apt-get -yq install bsdtar + - checkout + - restore_cache: + key: static-site-gems-v1-{{ checksum "Gemfile.lock" }} + - run: + command: bundle check || bundle install --path vendor/bundle + - save_cache: + key: static-site-gems-v1-{{ checksum "Gemfile.lock" }} + paths: + - ./vendor/bundle + - run: bundle exec rake test:unit jobs: + build: + <<: *builder + steps: + - checkout + - run: gem build vagrant.gemspec + - *PRIVATE_FAILURE + - persist_to_workspace: + root: . + paths: + - ./*.gem + store: + <<: *builder + steps: + - attach_workspace: + at: . + - run: | + if [[ "${CIRCLE_BRANCH}" = "build-"* ]]; then + s3_dst="${ASSETS_PRIVATE_BUCKET}/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BRANCH##build-}/" + else + s3_dst="${ASSETS_PRIVATE_BUCKET}/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/" + fi + s3_dst="${ASSETS_PRIVATE_BUCKET}/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_TAG}/" + aws s3 cp ./vagrant-*.gem "${s3_dst}" > .output 2>&1 + - *PRIVATE_FAILURE + release: + <<: *builder + steps: + - checkout + - attach_workspace: + at: . + - run: | + set +e + gem=(vagrant-*.gem) + gem_version="${gem##vagrant-}" + gem_version="${gem_version%%.gem}" + export GITHUB_TOKEN="${HASHIBOT_TOKEN}" + if [ "${CIRCLE_TAG}" = "" ]; then + version="v${gem_version}+$(git rev-parse --short "${CIRCLE_SHA1}")" + ghr -u ${CIRCLE_PROJECT_USERNAME} -r ${RELEASE_TARGET_REPONAME} -c master -prerelease -delete -replace ${version} ${gem} > .output 2>&1 + else + version="${CIRCLE_TAG}" + ghr -u ${CIRCLE_PROJECT_USERNAME} -r ${RELEASE_TARGET_REPONAME} -c master -delete -replace ${version} ${gem} > .output 2>&1 + fi + slack -m "New Vagrant installers release triggered: *${version}*" + - *PRIVATE_FAILURE + test_ruby23: + <<: *ruby23 + <<: *unit_tests + test_ruby24: + <<: *ruby24 + <<: *unit_tests + test_ruby25: + <<: *ruby25 + <<: *unit_tests + test_ruby26: + <<: *ruby26 + <<: *unit_tests build-website: # setting the working_directory along with the checkout path allows us to not have # to cd into the website/ directory for commands @@ -9,30 +132,65 @@ jobs: steps: - checkout: path: ~/project - - # restores gem cache - restore_cache: key: static-site-gems-v1-{{ checksum "Gemfile.lock" }} - - run: command: bundle check || bundle install --path vendor/bundle - - # saves gem cache if we have changed the Gemfile - save_cache: key: static-site-gems-v1-{{ checksum "Gemfile.lock" }} paths: - ~/project/website/vendor/bundle - - # middleman build - run: command: bundle exec middleman build - - # website deploy - run: command: ./scripts/deploy.sh - workflows: version: 2 + builds: + jobs: + - build: + <<: *PRIVATE_WORKFLOW_BUILD + - store: + <<: *PRIVATE_WORKFLOW_BUILD + requires: + - build + - release: + <<: *PRIVATE_WORKFLOW_BUILD + requires: + - build + pull_requests: + jobs: + - test_ruby23: + <<: *PUBLIC_WORKFLOW + - test_ruby24: + <<: *PUBLIC_WORKFLOW + - test_ruby25: + <<: *PUBLIC_WORKFLOW + - test_ruby26: + <<: *PUBLIC_WORKFLOW + master: + jobs: + - test_ruby23: + <<: *MASTER_WORKFLOW + - test_ruby24: + <<: *MASTER_WORKFLOW + - test_ruby25: + <<: *MASTER_WORKFLOW + - test_ruby26: + <<: *MASTER_WORKFLOW + - build: + <<: *MASTER_WORKFLOW + context: vagrant + requires: + - test_ruby23 + - test_ruby24 + - test_ruby25 + - test_ruby26 + - store: + <<: *MASTER_WORKFLOW + context: vagrant + requires: + - build website: jobs: - build-website: diff --git a/test/unit/base.rb b/test/unit/base.rb index b81be624c..513ecdc6f 100644 --- a/test/unit/base.rb +++ b/test/unit/base.rb @@ -41,6 +41,10 @@ RSpec.configure do |c| c.filter_run_excluding :windows end + if !Vagrant::Util::Which.which("bsdtar") + c.filter_run_excluding :bsdtar + end + c.after(:suite) do FileUtils.rm_rf(VAGRANT_TEST_CWD) end diff --git a/test/unit/plugins/providers/docker/provider_test.rb b/test/unit/plugins/providers/docker/provider_test.rb index 6b1749416..64d1f4d6d 100644 --- a/test/unit/plugins/providers/docker/provider_test.rb +++ b/test/unit/plugins/providers/docker/provider_test.rb @@ -21,8 +21,6 @@ describe VagrantPlugins::DockerProvider::Provider do end describe ".usable?" do - subject { described_class.new(machine) } - it "returns true if usable" do allow(provider_config).to receive(:compose).and_return(false) allow(subject.driver).to receive(:execute).with("docker", "version").and_return(true) @@ -53,9 +51,10 @@ describe VagrantPlugins::DockerProvider::Provider do end describe "#state" do + before { allow(subject).to receive(:driver).and_return(driver_obj) } + it "returns not_created if no ID" do allow(machine).to receive(:id).and_return(nil) - expect(subject.state.id).to eq(:not_created) end @@ -63,7 +62,8 @@ describe VagrantPlugins::DockerProvider::Provider do allow(provider_config).to receive(:compose).and_return(false) allow(platform).to receive(:windows?).and_return(false) allow(platform).to receive(:darwin?).and_return(false) - allow(machine).to receive(:id).and_return("foo") + expect(machine).to receive(:id).and_return("foo") + expect(driver_obj).to receive(:created?).with("foo").and_return(false) expect(subject.state.id).to eq(:not_created) end diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index 427635d80..8f648bcf1 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -10,7 +10,7 @@ require File.expand_path("../../../../base", __FILE__) require "vagrant/util/file_checksum" -describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do +describe Vagrant::Action::Builtin::BoxAdd, :skip_windows, :bsdtar do include_context "unit" let(:app) { lambda { |env| } } diff --git a/test/unit/vagrant/box_test.rb b/test/unit/vagrant/box_test.rb index 7d2675a53..fcb45780a 100644 --- a/test/unit/vagrant/box_test.rb +++ b/test/unit/vagrant/box_test.rb @@ -320,7 +320,7 @@ describe Vagrant::Box, :skip_windows do FileUtils.rm_rf(scratch) end - it "should repackage the box" do + it "should repackage the box", :bsdtar do test_file_contents = "hello, world!" # Put a file in the box directory to verify it is packaged properly