-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a "custom" language option toallow for customization of every command and step in mono. This way you don't have to reuse another language option and potentially running scripts not meant for that language. Allow custom package version scripts to be run so we don't need to implement this for Python right now, while we figure out how we want it to work.
- Loading branch information
Showing
9 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
bump: "minor" | ||
type: "add" | ||
--- | ||
|
||
Support custom languages with the custom language option. Example custom language configuration: | ||
|
||
```yaml | ||
--- | ||
language: custom | ||
repo: "https://github.com/appsignal/appsignal-python" | ||
bootstrap: | ||
command: "echo bootstrap" | ||
clean: | ||
command: "hatch clean" | ||
build: | ||
command: "hatch build" | ||
publish: | ||
command: "hatch publish" | ||
test: | ||
command: "hatch run test:pytest" | ||
read_version: "hatch version" | ||
write_version: "hatch version" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mono | ||
module Languages | ||
module Custom | ||
class Language < Language::Base | ||
def bootstrap(_options = {}) | ||
# noop | ||
end | ||
|
||
def unbootstrap(_options = {}) | ||
# noop | ||
end | ||
|
||
def clean(_options = {}) | ||
# noop | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mono | ||
module Languages | ||
module Custom | ||
class Package < PackageBase | ||
def current_version | ||
@current_version ||= | ||
if config.config?("read_version") | ||
version = run_command_in_package( | ||
config.config("read_version"), | ||
:capture => true, | ||
:print_command => false | ||
).strip | ||
Version.parse(version) | ||
else | ||
raise NotImplementedError, | ||
"Please add `read_version` config to `mono.yml` file." | ||
end | ||
end | ||
|
||
# Not supported | ||
def dependencies | ||
[] | ||
end | ||
|
||
def update_spec | ||
if config.config?("write_version") | ||
run_command_in_package( | ||
[ | ||
config.config("write_version"), | ||
next_version | ||
].join(" "), | ||
:print_command => false | ||
) | ||
else | ||
raise NotImplementedError, | ||
"Please add `write_version` config to `mono.yml` file." | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Mono::Cli::Publish do | ||
include PublishHelper | ||
|
||
around { |example| with_mock_stdin { example.run } } | ||
|
||
it "publishes the package" do | ||
mono_config = { | ||
"build" => { "command" => "echo build" }, | ||
"publish" => { "command" => "echo publish" }, | ||
"read_version" => "cat version.py", | ||
"write_version" => "ruby write_version_file.rb" | ||
} | ||
prepare_custom_project mono_config do | ||
create_version_file "1.2.3" | ||
File.write("write_version_file.rb", %(File.write("version.py", ARGV[0]))) | ||
add_changeset :patch | ||
end | ||
confirm_publish_package | ||
output = run_publish_process | ||
|
||
project_dir = "/#{current_project}" | ||
next_version = "1.2.4" | ||
|
||
expect(output).to include(<<~OUTPUT), output | ||
The following packages will be published (or not): | ||
- #{current_project}: | ||
Current version: v1.2.3 | ||
Next version: v1.2.4 (patch) | ||
OUTPUT | ||
expect(output).to include(<<~OUTPUT), output | ||
# Updating package versions | ||
- #{current_project}: | ||
Current version: v1.2.3 | ||
Next version: v1.2.4 (patch) | ||
OUTPUT | ||
|
||
in_project do | ||
expect(File.read("version.py")).to include(next_version) | ||
expect(current_package_changeset_files.length).to eql(0) | ||
|
||
changelog = File.read("CHANGELOG.md") | ||
expect_changelog_to_include_version_header(changelog, next_version) | ||
expect_changelog_to_include_release_notes(changelog, :patch) | ||
|
||
expect(local_changes?).to be_falsy, local_changes.inspect | ||
expect(commited_files).to eql([ | ||
".changesets/1_patch.md", | ||
"CHANGELOG.md", | ||
"version.py" | ||
]) | ||
end | ||
|
||
expect(performed_commands).to eql([ | ||
[project_dir, "cat version.py"], | ||
[project_dir, "ruby write_version_file.rb #{next_version}"], | ||
[project_dir, "echo build"], | ||
[project_dir, "git add -A"], | ||
[project_dir, "git commit -m 'Publish packages' -m '- v#{next_version}' -m '[ci skip]'"], | ||
[project_dir, "git tag v#{next_version}"], | ||
[project_dir, "echo publish"], | ||
[project_dir, "git push origin main v#{next_version}"] | ||
]) | ||
expect(exit_status).to eql(0), output | ||
end | ||
|
||
def prepare_custom_project(config = {}) | ||
prepare_new_project do | ||
create_mono_config({ "language" => "custom" }.merge(config)) | ||
yield | ||
end | ||
end | ||
|
||
def create_version_file(version) | ||
File.write("version.py", version) | ||
end | ||
|
||
def run_publish_process(failed_commands: [], stubbed_commands: [/^git push/]) | ||
output = | ||
capture_stdout do | ||
in_project do | ||
perform_commands do | ||
fail_commands failed_commands do | ||
stub_commands stubbed_commands do | ||
run_publish | ||
end | ||
end | ||
end | ||
end | ||
end | ||
strip_changeset_output output | ||
end | ||
end |