middleman-s3_sync 4.5.0 → 4.6.1
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.
- checksums.yaml +4 -4
- data/.s3_sync.sample +22 -0
- data/Changelog.md +59 -0
- data/README.md +217 -36
- data/lib/middleman/s3_sync/cloudfront.rb +211 -0
- data/lib/middleman/s3_sync/version.rb +1 -1
- data/lib/middleman/s3_sync.rb +34 -3
- data/lib/middleman-s3_sync/commands.rb +39 -0
- data/lib/middleman-s3_sync/extension.rb +7 -0
- data/middleman-s3_sync.gemspec +1 -0
- data/spec/cloudfront_spec.rb +511 -0
- data/spec/s3_sync_integration_spec.rb +132 -0
- metadata +21 -2
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'middleman/s3_sync'
|
3
|
+
|
4
|
+
describe 'S3Sync CloudFront Integration' do
|
5
|
+
let(:app) { double('middleman_app') }
|
6
|
+
let(:s3_sync_options) do
|
7
|
+
double(
|
8
|
+
cloudfront_invalidate: true,
|
9
|
+
cloudfront_distribution_id: 'E1234567890123',
|
10
|
+
cloudfront_invalidate_all: false,
|
11
|
+
cloudfront_invalidation_batch_size: 1000,
|
12
|
+
aws_access_key_id: 'test_key',
|
13
|
+
aws_secret_access_key: 'test_secret',
|
14
|
+
aws_session_token: nil,
|
15
|
+
dry_run: false,
|
16
|
+
verbose: false,
|
17
|
+
delete: true,
|
18
|
+
bucket: 'test-bucket'
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(::Middleman::Application).to receive(:new).and_return(app)
|
24
|
+
allow(Middleman::S3Sync).to receive(:s3_sync_options).and_return(s3_sync_options)
|
25
|
+
allow(Middleman::S3Sync).to receive(:say_status)
|
26
|
+
allow(Middleman::S3Sync).to receive(:work_to_be_done?).and_return(true)
|
27
|
+
allow(Middleman::S3Sync).to receive(:update_bucket_versioning)
|
28
|
+
allow(Middleman::S3Sync).to receive(:update_bucket_website)
|
29
|
+
allow(Middleman::S3Sync).to receive(:ignore_resources)
|
30
|
+
allow(Middleman::S3Sync).to receive(:create_resources)
|
31
|
+
allow(Middleman::S3Sync).to receive(:update_resources)
|
32
|
+
allow(Middleman::S3Sync).to receive(:delete_resources)
|
33
|
+
allow(Middleman::S3Sync::CloudFront).to receive(:invalidate)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'CloudFront invalidation integration' do
|
37
|
+
it 'calls CloudFront invalidation after sync operations' do
|
38
|
+
# Reset invalidation paths for this test
|
39
|
+
Middleman::S3Sync.instance_variable_set(:@invalidation_paths, [])
|
40
|
+
|
41
|
+
expect(Middleman::S3Sync::CloudFront).to receive(:invalidate).with(
|
42
|
+
[], # Initially empty, gets populated during resource operations
|
43
|
+
s3_sync_options
|
44
|
+
)
|
45
|
+
|
46
|
+
Middleman::S3Sync.sync
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'calls CloudFront invalidation with collected paths' do
|
50
|
+
# Mock the methods to inject paths during sync
|
51
|
+
allow(Middleman::S3Sync).to receive(:create_resources) do
|
52
|
+
Middleman::S3Sync.add_invalidation_path('/updated/file.html')
|
53
|
+
end
|
54
|
+
allow(Middleman::S3Sync).to receive(:update_resources) do
|
55
|
+
Middleman::S3Sync.add_invalidation_path('/new/file.css')
|
56
|
+
end
|
57
|
+
|
58
|
+
expect(Middleman::S3Sync::CloudFront).to receive(:invalidate) do |paths, options|
|
59
|
+
expect(paths).to include('/updated/file.html')
|
60
|
+
expect(paths).to include('/new/file.css')
|
61
|
+
expect(options).to eq(s3_sync_options)
|
62
|
+
end
|
63
|
+
|
64
|
+
Middleman::S3Sync.sync
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when cloudfront_invalidate_all is true' do
|
68
|
+
let(:s3_sync_options) do
|
69
|
+
double(
|
70
|
+
cloudfront_invalidate: true,
|
71
|
+
cloudfront_distribution_id: 'E1234567890123',
|
72
|
+
cloudfront_invalidate_all: true,
|
73
|
+
bucket: 'test-bucket'
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'still calls CloudFront invalidation even when no work is needed' do
|
78
|
+
allow(Middleman::S3Sync).to receive(:work_to_be_done?).and_return(false)
|
79
|
+
|
80
|
+
expect(Middleman::S3Sync::CloudFront).to receive(:invalidate).with(
|
81
|
+
[], s3_sync_options
|
82
|
+
)
|
83
|
+
|
84
|
+
Middleman::S3Sync.sync
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when CloudFront invalidation is disabled' do
|
89
|
+
let(:s3_sync_options) do
|
90
|
+
double(
|
91
|
+
cloudfront_invalidate: false,
|
92
|
+
bucket: 'test-bucket'
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'does not call CloudFront invalidation' do
|
97
|
+
expect(Middleman::S3Sync::CloudFront).not_to receive(:invalidate)
|
98
|
+
|
99
|
+
Middleman::S3Sync.sync
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'path tracking during resource operations' do
|
105
|
+
before do
|
106
|
+
# Reset invalidation paths before each path tracking test
|
107
|
+
Middleman::S3Sync.instance_variable_set(:@invalidation_paths, [])
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'adds paths to invalidation list when resources are processed' do
|
111
|
+
# Test the add_invalidation_path method directly
|
112
|
+
Middleman::S3Sync.add_invalidation_path('test/file.html')
|
113
|
+
Middleman::S3Sync.add_invalidation_path('images/photo.jpg')
|
114
|
+
|
115
|
+
expect(Middleman::S3Sync.invalidation_paths).to include('/test/file.html')
|
116
|
+
expect(Middleman::S3Sync.invalidation_paths).to include('/images/photo.jpg')
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'normalizes paths when adding to invalidation list' do
|
120
|
+
Middleman::S3Sync.add_invalidation_path('no-leading-slash.html')
|
121
|
+
|
122
|
+
expect(Middleman::S3Sync.invalidation_paths).to include('/no-leading-slash.html')
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'does not add duplicate paths' do
|
126
|
+
Middleman::S3Sync.add_invalidation_path('/same/path.html')
|
127
|
+
Middleman::S3Sync.add_invalidation_path('/same/path.html')
|
128
|
+
|
129
|
+
expect(Middleman::S3Sync.invalidation_paths.count('/same/path.html')).to eq(1)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-s3_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederic Jean
|
8
8
|
- Will Koehler
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-sdk-cloudfront
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: map
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -312,6 +326,7 @@ files:
|
|
312
326
|
- lib/middleman/redirect.rb
|
313
327
|
- lib/middleman/s3_sync.rb
|
314
328
|
- lib/middleman/s3_sync/caching_policy.rb
|
329
|
+
- lib/middleman/s3_sync/cloudfront.rb
|
315
330
|
- lib/middleman/s3_sync/options.rb
|
316
331
|
- lib/middleman/s3_sync/resource.rb
|
317
332
|
- lib/middleman/s3_sync/status.rb
|
@@ -319,7 +334,9 @@ files:
|
|
319
334
|
- lib/middleman_extension.rb
|
320
335
|
- middleman-s3_sync.gemspec
|
321
336
|
- spec/caching_policy_spec.rb
|
337
|
+
- spec/cloudfront_spec.rb
|
322
338
|
- spec/resource_spec.rb
|
339
|
+
- spec/s3_sync_integration_spec.rb
|
323
340
|
- spec/spec_helper.rb
|
324
341
|
homepage: http://github.com/fredjean/middleman-s3_sync
|
325
342
|
licenses:
|
@@ -344,5 +361,7 @@ specification_version: 4
|
|
344
361
|
summary: Tries really, really hard not to push files to S3.
|
345
362
|
test_files:
|
346
363
|
- spec/caching_policy_spec.rb
|
364
|
+
- spec/cloudfront_spec.rb
|
347
365
|
- spec/resource_spec.rb
|
366
|
+
- spec/s3_sync_integration_spec.rb
|
348
367
|
- spec/spec_helper.rb
|