hashicorp-checkpoint 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+ # Copyright (c) HashiCorp, Inc.
3
+ # SPDX-License-Identifier: MPL-2.0
4
+
5
+ csource="${BASH_SOURCE[0]}"
6
+ while [ -h "$csource" ] ; do csource="$(readlink "$csource")"; done
7
+ root="$( cd -P "$( dirname "$csource" )/../" && pwd )"
8
+
9
+ . "${root}/.ci/load-ci.sh"
10
+
11
+ # Allow the release name to be provided
12
+ release_name="${1}"
13
+ if [ -z "${release_name}" ]; then
14
+ release_name="${tag}"
15
+ fi
16
+
17
+ # Start by building the gem
18
+ gem build ./*.gemspec ||
19
+ failure "Unable to build RubyGem"
20
+
21
+ gem_files=(./*.gem)
22
+ if [ ! -f "${gem_files[0]}" ]; then
23
+ failure "Could not find built RubyGem"
24
+ fi
25
+ gem_file="${gem_files[0]}"
26
+
27
+ # Create the GitHub release
28
+ release "${release_name}" "${gem_file}"
data/.ci/load-ci.sh ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+ # Copyright (c) HashiCorp, Inc.
3
+ # SPDX-License-Identifier: MPL-2.0
4
+
5
+ csource="${BASH_SOURCE[0]}"
6
+ while [ -h "$csource" ] ; do csource="$(readlink "$csource")"; done
7
+ if ! root="$( cd -P "$( dirname "$csource" )/../" && pwd )"; then
8
+ echo "⛔ ERROR: Failed to determine root local directory ⛔" >&2
9
+ exit 1
10
+ fi
11
+
12
+ export root
13
+ export ci_bin_dir="${root}/.ci/.ci-utility-files"
14
+
15
+ # shellcheck source=/dev/null
16
+ if ! source "${ci_bin_dir}/common.sh"; then
17
+ echo "⛔ ERROR: Failed to source Vagrant CI common file ⛔" >&2
18
+ exit 1
19
+ fi
20
+ export PATH="${PATH}:${ci_bin_dir}"
21
+
22
+ # And we are done!
23
+ debug "VagrantCI Loaded"
data/.ci/publish ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ # Copyright (c) HashiCorp, Inc.
3
+ # SPDX-License-Identifier: MPL-2.0
4
+
5
+ csource="${BASH_SOURCE[0]}"
6
+ while [ -h "$csource" ] ; do csource="$(readlink "$csource")"; done
7
+ root="$( cd -P "$( dirname "$csource" )/../" && pwd )"
8
+
9
+ . "${root}/.ci/load-ci.sh"
10
+
11
+ # Allow the release name to be provided
12
+ release_name="${1}"
13
+ if [ -z "${release_name}" ]; then
14
+ release_name="${tag}"
15
+ fi
16
+
17
+ # Send dispatch to vagrant-terraform
18
+ github_repository_dispatch "vagrant-terraform" "publish-rubygem" "repository_tag=${repository}" "release_name=${release_name}"
@@ -0,0 +1 @@
1
+ * @hashicorp/Vagrant
@@ -0,0 +1,33 @@
1
+ name: GitHub Release
2
+ on:
3
+ workflow_call:
4
+ inputs:
5
+ release_name:
6
+ description: 'Name of the GitHub release (example: v1.0.0)'
7
+ required: false
8
+ type: string
9
+ workflow_dispatch:
10
+ inputs:
11
+ release_name:
12
+ description: 'Name of the GitHub release (example: v1.0.0)'
13
+ required: false
14
+ type: string
15
+
16
+ jobs:
17
+ github-release:
18
+ name: Create GitHub Release
19
+ runs-on: ubuntu-latest
20
+ permissions:
21
+ contents: write
22
+ steps:
23
+ - name: Code Checkout
24
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25
+ - name: Setup Ruby
26
+ uses: ruby/setup-ruby@922ebc4c5262cd14e07bb0e1db020984b6c064fe # v1.226.0
27
+ with:
28
+ ruby-version: 3.3
29
+ - name: GitHub Release
30
+ run: ./.ci/github-release "${RELEASE_NAME}"
31
+ env:
32
+ RELEASE_NAME: ${{ inputs.release_name }}
33
+ GITHUB_TOKEN: ${{ github.token }}
@@ -0,0 +1,28 @@
1
+ name: Publish RubyGem
2
+ on:
3
+ workflow_call:
4
+ inputs:
5
+ release_name:
6
+ description: 'Name of the GitHub release (example: v1.0.0)'
7
+ required: false
8
+ type: string
9
+
10
+ workflow_dispatch:
11
+ inputs:
12
+ release_name:
13
+ description: 'Name of the GitHub release (example: v1.0.0)'
14
+ required: false
15
+ type: string
16
+
17
+ jobs:
18
+ rubygem-publish:
19
+ name: Trigger RubyGem publication
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - name: Code Checkout
23
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24
+ - name: Trigger Publish
25
+ run: ./.ci/publish "${RELEASE_NAME}"
26
+ env:
27
+ RELEASE_NAME: ${{ inputs.release_name }}
28
+ HASHIBOT_TOKEN: ${{ vars.HASHIBOT_TOKEN }}
@@ -0,0 +1,27 @@
1
+ on:
2
+ push:
3
+ tags: 'v*'
4
+ workflow_dispatch:
5
+ inputs:
6
+ release_name:
7
+ description: 'Name of the GitHub release (example: v1.0.0)'
8
+ type: string
9
+ require: true
10
+
11
+ jobs:
12
+ github-release:
13
+ if: github.repository == 'hashicorp/ruby-checkpoint'
14
+ name: Create GitHub release
15
+ permissions:
16
+ contents: write
17
+ uses: ./.github/workflows/github-release.yml
18
+ with:
19
+ release_name: ${{ inputs.release_name }}
20
+ publish-rubygem:
21
+ if: github.repository == 'hashicorp/ruby-checkpoint'
22
+ needs: [github-release]
23
+ name: Trigger RubyGem publication
24
+ uses: ./.github/workflows/publish-rubygem.yml
25
+ secrets: inherit
26
+ with:
27
+ release_name: ${{ inputs.release_name }}
@@ -0,0 +1,23 @@
1
+ name: Vagrant Ruby Tests
2
+ on:
3
+ pull_request:
4
+ branches:
5
+ - main
6
+ ignored-paths:
7
+ - 'lib/**'
8
+ - 'spec/**'
9
+ - 'Gemfile'
10
+ - 'ruby-checkpoint.gemspec'
11
+ - 'Rakefile'
12
+
13
+ jobs:
14
+ unit-tests-ruby:
15
+ runs-on: ubuntu-latest
16
+ continue-on-error: true
17
+ strategy:
18
+ matrix:
19
+ ruby: [ '3.1', '3.2', '3.3', '3.4' ]
20
+ name: Checkpoint spec tests on Ruby ${{ matrix.ruby }}
21
+ steps:
22
+ - name: Stubbed for skip
23
+ run: "echo 'No testing required in changeset'"
@@ -0,0 +1,40 @@
1
+ name: Vagrant Ruby Tests
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ - 'test-*'
7
+ paths:
8
+ - 'lib/**'
9
+ - 'spec/**'
10
+ - 'Gemfile'
11
+ - 'ruby-checkpoint.gemspec'
12
+ - 'Rakefile'
13
+ pull_request:
14
+ branches:
15
+ - main
16
+ paths:
17
+ - 'lib/**'
18
+ - 'spec/**'
19
+ - 'Gemfile'
20
+ - 'ruby-checkpoint.gemspec'
21
+ - 'Rakefile'
22
+
23
+ jobs:
24
+ unit-tests-ruby:
25
+ runs-on: ubuntu-latest
26
+ continue-on-error: true
27
+ strategy:
28
+ matrix:
29
+ ruby: [ '3.1', '3.2', '3.3', '3.4' ]
30
+ name: Checkpoint spec tests on Ruby ${{ matrix.ruby }}
31
+ steps:
32
+ - name: Code Checkout
33
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34
+ - name: Setup Ruby
35
+ uses: ruby/setup-ruby@922ebc4c5262cd14e07bb0e1db020984b6c064fe # v1.226.0
36
+ with:
37
+ ruby-version: ${{matrix.ruby}}
38
+ bundler-cache: true
39
+ - name: Run Tests
40
+ run: bundle exec rspec
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  source 'https://rubygems.org'
2
5
 
3
6
  # Specify your gem's dependencies in ruby-checkpoint.gemspec
@@ -1,3 +1,5 @@
1
+ Copyright (c) 2014 HashiCorp, Inc.
2
+
1
3
  Mozilla Public License, version 2.0
2
4
 
3
5
  1. Definitions
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "rbconfig"
2
5
 
3
6
  module Checkpoint
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  module Checkpoint
2
- VERSION = "0.1.4"
5
+ VERSION = "0.1.6"
3
6
  end
data/lib/checkpoint.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "cgi"
2
5
  require "json"
3
6
  require "net/http"
@@ -9,7 +12,7 @@ require "checkpoint/platform"
9
12
  require "checkpoint/version"
10
13
 
11
14
  module Checkpoint
12
- @@disabled = false
15
+ @@disabled = !!ENV["CHECKPOINT_DISABLE"]
13
16
 
14
17
  # Checks for the latest version information as well as alerts.
15
18
  #
@@ -26,16 +29,18 @@ module Checkpoint
26
29
  # a new random signature.
27
30
  # @option opts [String] :cache_file If specified, the response will be
28
31
  # cached here for cache_time period (defaults to 48 hours).
29
- def self.check(**opts)
32
+ def self.check(opts=nil, **kargs)
30
33
  return nil if @@disabled
31
34
 
35
+ opts = kargs if opts.nil?
36
+
32
37
  # If we have the cache file, then just return the contents.
33
38
  if opts[:cache_file] && File.file?(opts[:cache_file])
34
39
  # If the cache file is too old, then delete it
35
40
  mtime = File.mtime(opts[:cache_file]).to_i
36
41
  limit = Time.now.to_i - (60 * 60 * 24 * 2)
37
42
  if mtime > limit
38
- return build_check(File.read(opts[:cache_file]))
43
+ return build_check(File.read(opts[:cache_file]), "cached" => true)
39
44
  end
40
45
 
41
46
  # Delete the file
@@ -101,7 +106,7 @@ module Checkpoint
101
106
  end
102
107
 
103
108
  build_check(resp.body)
104
- rescue Exception
109
+ rescue StandardError
105
110
  # If we want errors, raise it
106
111
  raise if opts[:raise_error]
107
112
 
@@ -116,9 +121,10 @@ module Checkpoint
116
121
 
117
122
  protected
118
123
 
119
- def self.build_check(response)
124
+ def self.build_check(response, extra_info={})
120
125
  JSON.parse(response).tap do |result|
121
126
  result["outdated"] = !!result["outdated"]
127
+ result.merge!(extra_info)
122
128
  end
123
129
  end
124
130
  end
@@ -11,15 +11,14 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = %q{Internal HashiCorp service to check version information.}
12
12
  spec.description = %q{Internal HashiCorp service to check version information}
13
13
  spec.homepage = "http://www.hashicorp.com"
14
- spec.license = "MPL2"
14
+ spec.license = "MPL-2.0"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
22
21
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", "~> 3.0.0"
24
- spec.add_development_dependency "rspec-its", "~> 1.0.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "rspec-its", "~> 2.0"
25
24
  end
@@ -1,9 +1,16 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "tempfile"
2
5
 
3
6
  require "helper"
4
7
 
5
8
  describe Checkpoint do
6
9
  describe ".check" do
10
+ before do
11
+ allow(ENV).to receive(:[]).and_return(nil)
12
+ end
13
+
7
14
  context "with a proper request" do
8
15
  subject do
9
16
  described_class.check(
@@ -17,25 +24,101 @@ describe Checkpoint do
17
24
  its(["current_version"]) { should eq("1.0") }
18
25
  its(["outdated"]) { should eq(false) }
19
26
  its(["product"]) { should eq("test") }
27
+
28
+ context "with hash argument" do
29
+ subject do
30
+ described_class.check({
31
+ product: "test",
32
+ version: "1.0",
33
+ raise_error: true,
34
+ })
35
+ end
36
+
37
+ its(["alerts"]) { should be_empty }
38
+ its(["current_version"]) { should eq("1.0") }
39
+ its(["outdated"]) { should eq(false) }
40
+ its(["product"]) { should eq("test") }
41
+ end
20
42
  end
21
43
 
22
- it "should cache things with cache_file" do
23
- tf = Tempfile.new("checkpoint")
24
- path = tf.path
25
- tf.close
26
- File.unlink(path)
44
+ context "cache file" do
45
+ let(:path){ @path }
46
+
47
+ before do
48
+ tf = Tempfile.new("checkpoint")
49
+ tfpath = tf.path
50
+ tf.close
51
+ File.unlink(tfpath)
52
+ @path = tfpath
53
+ end
54
+
55
+ after{ File.unlink(path) if File.exist?(path) }
56
+
57
+ it "should cache things with cache_file" do
58
+ opts = {
59
+ product: "test",
60
+ version: "1.0",
61
+ cache_file: path,
62
+ }
63
+
64
+ # Just run it twice
65
+ c = described_class.check(opts)
66
+ c = described_class.check(opts)
67
+
68
+ expect(c["product"]).to eq("test")
69
+ end
27
70
 
28
- opts = {
29
- product: "test",
30
- version: "1.0",
31
- cache_file: path,
71
+ it "should indicate cached result" do
72
+ opts = {
73
+ product: "test",
74
+ version: "1.0",
75
+ cache_file: path,
76
+ }
77
+
78
+ # Just run it twice
79
+ c = described_class.check(opts)
80
+ c = described_class.check(opts)
81
+
82
+ expect(c["cached"]).to eq(true)
83
+ end
84
+ end
85
+
86
+ context "with errors" do
87
+ let(:error_class){ StandardError }
88
+ let(:opts) {
89
+ {
90
+ product: "test",
91
+ version: "1.0"
92
+ }
32
93
  }
94
+ before{ allow(Net::HTTP).to receive(:new).and_raise(error_class) }
33
95
 
34
- # Just run it twice
35
- c = described_class.check(opts)
36
- c = described_class.check(opts)
96
+ it "should not raise error by default" do
97
+ expect(described_class.check(opts)).to be_nil
98
+ end
99
+
100
+ it "should raise error when option set" do
101
+ expect{ described_class.check(opts.merge(raise_error: true)) }.to raise_error(error_class)
102
+ end
103
+
104
+ context "with non-StandardError descendant exception" do
105
+ let(:error_class){ Interrupt }
106
+
107
+ it "should raise error by default" do
108
+ expect{ described_class.check(opts) }.to raise_error(error_class)
109
+ end
110
+
111
+ it "should raise error when option set" do
112
+ expect{ described_class.check(opts.merge(raise_error: true)) }.to raise_error(error_class)
113
+ end
114
+ end
115
+ end
37
116
 
38
- expect(c["product"]).to eq("test")
117
+ it "does not check when CHECKPOINT_DISABLE=1" do
118
+ allow(ENV).to receive(:[])
119
+ .with("CHECKPOINT_DISABLE")
120
+ .and_return(1)
121
+ expect(described_class.check).to be(nil)
39
122
  end
40
123
  end
41
124
  end
data/spec/helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require 'rspec/its'
2
5
 
3
6
  require "checkpoint"
metadata CHANGED
@@ -1,71 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashicorp-checkpoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hashimoto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-02 00:00:00.000000000 Z
11
+ date: 2025-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: '1.6'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - '>='
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: '0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - '>='
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ~>
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: 3.0.0
33
+ version: '3.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ~>
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: 3.0.0
40
+ version: '3.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec-its
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ~>
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 1.0.0
47
+ version: '2.0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ~>
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 1.0.0
54
+ version: '2.0'
69
55
  description: Internal HashiCorp service to check version information
70
56
  email:
71
57
  - mitchell@hashicorp.com
@@ -73,9 +59,19 @@ executables: []
73
59
  extensions: []
74
60
  extra_rdoc_files: []
75
61
  files:
76
- - .gitignore
62
+ - ".ci/.ci-utility-files/common.sh"
63
+ - ".ci/github-release"
64
+ - ".ci/load-ci.sh"
65
+ - ".ci/publish"
66
+ - ".github/CODEOWNERS"
67
+ - ".github/workflows/github-release.yml"
68
+ - ".github/workflows/publish-rubygem.yml"
69
+ - ".github/workflows/release.yml"
70
+ - ".github/workflows/testing-skipped.yml"
71
+ - ".github/workflows/testing.yml"
72
+ - ".gitignore"
77
73
  - Gemfile
78
- - LICENSE.txt
74
+ - LICENSE
79
75
  - README.md
80
76
  - Rakefile
81
77
  - lib/checkpoint.rb
@@ -86,26 +82,25 @@ files:
86
82
  - spec/helper.rb
87
83
  homepage: http://www.hashicorp.com
88
84
  licenses:
89
- - MPL2
85
+ - MPL-2.0
90
86
  metadata: {}
91
- post_install_message:
87
+ post_install_message:
92
88
  rdoc_options: []
93
89
  require_paths:
94
90
  - lib
95
91
  required_ruby_version: !ruby/object:Gem::Requirement
96
92
  requirements:
97
- - - '>='
93
+ - - ">="
98
94
  - !ruby/object:Gem::Version
99
95
  version: '0'
100
96
  required_rubygems_version: !ruby/object:Gem::Requirement
101
97
  requirements:
102
- - - '>='
98
+ - - ">="
103
99
  - !ruby/object:Gem::Version
104
100
  version: '0'
105
101
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.0.14
108
- signing_key:
102
+ rubygems_version: 3.5.22
103
+ signing_key:
109
104
  specification_version: 4
110
105
  summary: Internal HashiCorp service to check version information.
111
106
  test_files: