diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 0000000..2369228 --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_PATH: "vendor/bundle" diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b31c9e1..f921410 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,13 +1,13 @@ version: 2 updates: - - package-ecosystem: "github-actions" - directory: "/" + - package-ecosystem: 'github-actions' + directory: '/' schedule: - interval: "daily" - - package-ecosystem: "bundler" - directory: "/" + interval: 'daily' + - package-ecosystem: 'bundler' + directory: '/' schedule: - interval: "weekly" + interval: 'weekly' versioning-strategy: increase groups: rubocop-dependencies: diff --git a/.github/workflows/actionlint.yml b/.github/workflows/actionlint.yml new file mode 100644 index 0000000..538fa8b --- /dev/null +++ b/.github/workflows/actionlint.yml @@ -0,0 +1,24 @@ +name: Lint GitHub Actions workflows +on: + push: + branches: + - main + paths: + - '.github/**' + pull_request: + paths: + - '.github/**' + workflow_dispatch: + +jobs: + actionlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Download actionlint + id: get_actionlint + run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) + shell: bash + - name: Check workflow files + run: ${{ steps.get_actionlint.outputs.executable }} -color + shell: bash diff --git a/.github/workflows/ci-nix.yml b/.github/workflows/ci-nix.yml new file mode 100644 index 0000000..e69de14 --- /dev/null +++ b/.github/workflows/ci-nix.yml @@ -0,0 +1,38 @@ +name: CI - Nix +on: + push: + branches: [main] + paths: + - '.github/workflows/ci-nix.yml' + - '*.nix' + - 'flake.lock' + - '.ruby-version' + - 'dprint.json' + pull_request: + paths: + - '.github/workflows/ci-nix.yml' + - '*.nix' + - 'flake.lock' + - '.ruby-version' + - 'dprint.json' + schedule: + # About JST 8:00 + - cron: '0 17 * * *' + workflow_dispatch: + +jobs: + tasks: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v3 + - uses: DeterminateSystems/nix-installer-action@v2 + - uses: DeterminateSystems/magic-nix-cache-action@v2 + - run: nix flake check + - run: nix develop --command ./bin/setup + - name: Log current versions + run: nix develop --command bundle exec rake inspect_dependencies + - name: Test with external depdendencies + run: nix develop --command bundle exec rake check_non_ruby + - name: Test with Ruby + run: nix develop --command bundle exec rake simulate_ci diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 65e37a6..88f3000 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -9,17 +9,17 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL" +name: 'CodeQL' on: push: - branches: [ "main" ] + branches: ['main'] paths-ignore: - '**.md' - '.vscode/**' pull_request: # The branches below must be a subset of the branches above - branches: [ "main" ] + branches: ['main'] paths-ignore: - '**.md' - '.vscode/**' @@ -38,45 +38,44 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'ruby' ] + language: ['ruby'] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Use only 'java' to analyze code written in Java, Kotlin or both # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. - # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: '/language:${{matrix.language}}' diff --git a/.github/workflows/dprint.yml b/.github/workflows/dprint.yml new file mode 100644 index 0000000..df80409 --- /dev/null +++ b/.github/workflows/dprint.yml @@ -0,0 +1,15 @@ +name: dprint +on: + push: + branches: [main] + pull_request: + +jobs: + check: + timeout-minutes: 15 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dprint/check@v2.2 + with: + dprint-version: '0.36.1' diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 15ac442..3a59ac6 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -32,3 +32,4 @@ jobs: name: Build and deploy YARD steps: - uses: kachick/deploy-yard-to-pages@v1 + id: deployment diff --git a/.github/workflows/test_behaviors.yml b/.github/workflows/test_behaviors.yml index 349fd77..23870ae 100644 --- a/.github/workflows/test_behaviors.yml +++ b/.github/workflows/test_behaviors.yml @@ -33,13 +33,13 @@ jobs: ruby: [head, '3.2', '3.1'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: ruby/setup-ruby@v1 - env: - BUNDLE_WITHOUT: development - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - run: bundle exec rake test_behaviors --suppress-backtrace='\/bundle' - env: - BUNDLE_WITHOUT: development + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + env: + BUNDLE_WITHOUT: development + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - run: bundle exec rake test_behaviors --suppress-backtrace='\/bundle' + env: + BUNDLE_WITHOUT: development diff --git a/.github/workflows/test_signatures.yml b/.github/workflows/test_signatures.yml index 4a91d5b..cdedc34 100644 --- a/.github/workflows/test_signatures.yml +++ b/.github/workflows/test_signatures.yml @@ -37,9 +37,9 @@ jobs: ruby: ['3.2'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - run: bundle exec rake validate_signatures >/dev/null + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - run: bundle exec rake validate_signatures >/dev/null diff --git a/.gitignore b/.gitignore index 9633e1b..8a0e794 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ *.gem *.rbc -.bundle +.bundle/* +!.bundle/config .config .DS_Store -.ruby-version coverage coverage.data InstalledFiles @@ -36,3 +36,6 @@ doc/ *.bak tool/ *\#* + +!flake.lock +.direnv diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..be94e6f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2.2 diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..2d911fa --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,12 @@ +{ + "recommendations": [ + "editorconfig.editorconfig", + "redhat.vscode-yaml", + "streetsidesoftware.code-spell-checker", + "koichisasada.vscode-rdbg", + "soutaro.steep-vscode", + "soutaro.rbs-syntax", + "dprint.dprint", + "jnoortheen.nix-ide" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bdac3f1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "editor.defaultFormatter": "dprint.dprint", + "editor.formatOnSave": true, + "[nix]": { + "editor.defaultFormatter": "jnoortheen.nix-ide" + }, + "cSpell.words": [ + "cachix", + "dprint", + "nixos", + "nixpkgs" + ] +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f045c3..f155ba4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,8 +1,8 @@ # How to contribute -* Reporting bugs -* Suggesting features -* Creating PRs +- Reporting bugs +- Suggesting features +- Creating PRs Welcome all of the contributions! @@ -17,7 +17,20 @@ $ ./bin/setup # Installed! ``` -## Feel the latest version with REPL +Using several tools, not limited to the Ruby ecosystem. +An example is [dprint](https://github.com/dprint/dprint). + +This project is providing nix flake config for setup around them. +After installing [Nix](https://nixos.org/) package manager, you can do following. + +```console +$ nix develop +$ dprint check +$ actionlint +... +``` + +## Try latest version with REPL ```console $ ./bin/console diff --git a/README.md b/README.md index 5a7b31e..15745bb 100644 --- a/README.md +++ b/README.md @@ -80,15 +80,15 @@ All products can be called as `pattern === other`. This signature will fit in most Ruby code. -* `case ~ when` syntax -* Enumerable#grep -* Enumerable#grep_v -* Enumerable#all? -* Enumerable#any? -* Enumerable#none? -* Enumerable#one? -* Enumerable#slice_after -* Enumerable#slice_before +- `case ~ when` syntax +- Enumerable#grep +- Enumerable#grep_v +- Enumerable#all? +- Enumerable#any? +- Enumerable#none? +- Enumerable#one? +- Enumerable#slice_after +- Enumerable#slice_before They can take this interface as the `pattern`. @@ -97,22 +97,22 @@ Reuse as you wish! ### Builders -* OR(*patterns) - Product returns `true` when matched even one pattern -* AND(*patterns) - Product returns `true` when matched all patterns -* NOT(pattern) - Product returns `true` when not matched the pattern -* CAN(*method_names) - Product returns `true` when it has all of the methods (checked with `respond_to?`) -* RESCUE(exception_class/module, pattern) - Product returns `true` when the pattern raises the exception -* QUIET(*patterns) - Product returns `true` when all patterns did not raise any exception -* EQ(object) - Product returns `true` when matched with `#==` -* SAME(object) - Product returns `true` when matched with `#equal?` -* SEND(name, pattern) - Basically provided for Enumerable -* BOOLEAN() - Product returns `true` when matched to `true` or `false` -* NIL() - Product returns `true` when matched to `nil` (Not consider `nil?`) -* ANYTHING() - Product returns `true`, always `true` -* NEVER() - Product returns `false`, always `false` -* XOR(pattern1, pattern2) - Product returns `true` when matched one of the pattern, when matched both returns `false` -* NAND(*patterns) - Product is an inverted `AND` -* NOR(*patterns) - Product is an inverted `OR` +- OR(*patterns) - Product returns `true` when matched even one pattern +- AND(*patterns) - Product returns `true` when matched all patterns +- NOT(pattern) - Product returns `true` when not matched the pattern +- CAN(*method_names) - Product returns `true` when it has all of the methods (checked with `respond_to?`) +- RESCUE(exception_class/module, pattern) - Product returns `true` when the pattern raises the exception +- QUIET(*patterns) - Product returns `true` when all patterns did not raise any exception +- EQ(object) - Product returns `true` when matched with `#==` +- SAME(object) - Product returns `true` when matched with `#equal?` +- SEND(name, pattern) - Basically provided for Enumerable +- BOOLEAN() - Product returns `true` when matched to `true` or `false` +- NIL() - Product returns `true` when matched to `nil` (Not consider `nil?`) +- ANYTHING() - Product returns `true`, always `true` +- NEVER() - Product returns `false`, always `false` +- XOR(pattern1, pattern2) - Product returns `true` when matched one of the pattern, when matched both returns `false` +- NAND(*patterns) - Product is an inverted `AND` +- NOR(*patterns) - Product is an inverted `OR` ### Best fit for RSpec's `satisfy` matcher too @@ -138,19 +138,19 @@ end When you felt annoy to write `Eqq` in many place, some ways exist. -* `Eqq.build(&block)` - In the block scope, all builder methods can be used without receiver -* `extend Eqq::Buildable` - In the class/module, all builders can be used as class methods -* `include Eqq::Buildable` - In the class/module, all builders can be used as instance methods +- `Eqq.build(&block)` - In the block scope, all builder methods can be used without receiver +- `extend Eqq::Buildable` - In the class/module, all builders can be used as class methods +- `include Eqq::Buildable` - In the class/module, all builders can be used as instance methods ### Signature -* This gem provides [ruby/rbs](https://github.com/ruby/rbs) signature file +- This gem provides [ruby/rbs](https://github.com/ruby/rbs) signature file ## Links -* [Repository](https://github.com/kachick/eqq) -* [API documents](https://kachick.github.io/eqq) +- [Repository](https://github.com/kachick/eqq) +- [API documents](https://kachick.github.io/eqq) ## NOTE -* ["eqq" is the implementation name of "#===" in CRuby](https://github.com/ruby/ruby/blob/2a685da1fcd928530509e99f5edb4117bc377994/range.c#L1859) +- ["eqq" is the implementation name of "#===" in CRuby](https://github.com/ruby/ruby/blob/2a685da1fcd928530509e99f5edb4117bc377994/range.c#L1859) diff --git a/Rakefile b/Rakefile index 9358d1c..442d753 100644 --- a/Rakefile +++ b/Rakefile @@ -62,3 +62,16 @@ task :view_packaging_files do end sh 'rm -rf ./pkg' end + +desc 'Print dependencies' +task :inspect_dependencies do + sh 'ruby --version' + sh 'dprint --version' + sh 'actionlint --version' +end + +desc 'Tests except ruby' +task :check_non_ruby do + sh 'dprint check' + sh 'actionlint' +end diff --git a/dprint.json b/dprint.json new file mode 100644 index 0000000..e1f724c --- /dev/null +++ b/dprint.json @@ -0,0 +1,15 @@ +{ + "json": {}, + "markdown": {}, + "prettier": { + "printWidth": 120, + "singleQuote": true + }, + "includes": ["**/*.{json,md,yml}"], + "excludes": ["vendor"], + "plugins": [ + "https://plugins.dprint.dev/json-0.17.4.wasm", + "https://plugins.dprint.dev/markdown-0.15.3.wasm", + "https://plugins.dprint.dev/prettier-0.26.1.json@fdbe31f6aecd24f9d6b924214710a6766050d03146163b4e241e6056b2462f2e" + ] +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a65e06b --- /dev/null +++ b/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1688482527, + "narHash": "sha256-9zd0YC2gfsRvVJENZsVs1R5LBj5/t127JlCLggn/970=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c7a18f89ef1dc423f57f3de9bd5d9355550a5d15", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-ruby": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688103575, + "narHash": "sha256-VkkUAm6U9sogXYFGhru0xIb0KI+mrVbk5PKjCD8rnV4=", + "owner": "bobvanderlinden", + "repo": "nixpkgs-ruby", + "rev": "e6ae16647947d0858a99e033ce695c33d6212852", + "type": "github" + }, + "original": { + "owner": "bobvanderlinden", + "repo": "nixpkgs-ruby", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "nixpkgs-ruby": "nixpkgs-ruby" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c023171 --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + nixpkgs-ruby.url = "github:bobvanderlinden/nixpkgs-ruby"; + nixpkgs-ruby.inputs.nixpkgs.follows = "nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, nixpkgs-ruby, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + ruby = nixpkgs-ruby.lib.packageFromRubyVersionFile { + file = ./.ruby-version; + inherit system; + }; + in + { + devShells.default = with pkgs; + mkShell { + buildInputs = [ + ruby + dprint + nil + nixpkgs-fmt + actionlint + ]; + }; + }); +}