From b0be3eea6d9036647e3a632505701ddcd835790c Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Thu, 25 Apr 2024 09:41:00 +0800 Subject: [PATCH] feat: Update tools --- .github/workflows/build.yaml | 4 --- .mise.toml | 2 ++ .pre-commit-config.yaml | 18 +++++++++++++ Rakefile | 50 ++++++++++++++++++++++++++++++++++-- 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 .mise.toml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index af0a11a..9144b5b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,12 +10,8 @@ name: Swift Build on: - push: - branches: [main] - paths: ["**/*.swift"] pull_request: branches: [main] - paths: ["**/*.swift"] workflow_dispatch: jobs: diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..207d222 --- /dev/null +++ b/.mise.toml @@ -0,0 +1,2 @@ +[tools] +pre-commit = "3.7.0" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d9bee91 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +default_install_hook_types: [pre-commit, pre-push] +fail_fast: true + +repos: +- repo: local + hooks: + - id: lint + name: Run Lint + language: system + entry: rake swift:lint + stages: [pre-commit] + verbose: true + - id: build + name: Run Build + language: system + entry: rake swift:build + stages: [pre-push] + verbose: true diff --git a/Rakefile b/Rakefile index 6c7d9ae..ed554c9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,53 @@ -FORMAT_COMMAND = 'swift package --allow-writing-to-package-directory format' -BUILD_COMMAND = 'xcodebuild -scheme RakuyoKit -destination' +namespace :env do + MISE_EXEC_PREFIX = 'mise exec --' + + desc 'Init env' + task :init do + if File.exist?('.mise.toml') + install_mise + puts "mise installed: #{`mise --version`}" + sh "mise install" + end + + if File.exist?('.pre-commit-config.yaml') + Rake::Task['env:githook'].invoke + end + end + + desc 'Install git hook' + task :githook do + sh "#{MISE_EXEC_PREFIX} pre-commit install" + end + + def install_mise + output = `which mise >/dev/null 2>&1` + if $?.success? + return + end + + puts "mise not found, installing..." + sh "curl https://mise.run | sh" + + case ENV['SHELL'] + when /bash/ + sh 'echo "eval \"\$(~/.local/bin/mise activate bash)\"" >> ~/.bashrc' + sh "source ~/.bashrc" + + when /zsh/ + sh 'echo "eval \"\$(~/.local/bin/mise activate zsh)\"" >> ~/.zshrc' + sh "zsh -c 'source ~/.zshrc'" + + else + puts "Unknown shell env!" + exit 1 + end + end +end namespace :swift do + FORMAT_COMMAND = 'swift package --allow-writing-to-package-directory format' + BUILD_COMMAND = 'xcodebuild -scheme RakuyoKit -destination' + desc 'Run Format' task :format do sh FORMAT_COMMAND