Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
radhermit committed Mar 13, 2023
0 parents commit 95174ce
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: ci

on:
push:
branches-ignore: [release]
paths:
- "lib/**"
- "pkgcraft.gemspec"
- ".github/workflows/ci.yml"
pull_request:
branches: [main]
paths:
- "lib/**"
- "pkgcraft.gemspec"
workflow_dispatch:
inputs:
ruby-version:
required: false
type: string
workflow_call:
inputs:
ruby-version:
required: false
type: string
event-type:
required: true
type: string

jobs:
setup:
runs-on: ubuntu-latest
outputs:
ruby-version: ${{ steps.vars.outputs.ruby-version }}
steps:
- name: Checkout code to determine the minimum supported ruby version
if: ${{ inputs.ruby-version == '' }}
uses: actions/checkout@v3
with:
repository: pkgcraft/pkgcraft-ruby

- name: Set ruby versions to test against
id: vars
run: |
if [[ -n "${{ inputs.ruby-version }}" ]]; then
echo "ruby-version=$(jq 'split(",")' -Rc <(echo '${{ inputs.ruby-version }}'))" >> $GITHUB_OUTPUT
else
min_ver=$(sed -rn '/required_ruby_version/ s/.*= ">= ([0-9](\.[0-9])*)"/\1/p' pkgcraft.gemspec)
if [[ -n ${min_ver} ]]; then
echo "ruby-version=['${min_ver}', '3.2']" >> $GITHUB_OUTPUT
else
exit 1
fi
fi
test:
needs: setup
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
ruby-version: ${{ fromJson(needs.setup.outputs.ruby-version) }}

steps:
- name: Set pkgcraft dir env var
run: echo pkgcraft_dir=~/pkgcraft >> $GITHUB_ENV

- name: Download pkgcraft-c library from most recent run
if: ${{ inputs.event-type == '' }}
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{ secrets.PKGCRAFT_CI_TOKEN }}
repo: pkgcraft/pkgcraft
branch: main
workflow: pkgcraft-c.yml
workflow_conclusion: ""
search_artifacts: true
name: pkgcraft-c-${{ runner.os }}
path: ${{ env.pkgcraft_dir }}

- name: Download pkgcraft-c library from running workflow
if: ${{ inputs.event-type != '' }}
uses: actions/download-artifact@v3
with:
name: pkgcraft-c-${{ runner.os }}
path: ${{ env.pkgcraft_dir }}

- name: Checkout code
uses: actions/checkout@v3

- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Install dependencies
run: bundle install

- name: Override build variables
run: |
echo "PKG_CONFIG_PATH=${pkgcraft_dir}" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=${pkgcraft_dir}/lib" >> $GITHUB_ENV
echo "DYLD_LIBRARY_PATH=${pkgcraft_dir}/lib" >> $GITHUB_ENV
- run: bundle exec rake
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: lint

on:
push:
branches-ignore: [release]
paths:
- "lib/**"
- "test/**"
- ".github/workflows/lint.yml"
pull_request:
branches: [main]
paths:
- "lib/**"
- "test/**"

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2

- name: Install RuboCop
run: gem install rubocop

- name: Lint code
run: rubocop
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
14 changes: 14 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
AllCops:
NewCops: enable
TargetRubyVersion: 3.0

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes

Layout/LineLength:
Max: 120
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec

gem "minitest", "~> 5.0"
gem "rake", "~> 13.0"
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 Tim Harder

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[![ci](https://github.com/pkgcraft/pkgcraft-ruby/workflows/ci/badge.svg)](https://github.com/pkgcraft/pkgcraft-ruby/actions/workflows/ci.yml)

# pkgcraft-ruby

Ruby bindings for pkgcraft.
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/test_*.rb"]
end

task default: %i[test]
8 changes: 8 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "pkgcraft"

require "irb"
IRB.start(__FILE__)
6 changes: 6 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install
17 changes: 17 additions & 0 deletions lib/pkgcraft.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require "ffi"
require_relative "pkgcraft/_version"

# Bindings for pkgcraft
module Pkgcraft
# version requirements for pkgcraft C library
MINVER = "0.0.7"
MAXVER = "0.0.7"

class Error < StandardError; end

extend FFI::Library
ffi_lib ["pkgcraft"]
attach_function :pkgcraft_lib_version, [], :string
end
5 changes: 5 additions & 0 deletions lib/pkgcraft/_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Pkgcraft
VERSION = "0.0.1"
end
32 changes: 32 additions & 0 deletions pkgcraft.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require_relative "lib/pkgcraft/_version"

Gem::Specification.new do |spec|
spec.name = "pkgcraft"
spec.version = Pkgcraft::VERSION
spec.authors = ["Tim Harder"]
spec.email = ["[email protected]"]

spec.summary = "Ruby bindings for pkgcraft"
spec.homepage = "https://github.com/pkgcraft/pkgcraft-ruby"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.0"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/pkgcraft/pkgcraft-ruby.git"
spec.metadata["rubygems_mfa_required"] = "true"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |f|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
end
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "ffi", "~> 1.15"
end
4 changes: 4 additions & 0 deletions sig/pkgcraft.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pkgcraft
VERSION: String
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
end
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "pkgcraft"

require "minitest/autorun"
17 changes: 17 additions & 0 deletions test/test_pkgcraft.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require "test_helper"

class TestPkgcraft < Minitest::Test
def test_that_it_has_a_version_number
refute_nil Pkgcraft::VERSION
end

def test_pkgcraft_c_version
version = Gem::Version.new(Pkgcraft.pkgcraft_lib_version)
minver = Gem::Version.new(Pkgcraft::MINVER)
maxver = Gem::Version.new(Pkgcraft::MAXVER)
assert(version >= minver, "pkgcraft C library #{version} fails requirement >=#{minver}")
assert(version <= maxver, "pkgcraft C library #{version} fails requirement <=#{maxver}")
end
end

0 comments on commit 95174ce

Please sign in to comment.