Skip to content
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
14 changes: 12 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,19 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
bundler-cache: false

- name: export CGO_CFLAGS
run: ruby -e "puts %Q(CGO_CFLAGS=-I#{RbConfig::CONFIG['rubyarchhdrdir']} -I#{RbConfig::CONFIG['rubyhdrdir']})" >> $GITHUB_ENV
# FIXME: setup-go installs cache in `vendor/` and setup-ruby installs cache in `vendor/bundle/`
# If we use the cache in setup-go and setup-ruby at the same time, this doesn't work well because they use the same directory.
# Therefore, the installation location needs to be changed from the setup-ruby default.
- name: bundle install
run: |
set -xe
bundle config --local path ruby-vendor/bundle
bundle install --jobs 4

- name: export CGO_CFLAGS for golangci-lint
run: bundle exec rake go:build_envs[CGO_CFLAGS] >> $GITHUB_ENV

- run: echo $CGO_CFLAGS

Expand Down
20 changes: 20 additions & 0 deletions _gem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Following tasks are generated
* `rake go:test`
* `rake go:testrace`
* `rake go:fmt`
* `rake go:build_envs`

#### Example (With config)
```ruby
Expand All @@ -68,6 +69,7 @@ Following tasks are generated
* `rake go5:test`
* `rake go5:testrace`
* `rake go5:fmt`
* `rake go5:build_envs`

#### Example (Add additional tasks)
```ruby
Expand All @@ -89,6 +91,24 @@ namespace :go do
end
```

#### Example (Use [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action))
```yml
jobs:
go-lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: ruby/setup-ruby@v1

- name: export CGO_CFLAGS for golangci-lint
run: bundle exec rake go:build_envs[CGO_CFLAGS] >> $GITHUB_ENV

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
```

#### Available configurations
* `task_namespace` : task namespace (default: `:go`)
* `go_bin_path` : path to go binary (default: `"go"`)
Expand Down
15 changes: 15 additions & 0 deletions _gem/lib/go_gem/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def initialize(gem_name)
define_go_test_task
define_go_testrace_task
define_go_fmt_task
define_go_build_envs_task
end
end

Expand Down Expand Up @@ -168,5 +169,19 @@ def define_go_fmt_task
end
end
end

def define_go_build_envs_task
desc "Print build envs for `go build`"
task(:build_envs, [:env_name]) do |_, args|
if args[:env_name]
value = RakeTask.build_env_vars[args[:env_name]]
puts "#{args[:env_name]}=#{value}"
else
RakeTask.build_env_vars.each do |name, value|
puts "#{name}=#{value}"
end
end
end
end
end
end
2 changes: 2 additions & 0 deletions _gem/sig/go_gem/rake_task.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module GoGem

def define_go_fmt_task: () -> void

def define_go_build_envs_task: () -> void

def within_target_dir: () { () -> void } -> void

def ext_dir: () -> String
Expand Down
21 changes: 21 additions & 0 deletions _gem/sig/non-gemify/rake.rbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# Monkey path to https://github.com/ruby/gem_rbs_collection/blob/main/gems/rake/13.0/rake.rbs

module Rake
class Task
end

class TaskArguments
include Enumerable[untyped]

def []: (untyped index) -> untyped
def each: () ?{ (untyped, untyped) -> void } -> void
end

module DSL
private

def task: (*untyped args) ?{ (Rake::Task, Rake::TaskArguments) -> void } -> void
| ...
end
end

module FileUtils
def sh: (Hash[String, String] env, *String cmd, **untyped options) ?{ (bool, Process::Status) -> void } -> void
| ...
Expand Down
1 change: 1 addition & 0 deletions _gem/spec/go_gem/rake_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
it { should be_task_defined("go:test") }
it { should be_task_defined("go:testrace") }
it { should be_task_defined("go:fmt") }
it { should be_task_defined("go:build_envs") }

describe "Add additional tasks" do
include Rake::DSL
Expand Down
Loading