diff --git a/.claude/rules/ruby/smalruby3.md b/.claude/rules/ruby/smalruby3.md index f3e1990f75c..b6cc3a7308a 100644 --- a/.claude/rules/ruby/smalruby3.md +++ b/.claude/rules/ruby/smalruby3.md @@ -12,6 +12,50 @@ paths: smalruby3 は scratch-vm の Ruby 実装。smalruby3-editor で生成した Ruby スクリプトをデスクトップでネイティブ実行する。 +## RubyGems 公開 + +- **gem 名**: `smalruby3`(https://rubygems.org/gems/smalruby3) +- **所有者**: Kouji Takao + +### バージョニング: YY.MR.DDR + +semantic versioning 互換かつリリース日推測可能な形式: + +| フィールド | 意味 | 例 | +|-----------|------|-----| +| `YY` (MAJOR) | 年の下2桁 | `26` = 2026 | +| `MR` (MINOR) | 月 × 10 + 月内リリース番号 | `31` = 3月1回目, `32` = 3月2回目 | +| `DDR` (PATCH) | 日 × 10 + 日内リリース番号 | `291` = 29日1回目, `292` = 29日2回目 | + +**例**: +- `26.31.291` — 2026年3月29日、月内1回目、日内1回目 +- `26.31.292` — 同日2回目 +- `26.32.301` — 3月30日、月内2回目(機能追加) +- `26.41.11` — 4月1日、月内1回目 + +**CRITICAL**: MINOR を上げても月が変わったことを意味しない。月内の機能リリース回数を表す。 + +### ライセンス + +- **smalruby3 本体**: MIT +- **依存ライブラリ**(LICENSE の Third-Party Notices に記載): + - ruby-sdl2: LGPL-3.0(gem 依存、動的リンク) + - resvg: MPL-2.0(Rust crate、smalruby3_imageutil にコンパイル) + - rsdl: Ruby's License(smalruby3_launcher の元コード) + +### gem ビルド・公開 + +```bash +# ビルド +cd ruby/smalruby3 +gem build smalruby3.gemspec + +# 公開 +gem push smalruby3-YY.MR.DDR.gem +``` + +**注意**: `spec.files` は `Dir[...]` で列挙し、`ext/smalruby3_imageutil/target/` を除外する。 + ## Tech Stack - **Ruby**: 3.3+ (`rbenv local 3.3.9` が設定済み) diff --git a/.claude/skills/gem-release/SKILL.md b/.claude/skills/gem-release/SKILL.md new file mode 100644 index 00000000000..29949777a2e --- /dev/null +++ b/.claude/skills/gem-release/SKILL.md @@ -0,0 +1,98 @@ +--- +name: gem-release +description: "Build and release the smalruby3 gem to RubyGems. Handles version bump, gem build, and push." +argument-hint: "[version e.g. 26.31.291]" +--- + +# /gem-release - smalruby3 gem リリース + +smalruby3 gem をビルドして RubyGems に公開する。 + +## 引数 + +- `$ARGUMENTS` — リリースバージョン(例: `26.31.291`) + +バージョン未指定の場合は `ruby/smalruby3/lib/smalruby3/version.rb` の現在のバージョンを使用する。 + +## バージョニング: YY.MR.DDR + +| フィールド | 意味 | 例 | +|-----------|------|-----| +| YY (MAJOR) | 年の下2桁 | 26 = 2026 | +| MR (MINOR) | 月 × 10 + 月内リリース番号 | 31 = 3月1回目 | +| DDR (PATCH) | 日 × 10 + 日内リリース番号 | 291 = 29日1回目 | + +## 手順 + +### Step 1: バージョン確認・更新 + +1. `ruby/smalruby3/lib/smalruby3/version.rb` の現在のバージョンを読む +2. 引数でバージョンが指定されている場合: + - `version.rb` を更新する + - YY.MR.DDR 形式であることを検証する +3. 引数がない場合: + - 現在のバージョンをそのまま使用する + - ユーザーに確認: 「バージョン X.XX.XXX でリリースしますか?」 + +### Step 2: テスト・lint + +```bash +docker compose run --rm smalruby3 bash -c "bundle exec standardrb && bundle exec rake test" +``` + +テストが失敗した場合はリリースを中止する。 + +### Step 3: gem ビルド + +```bash +cd ruby/smalruby3 +gem build smalruby3.gemspec +``` + +ビルド成功を確認し、`gem specification smalruby3-VERSION.gem` で metadata を表示する。 + +### Step 4: ユーザーに最終確認 + +以下を表示してユーザーに確認を求める: +- バージョン +- gem ファイル名 +- gem に含まれるファイル数 +- 依存関係 + +「`gem push` を実行してよいですか?」と確認する。 + +### Step 5: gem push + +**IMPORTANT**: この手順はユーザーの明示的な承認後のみ実行する。 + +```bash +cd ruby/smalruby3 +gem push smalruby3-VERSION.gem +``` + +初回は認証情報の入力が必要。ユーザーに `! gem push smalruby3-VERSION.gem` の実行を案内する(インタラクティブ認証が必要なため)。 + +### Step 6: タグ付け・コミット・プッシュ + +1. バージョン更新がある場合はコミット: + ```bash + git add ruby/smalruby3/lib/smalruby3/version.rb + git commit -m "release: smalruby3 vVERSION" + ``` + +2. タグを作成: + ```bash + git tag smalruby3-vVERSION + ``` + +3. プッシュ: + ```bash + git push origin HEAD + git push origin smalruby3-vVERSION + ``` + +### Step 7: 完了報告 + +- RubyGems の URL: https://rubygems.org/gems/smalruby3/versions/VERSION +- タグ: `smalruby3-vVERSION` +- 次回リリース時のバージョン例を提示 diff --git a/.github/workflows/ci-ruby.yml b/.github/workflows/ci-ruby.yml index 093bc207bd0..214a9c0c0f2 100644 --- a/.github/workflows/ci-ruby.yml +++ b/.github/workflows/ci-ruby.yml @@ -36,8 +36,12 @@ jobs: run: bundle exec standardrb unit-test: - name: "[smalruby3] Unit Tests" + name: "[smalruby3] Unit Tests (Ruby ${{ matrix.ruby }})" runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['3.3', '3.4', '4.0'] defaults: run: working-directory: ruby/smalruby3 @@ -51,7 +55,7 @@ jobs: uses: dtolnay/rust-toolchain@stable - uses: ruby/setup-ruby@v1 with: - ruby-version-file: ruby/smalruby3/.ruby-version + ruby-version: ${{ matrix.ruby }} bundler-cache: true working-directory: ruby/smalruby3 - name: Compile native extension diff --git a/.github/workflows/gem-build-check.yml b/.github/workflows/gem-build-check.yml new file mode 100644 index 00000000000..08edc884e99 --- /dev/null +++ b/.github/workflows/gem-build-check.yml @@ -0,0 +1,124 @@ +name: Gem Build Check (cross-platform) + +on: + workflow_dispatch: + inputs: + ruby-version: + description: 'Ruby version to test' + required: false + default: '3.4' + type: choice + options: + - '3.3' + - '3.4' + - '4.0' + +concurrency: + group: "${{ github.workflow }} @ ${{ github.head_ref || github.ref }}" + cancel-in-progress: true + +jobs: + build-linux: + name: "Build gem (Linux / Ruby ${{ inputs.ruby-version || '3.4' }})" + runs-on: ubuntu-latest + defaults: + run: + working-directory: ruby/smalruby3 + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + + - name: Install SDL2 development libraries + run: | + sudo apt-get update + sudo apt-get install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ inputs.ruby-version || '3.4' }} + bundler-cache: true + working-directory: ruby/smalruby3 + + - name: Build gem + run: gem build smalruby3.gemspec + + - name: Install gem locally + run: gem install --local smalruby3-*.gem --no-document + + - name: Compile native extension + run: bundle exec rake compile + + - name: Run tests + run: bundle exec rake test + + - name: Verify smalruby3 loads + run: ruby -r smalruby3 -e 'puts "smalruby3 v#{Smalruby3::VERSION} loaded OK"' + + - name: Upload gem artifact + uses: actions/upload-artifact@v4 + with: + name: smalruby3-gem-linux + path: ruby/smalruby3/smalruby3-*.gem + + build-windows: + name: "Build gem (Windows / Ruby ${{ inputs.ruby-version || '3.4' }})" + runs-on: windows-latest + defaults: + run: + working-directory: ruby/smalruby3 + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + + - name: Install SDL2 via MSYS2 + uses: msys2/setup-msys2@v2 + with: + msystem: UCRT64 + update: true + install: >- + mingw-w64-ucrt-x86_64-SDL2 + mingw-w64-ucrt-x86_64-SDL2_image + mingw-w64-ucrt-x86_64-SDL2_mixer + mingw-w64-ucrt-x86_64-SDL2_ttf + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ inputs.ruby-version || '3.4' }} + bundler-cache: true + working-directory: ruby/smalruby3 + + - name: Add MSYS2 to PATH + shell: bash + run: echo "C:/msys64/ucrt64/bin" >> "$GITHUB_PATH" + + - name: Build gem + run: gem build smalruby3.gemspec + + - name: Compile native extension + shell: bash + env: + CPATH: C:/msys64/ucrt64/include + LIBRARY_PATH: C:/msys64/ucrt64/lib + PKG_CONFIG_PATH: C:/msys64/ucrt64/lib/pkgconfig + run: bundle exec rake compile + + - name: Run tests + shell: bash + env: + CPATH: C:/msys64/ucrt64/include + LIBRARY_PATH: C:/msys64/ucrt64/lib + PKG_CONFIG_PATH: C:/msys64/ucrt64/lib/pkgconfig + run: bundle exec rake test + + - name: Verify smalruby3 loads + run: ruby -r smalruby3 -e "puts \"smalruby3 v#{Smalruby3::VERSION} loaded OK\"" + + - name: Upload gem artifact + uses: actions/upload-artifact@v4 + with: + name: smalruby3-gem-windows + path: ruby/smalruby3/smalruby3-*.gem diff --git a/.github/workflows/release-gem.yml b/.github/workflows/release-gem.yml new file mode 100644 index 00000000000..e40fa4c18ee --- /dev/null +++ b/.github/workflows/release-gem.yml @@ -0,0 +1,98 @@ +name: Release - smalruby3 gem + +on: + push: + tags: + - 'smalruby3-v*' + +permissions: + contents: write + id-token: write + +jobs: + test: + name: "[smalruby3] Test before release" + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['3.3', '3.4', '4.0'] + defaults: + run: + working-directory: ruby/smalruby3 + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + - name: Install SDL2 development libraries + run: | + sudo apt-get update + sudo apt-get install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + working-directory: ruby/smalruby3 + - name: Compile native extension + run: bundle exec rake compile + - name: Run lint + if: matrix.ruby == '4.0' + run: bundle exec standardrb + - name: Run unit tests + run: bundle exec rake test + + release: + name: "[smalruby3] Publish to RubyGems" + needs: test + runs-on: ubuntu-latest + environment: rubygems + defaults: + run: + working-directory: ruby/smalruby3 + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + + - name: Extract version from tag + id: version + run: | + VERSION="${GITHUB_REF_NAME#smalruby3-v}" + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "Releasing smalruby3 v${VERSION}" + + - name: Verify version matches + run: | + GEM_VERSION=$(ruby -r ./lib/smalruby3/version -e 'puts Smalruby3::VERSION') + TAG_VERSION="${{ steps.version.outputs.version }}" + if [ "$GEM_VERSION" != "$TAG_VERSION" ]; then + echo "::error::Version mismatch: gem=$GEM_VERSION tag=$TAG_VERSION" + exit 1 + fi + + - name: Install SDL2 development libraries + run: | + sudo apt-get update + sudo apt-get install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev + + - uses: ruby/setup-ruby@v1 + with: + ruby-version-file: ruby/smalruby3/.ruby-version + bundler-cache: true + working-directory: ruby/smalruby3 + + - name: Build gem + run: gem build smalruby3.gemspec + + - name: Push to RubyGems (Trusted Publishing) + uses: rubygems/release-gem@v1 + with: + working-directory: ruby/smalruby3 + + - name: Create GitHub Release + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "$GITHUB_REF_NAME" \ + --repo "$GITHUB_REPOSITORY" \ + --title "smalruby3 v${{ steps.version.outputs.version }}" \ + --generate-notes \ + smalruby3-${{ steps.version.outputs.version }}.gem diff --git a/ruby/smalruby3/LICENSE b/ruby/smalruby3/LICENSE new file mode 100644 index 00000000000..43a49a09401 --- /dev/null +++ b/ruby/smalruby3/LICENSE @@ -0,0 +1,49 @@ +MIT License + +Copyright (c) 2024-2026 Kouji Takao + +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. + +--- + +## Third-Party Notices + +This software depends on the following third-party libraries with their +respective licenses: + +### ruby-sdl2 (LGPL-3.0) + +Ruby bindings for SDL2. +https://github.com/ohai/ruby-sdl2 +Licensed under the GNU Lesser General Public License, Version 3 (LGPL-3.0). +Used as a gem dependency (dynamic linking). + +### resvg (MPL-2.0) + +An SVG rendering library used in the smalruby3_imageutil native extension. +https://github.com/nickel-rb/resvg +Licensed under the Mozilla Public License, Version 2.0 (MPL-2.0). +Compiled as a Rust crate dependency. + +### rsdl (Ruby's License) + +macOS SDL2 wrapper command. The smalruby3_launcher native extension is +derived from rsdl. +https://github.com/knu/rsdl +Licensed under Ruby's License (BSD-2-Clause compatible). diff --git a/ruby/smalruby3/README.md b/ruby/smalruby3/README.md new file mode 100644 index 00000000000..94f15d1132a --- /dev/null +++ b/ruby/smalruby3/README.md @@ -0,0 +1,47 @@ +# smalruby3 + +Scratch-compatible Ruby runtime for [Smalruby](https://smalruby.jp). + +A Ruby gem that provides a Scratch VM-compatible runtime, allowing Ruby scripts generated by [smalruby3-editor](https://github.com/smalruby/smalruby3-editor) to run natively on the desktop using SDL2. + +## Requirements + +- Ruby >= 3.3 +- SDL2 (system library) +- Rust toolchain (for building native extensions) + +## Installation + +```bash +gem install smalruby3 +``` + +## Usage + +```bash +smalruby3 your_script.rb +``` + +Or use directly in Ruby: + +```ruby +require "smalruby3" + +# Your Smalruby script here +``` + +## Development + +```bash +git clone https://github.com/smalruby/smalruby3-editor.git +cd smalruby3-editor/ruby/smalruby3 +bundle install +bundle exec rake test +``` + +## License + +This software is licensed under the [MIT License](LICENSE). + +See the [LICENSE](LICENSE) file for details, including third-party notices for +ruby-sdl2 (LGPL-3.0), resvg (MPL-2.0), and rsdl (Ruby's License). diff --git a/ruby/smalruby3/lib/smalruby3/version.rb b/ruby/smalruby3/lib/smalruby3/version.rb index 8b0e623997f..18492b8f733 100644 --- a/ruby/smalruby3/lib/smalruby3/version.rb +++ b/ruby/smalruby3/lib/smalruby3/version.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true module Smalruby3 - VERSION = "0.1.0" + # Versioning scheme: YY.MR.DDR + # YY = year (last 2 digits, e.g. 26 = 2026) + # MR = month * 10 + monthly release number (e.g. 31 = March, 1st release) + # DDR = day * 10 + daily release number (e.g. 291 = 29th, 1st release) + VERSION = "26.31.291" end diff --git a/ruby/smalruby3/smalruby3.gemspec b/ruby/smalruby3/smalruby3.gemspec index 1c2bd91fefc..315efc8031e 100644 --- a/ruby/smalruby3/smalruby3.gemspec +++ b/ruby/smalruby3/smalruby3.gemspec @@ -17,6 +17,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 3.3" spec.files = Dir["lib/**/*.rb", "lib/**/*.json", "ext/**/*.{rb,rs,toml,in,c.in}", "exe/*", "assets/**/*", "LICENSE", "README.md"] + .reject { |f| f.start_with?("ext/smalruby3_imageutil/target/") } spec.bindir = "exe" spec.executables = ["smalruby3"] spec.require_paths = ["lib"] @@ -27,4 +28,5 @@ Gem::Specification.new do |spec| spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/smalruby/smalruby3-editor/tree/develop/ruby/smalruby3" + spec.metadata["changelog_uri"] = "https://github.com/smalruby/smalruby3-editor/releases" end