Skip to content

Commit

Permalink
Fourier improvements (tuist#2676)
Browse files Browse the repository at this point in the history
* Move Fourier to projects

* Add command to lint the Swift code

* Add command to lint fourier's code

* Add command to format Swift's code

* Update git hook to run fourier

* Add tests

* Fix the fourier path

* Add command to test Tuist
  • Loading branch information
Pedro Piñera Buendía authored Mar 17, 2021
1 parent 9c1db84 commit cbc4e46
Show file tree
Hide file tree
Showing 67 changed files with 317 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fourier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
bundle install --jobs 4 --retry 3
- name: Unit tests
run: |
bundle exec rake test_fourier
./fourier test fourier
rubocop:
name: Rubocop
runs-on: ubuntu-latest
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/meta-tuist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ jobs:
bundle install --jobs 4 --retry 3
- name: Generate Xcode project
run: |
./bin/fourier generate tuist
./fourier generate tuist
- name: Build
run: |
./bin/fourier build tuist all
./fourier build tuist all
test:
name: Test with Xcode ${{ matrix.xcode }}
runs-on: macos-latest
Expand All @@ -72,7 +72,7 @@ jobs:
bundle install --jobs 4 --retry 3
- name: Generate Xcode project
run: |
./bin/fourier generate tuist
./fourier generate tuist
- name: Test
run: |
./bin/fourier test tuist unit
./fourier test tuist unit
4 changes: 2 additions & 2 deletions .github/workflows/tuist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
bundle install --jobs 4 --retry 3
- name: Run tests
run: |
./bin/fourier test tuist unit
./fourier test tuist unit
release_build:
name: Release build with Xcode ${{ matrix.xcode }}
runs-on: macOS-latest
Expand Down Expand Up @@ -127,4 +127,4 @@ jobs:
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Run tests
run: ./bin/fourier test tuist acceptance features/${{ matrix.feature }}.feature
run: ./fourier test tuist acceptance features/${{ matrix.feature }}.feature
2 changes: 1 addition & 1 deletion .shadowenv.d/fourier.lisp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(env/prepend-to-pathlist "PATH" (expand-path "./bin"))
(env/prepend-to-pathlist "PATH" (expand-path "."))
6 changes: 2 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ gem "rubyzip", "~> 2.3.0"
gem "ruby-macho", "~> 1.4"
gem "cli-ui", "~> 1.4"
gem "thor", "~> 1.1"
gem "octokit", "~> 4.20"
gem "zeitwerk", "~> 2.4"

group :test do
gem "mocha", "~> 1.12"
Expand All @@ -31,7 +33,3 @@ end
group :development, :test do
gem "byebug", "~> 11.1"
end

gem "octokit", "~> 4.20"

gem "zeitwerk", "~> 2.4"
47 changes: 0 additions & 47 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ require "json"
require "zip"
require "macho"

desc("Runs the Fourier tests")
Rake::TestTask.new do |t|
t.name = "test_fourier"
t.libs += [File.expand_path("./tools/fourier/test", __dir__)]
test_root = File.expand_path("./tools/fourier/test", __dir__)
t.test_files = FileList[File.join(test_root, "**", "*_test.rb")]
t.verbose = false
t.warning = false
end

desc("Updates swift-doc binary with the latest version available.")
task :swift_doc_update do
root_dir = File.expand_path(__dir__)
Expand Down Expand Up @@ -113,31 +103,6 @@ task :xcbeautify_update do
File.write(File.join(root_dir, "vendor/.xcbeautify.version"), XCBEAUTIFY_VERSION)
end

desc("Formats the code style")
task :style_correct do
system(code_style_path)
end

desc("Swift format check")
task :swift_format do
Kernel.system(swiftformat_path, "--lint", ".") || abort
end

desc("Swift lint check")
task :swift_lint do
Kernel.system(swiftlint_path) || abort
end

desc("Lints the Ruby code style")
task :style_ruby do
system("bundle", "exec", "rubocop")
end

desc("Corrects the issues with the Ruby style")
task :style_ruby_correct do
system("bundle", "exec", "rubocop", "-a")
end

desc("Builds and archive a release version of tuist and tuistenv for local testing.")
task :local_package do
package
Expand Down Expand Up @@ -233,18 +198,6 @@ task :benchmark do
)
end

def swiftformat_path
File.expand_path("bin/swiftformat", __dir__)
end

def swiftlint_path
File.expand_path("bin/swiftlint", __dir__)
end

def code_style_path
File.expand_path("script/code_style.sh", __dir__)
end

def decrypt_secrets
Encrypted::Environment.load_from_ejson("secrets.ejson", private_key: ENV["SECRET_KEY"])
end
Expand Down
2 changes: 1 addition & 1 deletion bin/fourier → fourier
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require "pathname"
require "bundler/setup"

# Load fourier's directory
fourier_directory = File.expand_path("../tools/fourier/lib", __dir__)
fourier_directory = File.expand_path("./projects/fourier/lib", __dir__)
$LOAD_PATH.unshift(fourier_directory) unless $LOAD_PATH.include?(fourier_directory)

# Load Fourier
Expand Down
4 changes: 3 additions & 1 deletion hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

script/code_style.sh
./fourier lint tuist
./fourier lint fourier
./fourier format tuist
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# frozen_string_literal: true

require "cli/ui"
require "zeitwerk"
require "thor"

loader = Zeitwerk::Loader.new
loader.push_dir(__dir__)
loader.inflector.inflect("github_client" => "GitHubClient")
loader.inflector.inflect("github" => "GitHub")
loader.setup

module Fourier
class CLI < Thor
desc "test", "Run tests"
Expand All @@ -18,6 +27,12 @@ class CLI < Thor
desc "edit", "Edit Tuist's project manifest in Xcode"
subcommand "edit", Commands::Edit

desc "lint", "Lint the project's code"
subcommand "lint", Commands::Lint

desc "format", "Format the project's code"
subcommand "format", Commands::Format

desc "focus TARGET", "Edit Tuist's project focusing on the target TARGET"
def focus(target)
Services::Focus.call(target: target)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
module Fourier
module Commands
class Build < Base
autoload :Tuist, "fourier/commands/build/tuist"

desc "tuist SUBCOMMAND ...ARGS", "Build Tuist"
subcommand "tuist", Commands::Build::Tuist
end
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions projects/fourier/lib/fourier/commands/format.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true
module Fourier
module Commands
class Format < Base
desc "tuist", "Format the source code of the Tuist CLI"
option :fix, desc: "When passed, it fixes the issues", type: :boolean, default: false
def tuist
Services::Format::Tuist.call(fix: options[:fix])
end
end
end
end
25 changes: 25 additions & 0 deletions projects/fourier/lib/fourier/commands/lint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true
module Fourier
module Commands
class Lint < Base
desc "tuist", "Lint the source code of the Tuist CLI"
option :fix, desc: "When passed, it fixes the issues", type: :boolean, default: false
def tuist
Services::Lint::Tuist.call(fix: options[:fix])
end

desc "fourier", "Lint the source code of the Fourier CLI"
option :fix, desc: "When passed, it fixes the issues", type: :boolean, default: false
def fourier
Services::Lint::Fourier.call(fix: options[:fix])
end

desc "all", "Lint all the code in the repository"
option :fix, desc: "When passed, it fixes the issues", type: :boolean, default: false
def all
Services::Lint::Tuist.call(fix: options[:fix])
Services::Lint::Fourier.call(fix: options[:fix])
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
module Fourier
module Commands
class Test < Base
autoload :Tuist, "fourier/commands/test/tuist"

desc "tuist SUBCOMMAND ...ARGS", "Run Tuist tests"
subcommand "tuist", Commands::Test::Tuist

desc "fourier", "Run Fourier tests"
def fourier
Services::Test::Fourier.call
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Fourier
module Constants
ROOT_DIRECTORY = File.expand_path("../../../..", __dir__)
VENDOR_DIRECTORY = File.expand_path("../../vendor", __dir__)
REPOSITORY = "tuist/tuist"
end
end
30 changes: 30 additions & 0 deletions projects/fourier/lib/fourier/services/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true
module Fourier
module Services
class Base
def self.call(*args, &block)
new(*args).call(&block)
end

def call
raise NotImplementedError
end

def root_directory
Fourier::Constants::ROOT_DIRECTORY
end

def fourier_directory
File.join(Fourier::Constants::ROOT_DIRECTORY, "projects/fourier")
end

def tuist_directory
File.join(Fourier::Constants::ROOT_DIRECTORY)
end

def vendor_path(path)
File.join(Fourier::Constants::VENDOR_DIRECTORY, path)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Build
module Tuist
class All < Base
def call
Dir.chdir(Constants::ROOT_DIRECTORY) do
Dir.chdir(tuist_directory) do
Utilities::System.tuist("build")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Build
module Tuist
class Support < Base
def call
Dir.chdir(Constants::ROOT_DIRECTORY) do
Dir.chdir(tuist_directory) do
Utilities::System.tuist("build", "TuistSupport")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Services
module Edit
class Tuist < Base
def call
Dir.chdir(Constants::ROOT_DIRECTORY) do
Dir.chdir(tuist_directory) do
Utilities::System.tuist("edit", "--only-current-directory")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(target:)
end

def call
Dir.chdir(Constants::ROOT_DIRECTORY) do
Dir.chdir(tuist_directory) do
Utilities::System.tuist("focus", target)
end
end
Expand Down
24 changes: 24 additions & 0 deletions projects/fourier/lib/fourier/services/format/tuist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true
module Fourier
module Services
module Format
class Tuist < Base
attr_reader :fix

def initialize(fix:)
@fix = fix
end

def call
Dir.chdir(tuist_directory) do
arguments = [vendor_path("swiftformat"), ".", "--quiet"]
unless fix
arguments << "--lint"
end
Fourier::Utilities::System.system(*arguments)
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(open: false)
end

def call
Dir.chdir(Constants::ROOT_DIRECTORY) do
Dir.chdir(tuist_directory) do
arguments = ["generate"]
arguments << "--open" if open
Utilities::System.tuist(*arguments)
Expand Down
24 changes: 24 additions & 0 deletions projects/fourier/lib/fourier/services/lint/fourier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true
module Fourier
module Services
module Lint
class Fourier < Base
attr_reader :fix

def initialize(fix:)
@fix = fix
end

def call
Dir.chdir(fourier_directory) do
gem_path = Gem.loaded_specs["rubocop"].full_gem_path
executable_path = File.join(gem_path, "exe/rubocop")
arguments = [executable_path]
arguments << "-A" if fix
Utilities::System.system(*arguments)
end
end
end
end
end
end
Loading

0 comments on commit cbc4e46

Please sign in to comment.