|
4 | 4 | # Copyright, 2026, by Samuel Williams. |
5 | 5 |
|
6 | 6 | require "bake/gem/github/setup" |
7 | | -require "bake/context" |
8 | | -require "sus/fixtures/temporary_directory_context" |
| 7 | +require "bake/gem/github/repository_context" |
9 | 8 |
|
10 | 9 | describe Bake::Gem::GitHub::Setup do |
11 | | - include Sus::Fixtures::TemporaryDirectoryContext |
| 10 | + include Bake::Gem::GitHub::RepositoryContext |
12 | 11 |
|
13 | | - let(:setup) {subject.new(root)} |
| 12 | + let(:setup) {subject.new(repository)} |
14 | 13 |
|
15 | | - before do |
16 | | - setup.generate(repository: "socketry/example", checks: ["Tests"], signing: false) |
17 | | - end |
18 | | - |
19 | | - it "proposes configuration changes and customizations without overwriting them" do |
20 | | - path = File.join(root, "config/release.yaml") |
21 | | - config = YAML.safe_load_file(path) |
22 | | - config["approvals"] = 3 |
23 | | - config["checks"] << "New check" |
24 | | - File.write(path, YAML.dump(config)) |
25 | | - workflow = File.join(root, ".github/workflows/release-validate.yaml") |
26 | | - File.write(workflow, "# Custom workflow\n" + File.read(workflow)) |
27 | | - before = Dir.glob("{config,.github}/**/*", File::FNM_DOTMATCH, base: root).select{|name| File.file?(File.join(root, name))}.to_h{|name| [name, File.read(File.join(root, name))]} |
28 | | - registry = Bake::Registry::Aggregate.new |
29 | | - registry.append_path(::Gem.loaded_specs.fetch("bake-gem-github").full_gem_path) |
30 | | - patch = Bake::Context.new(registry, root).call("gem:github:setup:update") |
31 | | - expect(File.read(patch)).to be(:include?, "-# Custom workflow") |
32 | | - expect(File.read(patch)).to be(:include?, '+ "context": "New check"') |
33 | | - before.each do |name, content| |
34 | | - expect(File.read(File.join(root, name))).to be == content |
| 14 | + with "#update" do |
| 15 | + it "leaves generated updates in the working tree for selective review" do |
| 16 | + workflow = File.join(repository, ".github/workflows/release-validate.yaml") |
| 17 | + File.write(workflow, "# Custom workflow\n" + File.read(workflow)) |
| 18 | + File.write(File.join(repository, ".github/workflows/custom.yaml"), "Custom workflow\n") |
| 19 | + git("add", "--all") |
| 20 | + git("commit", "--quiet", "-m", "Repository customizations") |
| 21 | + original = git("rev-parse", "HEAD") |
| 22 | + path = File.join(repository, "config/release.yaml") |
| 23 | + config = YAML.safe_load_file(path) |
| 24 | + config["approvals"] = 3 |
| 25 | + config["checks"] << "New check" |
| 26 | + File.write(path, YAML.dump(config)) |
| 27 | + registry = Bake::Registry::Aggregate.new |
| 28 | + registry.append_path(::Gem.loaded_specs.fetch("bake-gem-github").full_gem_path) |
| 29 | + changed = Bake::Context.new(registry, repository).call("gem:github:setup:update") |
| 30 | + expect(changed.sort).to be == [".github/release-rules/checks.json", ".github/release-rules/reviews.json", ".github/workflows/release-validate.yaml"] |
| 31 | + diff = git("diff") |
| 32 | + expect(diff).to be(:include?, "-# Custom workflow") |
| 33 | + expect(diff).to be(:include?, '+ "context": "New check"') |
| 34 | + expect(git("rev-parse", "HEAD")).to be == original |
| 35 | + expect(git("diff", "--cached")).to be == "" |
| 36 | + expect(File.read(File.join(repository, ".github/workflows/custom.yaml"))).to be == "Custom workflow\n" |
| 37 | + expect(setup.update).to be == [] |
| 38 | + expect(git("diff")).to be == diff |
| 39 | + expect(YAML.safe_load_file(path)).to be == config |
| 40 | + end |
| 41 | + |
| 42 | + it "restores missing generated files" do |
| 43 | + path = File.join(repository, ".github/releasing.md") |
| 44 | + original = File.read(path) |
| 45 | + File.unlink(path) |
| 46 | + expect(setup.update).to be == [".github/releasing.md"] |
| 47 | + expect(File.read(path)).to be == original |
| 48 | + expect(setup.update).to be == [] |
| 49 | + end |
| 50 | + |
| 51 | + it "refuses unsupported configuration schemas" do |
| 52 | + File.write(File.join(repository, "config/release.yaml"), YAML.dump("schema" => 2)) |
| 53 | + expect{setup.update}.to raise_exception(RuntimeError, message: be =~ /Unsupported release configuration/) |
35 | 54 | end |
36 | | - expect(system("git", "apply", "--check", patch, chdir: root)).to be == true |
37 | | - expect(system("git", "apply", patch, chdir: root)).to be == true |
38 | | - expect(File.read(setup.update)).to be == "" |
39 | | - expect(YAML.safe_load_file(path)).to be == config |
40 | | - end |
41 | | - |
42 | | - it "restores missing generated files through the patch" do |
43 | | - path = File.join(root, ".github/releasing.md") |
44 | | - original = File.read(path) |
45 | | - File.unlink(path) |
46 | | - patch = setup.update |
47 | | - expect(File.exist?(path)).to be == false |
48 | | - expect(system("git", "apply", patch, chdir: root)).to be == true |
49 | | - expect(File.read(path)).to be == original |
50 | | - expect(File.read(setup.update)).to be == "" |
51 | | - end |
52 | | - |
53 | | - it "refuses unsupported configuration schemas" do |
54 | | - File.write(File.join(root, "config/release.yaml"), YAML.dump("schema" => 2)) |
55 | | - expect{setup.update}.to raise_exception(RuntimeError, message: be =~ /Unsupported release configuration/) |
56 | 55 | end |
57 | 56 | end |
0 commit comments