Skip to content

Commit

Permalink
chore: Gemfile consistent method for defining local gem source
Browse files Browse the repository at this point in the history
  • Loading branch information
lwoggardner committed Jan 20, 2023
1 parent c12e958 commit 0e16bf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

source 'https://rubygems.org'

LOCAL_GEM_PATH = ENV.fetch('LOCAL_GEMS', '..')
AVAILABLE_LOCAL_GEMS = %w[ffi].freeze
LOCAL_GEM_PATH = ENV.fetch('LOCAL_GEM_PATH', '..')
LOCAL_GEMS = ENV.fetch('LOCAL_GEMS', AVAILABLE_LOCAL_GEMS.join(';')).split(/[,;]|\s+/)

def local_gem(gem_name, **options)
options[:path] = "#{LOCAL_GEM_PATH}/#{gem_name}" if Dir.exist?("#{LOCAL_GEM_PATH}/#{gem_name}")
gem gem_name, **options
end

%w[ffi].each { |g| local_gem g }
(AVAILABLE_LOCAL_GEMS & LOCAL_GEMS).each { |g| local_gem(g) }

gemspec
11 changes: 2 additions & 9 deletions lib/ffi/libfuse/gem_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ module FFI
module Libfuse
# @!visibility private
class GemHelper
SEMVER_TAG_REGEX = /^v\d+\.\d+\.\d+/.freeze

# branches the format is refs/heads/<branch_name>,
# tags it is refs/tags/<tag_name>.
# for pull requests it is refs/pull/<pr_number>/merge,
GIT_REF_TYPES = { 'heads' => :branch, 'tags' => :tag, 'pull' => :pull }.freeze

class << self
# set when install'd.
attr_accessor :instance
Expand All @@ -33,7 +26,7 @@ def git_ref(env: ENV)
return [ref, nil] unless ref&.start_with?('refs/')

_refs, ref_type, ref_name = ref.split('/', 3)
[ref_name, GIT_REF_TYPES[ref_type]]
[ref_name, { 'heads' => :branch, 'tags' => :tag, 'pull' => :pull }[ref_type]]
end

def gem_version(main_branch:, version:, env: ENV)
Expand All @@ -44,7 +37,7 @@ def gem_version(main_branch:, version:, env: ENV)
when :branch
ref_name == main_branch ? [version] : [version, ref_name]
when :tag
SEMVER_TAG_REGEX.match?(ref_name) ? [ref_name[1..]] : [version, ref_name]
/^v\d+\.\d+\.\d+/.match?(ref_name) ? [ref_name[1..]] : [version, ref_name]
when :pull
pr_number, merge, _rest = ref_name.split('/')
# GITHUB_BASE_REF The name of the base ref or target branch of the pull request in a workflow run
Expand Down

0 comments on commit 0e16bf1

Please sign in to comment.