Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update tools #11

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
name: Swift Build

on:
push:
branches: [main]
paths: ["**/*.swift"]
pull_request:
branches: [main]
paths: ["**/*.swift"]
workflow_dispatch:

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
pre-commit = "3.7.0"
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 48 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down