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
6 changes: 3 additions & 3 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ if [ $? -ne 0 ]; then
fi

echo
echo "Starting rubocop"
bundle exec rubocop --format worst --format simple --format offenses
echo "Starting standard"
bundle exec standardrb
if [ $? -ne 0 ]; then
echo ""
echo ""
echo "Rubocop failed; push aborted!"
echo "Standard failed; push aborted!"
exit 1
fi

Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Publish Gem

on:
push:
tags:
- "v*"

permissions:
contents: write

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: true

- name: Build gem
run: |
set -euo pipefail
gemspec="$(ls *.gemspec | head -n 1)"
gem_name="${gemspec%.gemspec}"
version="${GITHUB_REF_NAME#v}"
gem_file="pkg/${gem_name}-${version}.gem"

echo "Building ${gem_name} ${version}..."
mkdir -p pkg
bundle exec gem build "$gemspec" --output "$gem_file"
test -f "$gem_file"

- name: Publish to RubyGems
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
set -euo pipefail

if [[ -z "${RUBYGEMS_API_KEY:-}" ]]; then
echo "::error::Missing RUBYGEMS_API_KEY secret."
exit 1
fi

gem_file="$(ls pkg/*.gem | head -n 1)"
echo "Publishing ${gem_file}..."

mkdir -p ~/.gem
printf -- "---\n:rubygems_api_key: %s\n" "$RUBYGEMS_API_KEY" > ~/.gem/credentials
chmod 0600 ~/.gem/credentials

gem push "$gem_file"

- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail

prerelease_flag=()
if [[ "$GITHUB_REF_NAME" == *-* ]]; then
prerelease_flag=(--prerelease)
fi

echo "Creating GitHub release ${GITHUB_REF_NAME}..."
gh release create "$GITHUB_REF_NAME" pkg/*.gem \
--verify-tag \
--title "$GITHUB_REF_NAME" \
--notes "Published to RubyGems." \
"${prerelease_flag[@]}"
27 changes: 0 additions & 27 deletions .github/workflows/release.yml

This file was deleted.

6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
ruby-version: ['3.3', '3.2', '3.1', '3.0', '2.7']
ruby-version: ['4.0', '3.4', '3.3']

steps:
- uses: actions/checkout@v4
Expand All @@ -22,7 +22,5 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
- name: Install dependencies
run: bundle install
- name: Rubocop
run: rubocop
- name: Run tests
- name: Lint and test
run: bundle exec rake
64 changes: 0 additions & 64 deletions .rubocop.yml

This file was deleted.

11 changes: 11 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Standard Ruby configuration
# https://github.com/testdouble/standard

ruby_version: 3.3

ignore:
- 'bin/**/*'
- 'vendor/**/*'
- 'tmp/**/*'

fix: true
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in slayer.gemspec
gemspec
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,41 @@ require 'slayer/compat/rspec_compat_040'

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests and lint checks. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
To install this gem onto your local machine, run `bundle exec rake install`.

To generate documentation run `yard`. To view undocumented files run `yard stats --list-undoc`.

## Releases

Releases are driven by git tags. The version lives in `lib/slayer/version.rb`, and the gemspec reads `Slayer::VERSION`.

```bash
bundle install
bin/release patch # or: minor, major
```

To publish an RC for a specific version:

```bash
bin/release rc 1.2.0
```

This sets the version to `1.2.0-rc` and tags it as `v1.2.0-rc`.

Prereleases can also use `bump`'s native `pre` increment:

```bash
bin/release pre
```

`pre` cycles prerelease labels in order: `alpha`, `beta`, `rc`, then the final version. For example, `1.2.0-rc` becomes `1.2.0`, tagged as `v1.2.0`.

`bin/release` uses `bump`, commits the version file, creates a `v<version>` tag, pushes the branch, and pushes the tag.

GitHub Actions publishes only when a `v*` tag is pushed. The publish workflow builds the gem, pushes it to RubyGems with `RUBYGEMS_API_KEY`, and creates a GitHub release with the built gem attached. Tags containing a prerelease suffix, such as `v1.2.0-rc`, are marked as prereleases on GitHub.

### Development w/ Docker

$ docker-compose up
Expand Down
12 changes: 9 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task default: :spec
begin
require "standard/rake"
rescue LoadError
# Standard not available
end

task default: [:standard, :spec]
84 changes: 84 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
set -euo pipefail

usage() {
echo "Usage: bin/release patch|minor|major|pre"
echo " bin/release rc X.Y.Z"
}

level="${1:-}"
target_version="${2:-}"
case "$level" in
patch|minor|major|pre)
if [[ $# -ne 1 ]]; then
usage
exit 1
fi
;;
rc)
if [[ $# -ne 2 || ! "$target_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
usage
exit 1
fi
;;
*)
usage
exit 1
;;
esac

if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Error: bin/release must be run inside a git repository."
exit 1
fi

branch="$(git symbolic-ref --quiet --short HEAD)" || {
echo "Error: releases must be run from a branch, not a detached HEAD."
exit 1
}

version_file="$(bundle exec bump file | awk '{print $NF}')"
current_version="$(bundle exec bump current --value-only)"
if [[ "$level" == "rc" ]]; then
next_version="${target_version}-rc"
else
next_version="$(bundle exec bump show-next "$level" --value-only)"
fi
tag="v${next_version}"

if [[ -z "$version_file" || -z "$current_version" || -z "$next_version" ]]; then
echo "Error: could not determine gem version information."
exit 1
fi

if ! git diff --quiet -- "$version_file" || ! git diff --cached --quiet -- "$version_file"; then
echo "Error: $version_file has uncommitted changes."
exit 1
fi

if git rev-parse "$tag" >/dev/null 2>&1; then
echo "Error: tag $tag already exists."
exit 1
fi

echo "Releasing ${tag} (${level})"
echo "Version: ${current_version} -> ${next_version}"
echo "Branch: ${branch}"

if [[ "$level" == "rc" ]]; then
bundle exec bump set "$next_version" --no-commit --no-bundle
else
bundle exec bump "$level" --no-commit --no-bundle
fi

git add "$version_file"
git commit -m "$tag"
git tag "$tag"

echo "Pushing ${branch}..."
git push origin "$branch"

echo "Pushing ${tag}..."
git push origin "$tag"

echo "Released ${tag}."
4 changes: 2 additions & 2 deletions lib/ext/string_ext.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class String
def underscore
word = dup
word.gsub!(/::/, '/')
word.gsub!("::", "/")
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
word.tr!('-', '_')
word.tr!("-", "_")
word.downcase!
word
end
Expand Down
14 changes: 7 additions & 7 deletions lib/slayer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'ext/string_ext' unless defined?(Rails)
require "ext/string_ext" unless defined?(Rails)

require 'slayer/version'
require 'slayer/errors'
require 'slayer/result'
require 'slayer/result_matcher'
require 'slayer/command'
require 'slayer/form'
require "slayer/version"
require "slayer/errors"
require "slayer/result"
require "slayer/result_matcher"
require "slayer/command"
require "slayer/form"
Loading
Loading