bard 1.7.3 → 1.7.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68411db6b0d930d06cc7708835eaa23d10cbedc42eb905bec4065c47834f488a
4
- data.tar.gz: e2488bd0f625e3aa7a87aa6f3334178dbdff49a19a7c020d2424b073dea3f999
3
+ metadata.gz: d1e8b7a7dc083d479b5322405ddbfc58ecab56967433c5f2a543c7637a86ce28
4
+ data.tar.gz: 3c09e62579e85fa615e2005ed6f5cc2d0068576eba46255791523a211b7c0387
5
5
  SHA512:
6
- metadata.gz: 1cc1f667c31694e70f54621b13d3871e74c011f4fd25ab80b66b6caa325fc89d878f4f4199d4adec314b599c4c9e8162ee12dd3e5830b255e9cfcde1c9504e06
7
- data.tar.gz: 9f9be575ee8baa54d8f175c6a4c9227daa22b360343a1143736168d68b5f91697840819f9ed1f165b07e2cea2660c92bce2e466b72e87bf236f459cff304fed5
6
+ metadata.gz: 2ab06301b535cfe5eb37bb3da892fc6e8a66cb46c6c346bfb0d8279bfd37bba9c495f3c9fc9ffda8663881b7fe333186820cc4c57d36f086c524191dc953da14
7
+ data.tar.gz: 0f55ad3b8d94900354005227d73b86ba3ab25847eb7d88242f89e28fafbd281256755a802a7ca10092bd1571040335a3a4d8de845406af94b4d5a10edd1e9e16
@@ -22,34 +22,55 @@ module Bard
22
22
  private
23
23
 
24
24
  def build_site
25
- system "rm -rf #{@build_dir.sub(@sha, "*")}"
26
- run! <<~SH
27
- set -e
28
- RAILS_ENV=production bundle exec rails s -p 3000 -d --pid tmp/pids/server.pid
29
- OUTPUT=$(bundle exec rake assets:clean assets:precompile 2>&1) || echo "$OUTPUT"
30
-
31
- # Create the output directory and enter it
32
- BUILD=#{@build_dir}
33
- rm -rf $BUILD
34
- mkdir -p $BUILD
35
- cp -R public/assets $BUILD/
36
- cd $BUILD
37
-
38
- # wait until server responds
39
- echo waiting...
40
- curl -s --retry 5 --retry-delay 2 http://localhost:3000 >/dev/null 2>&1
41
-
42
- echo copying...
43
- # Mirror the site to the build folder, ignoring links with query params
44
- wget -nv -r -l inf --no-remove-listing -FEnH --reject-regex "(\\.*)\\?(.*)" http://localhost:3000/ 2>&1
45
-
46
- echo #{@domain} > CNAME
47
- SH
48
- ensure # cleanup
49
- run! <<~SH
50
- cat tmp/pids/server.pid | xargs -I {} kill {}
51
- rm -rf public/assets
52
- SH
25
+ with_locked_port do |port|
26
+ system "rm -rf #{@build_dir.sub(@sha, "*")}"
27
+ run! <<~SH
28
+ set -e
29
+ RAILS_ENV=production bundle exec rails s -p #{port} -d --pid tmp/pids/server.pid
30
+ OUTPUT=$(bundle exec rake assets:clean assets:precompile 2>&1) || echo "$OUTPUT"
31
+
32
+ # Create the output directory and enter it
33
+ BUILD=#{@build_dir}
34
+ rm -rf $BUILD
35
+ mkdir -p $BUILD
36
+ cp -R public/assets $BUILD/
37
+ cd $BUILD
38
+
39
+ # wait until server responds
40
+ echo waiting...
41
+ curl -s --retry 5 --retry-delay 2 http://localhost:#{port} >/dev/null 2>&1
42
+
43
+ echo copying...
44
+ # Mirror the site to the build folder, ignoring links with query params
45
+ wget -nv -r -l inf --no-remove-listing -FEnH --reject-regex "(\\.*)\\?(.*)" http://localhost:#{port}/ 2>&1
46
+
47
+ echo #{@domain} > CNAME
48
+ SH
49
+ ensure # cleanup
50
+ run! <<~SH
51
+ cat tmp/pids/server.pid | xargs -I {} kill {}
52
+ rm -rf public/assets
53
+ SH
54
+ end
55
+ end
56
+
57
+ def with_locked_port
58
+ (3000..3020).each do |port|
59
+ lock_file = "/tmp/bard_github_pages_#{port}.lock"
60
+ file = File.open(lock_file, File::RDWR | File::CREAT, 0644)
61
+ if file.flock(File::LOCK_EX | File::LOCK_NB)
62
+ begin
63
+ yield port
64
+ return
65
+ ensure
66
+ file.flock(File::LOCK_UN)
67
+ file.close
68
+ end
69
+ else
70
+ file.close
71
+ end
72
+ end
73
+ raise "Could not find an available port for GitHub Pages deployment (checked 3000-3020)."
53
74
  end
54
75
 
55
76
  def create_tree_from_build
data/lib/bard/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "1.7.3"
2
+ VERSION = "1.7.4"
3
3
  end
4
4
 
@@ -38,6 +38,69 @@ describe Bard::GithubPages do
38
38
  end
39
39
  end
40
40
 
41
+ describe "#build_site" do
42
+ it "uses the locked port" do
43
+ github_pages.instance_variable_set(:@sha, "abc123")
44
+ github_pages.instance_variable_set(:@build_dir, "tmp/github-build-abc123")
45
+ github_pages.instance_variable_set(:@domain, "example.com")
46
+
47
+ allow(github_pages).to receive(:with_locked_port).and_yield(3005)
48
+
49
+ expect(github_pages).to receive(:run!).with(satisfy { |cmd|
50
+ cmd.include?("rails s -p 3005") && cmd.include?("http://localhost:3005")
51
+ }).ordered
52
+
53
+ expect(github_pages).to receive(:run!).with(include("kill")).ordered
54
+
55
+ github_pages.send(:build_site)
56
+ end
57
+ end
58
+
59
+ describe "#with_locked_port" do
60
+ let(:file_mock) { double("file", close: true) }
61
+
62
+ before do
63
+ allow(File).to receive(:open).and_return(file_mock)
64
+ end
65
+
66
+ it "yields the first available port" do
67
+ allow(file_mock).to receive(:flock).and_return(true)
68
+
69
+ expect(File).to receive(:open).with("/tmp/bard_github_pages_3000.lock", anything, anything)
70
+
71
+ yielded_port = nil
72
+ github_pages.send(:with_locked_port) { |p| yielded_port = p }
73
+ expect(yielded_port).to eq(3000)
74
+ end
75
+
76
+ it "retries if the first port is locked" do
77
+ # 1. Try port 3000
78
+ expect(File).to receive(:open).with("/tmp/bard_github_pages_3000.lock", anything, anything).ordered
79
+ expect(file_mock).to receive(:flock).with(File::LOCK_EX | File::LOCK_NB).and_return(false).ordered
80
+ expect(file_mock).to receive(:close).ordered
81
+
82
+ # 2. Try port 3001
83
+ expect(File).to receive(:open).with("/tmp/bard_github_pages_3001.lock", anything, anything).ordered
84
+ expect(file_mock).to receive(:flock).with(File::LOCK_EX | File::LOCK_NB).and_return(true).ordered
85
+
86
+ # 3. Cleanup after yielding
87
+ expect(file_mock).to receive(:flock).with(File::LOCK_UN).ordered
88
+ expect(file_mock).to receive(:close).ordered
89
+
90
+ yielded_port = nil
91
+ github_pages.send(:with_locked_port) { |p| yielded_port = p }
92
+ expect(yielded_port).to eq(3001)
93
+ end
94
+
95
+ it "raises an error if no ports are available" do
96
+ allow(file_mock).to receive(:flock).and_return(false)
97
+
98
+ expect {
99
+ github_pages.send(:with_locked_port) {}
100
+ }.to raise_error(/Could not find an available port/)
101
+ end
102
+ end
103
+
41
104
  describe "#get_parent_commit" do
42
105
  it "returns the sha of the gh-pages branch" do
43
106
  github_pages.instance_variable_set(:@branch, "gh-pages")
@@ -77,4 +140,4 @@ describe Bard::GithubPages do
77
140
  end
78
141
  end
79
142
  end
80
- end
143
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-12-15 00:00:00.000000000 Z
10
+ date: 2025-12-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor