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
26 changes: 15 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
name: Spec CI
name: Test & Lint

on: [push, pull_request]
on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
name: Ruby ${{ matrix.ruby }} / ${{ matrix.appraisal }}
strategy:
fail-fast: false
matrix:
ruby: [3.2, 3.3, 3.4]
ruby: ["3.2", "3.3", "3.4"]
appraisal: [rails_7.0, rails_7.1, rails_7.2, rails_8.0]
env:
RUBY_VERSION: ${{ matrix.ruby }}
BUNDLE_GEMFILE: gemfiles/${{ matrix.appraisal }}.gemfile
steps:
- uses: actions/checkout@v6
- name: Set up Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Install dependencies
run: |
bundle exec appraisal install
- name: Run rspec
run: |
bundle exec appraisal "rake dummy:db:create dummy:db:migrate && rspec"
- name: Lint
if: matrix.ruby == '3.4' && matrix.appraisal == 'rails_8.0'
run: bundle exec standardrb
- name: Run tests
run: bundle exec rake spec
76 changes: 57 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,74 @@
name: Publish Gem

on:
release:
types: [published]
push:
tags:
- "v*"

permissions:
contents: write

jobs:
build:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
- name: Checkout
uses: actions/checkout@v6

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
ruby-version: "3.4"
bundler-cache: true
- name: Release Gem
if: contains(github.ref, 'refs/tags/v')

- 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}}
TAG: ${{ github.event.release.tag_name }}
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
echo "Setting up gem credentials..."
mkdir -p ~/.gem
set -euo pipefail

cat << EOF > ~/.gem/credentials
---
:rubygems_api_key: ${RUBYGEMS_API_KEY}
EOF
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

bundle exec rake build
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 "Running gem release task..."
gem push pkg/phi_attrs-${TAG#v}.gem
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[@]}"
97 changes: 0 additions & 97 deletions .rubocop.yml

This file was deleted.

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

ruby_version: 3.2

ignore:
- "bin/**/*"
- "gemfiles/**/*"
- "spec/dummy/db/schema.rb"
- "vendor/**/*"
- "tmp/**/*"
- "coverage/**/*"

fix: true
31 changes: 26 additions & 5 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
# frozen_string_literal: true

appraise 'rails_7.0' do
gem 'rails', '~> 7.0'
gem 'rspec', '~> 3.12'
gem 'rspec-rails', '~> 7.0'
gem 'sqlite3', '~> 1.5'
appraise "rails_7.0" do
gem "rails", "~> 7.0.0"
gem "rspec", "~> 3.13"
gem "rspec-rails", "~> 7.0"
gem "sqlite3", "~> 1.7"
end

appraise "rails_7.1" do
gem "rails", "~> 7.1.0"
gem "rspec", "~> 3.13"
gem "rspec-rails", "~> 7.0"
gem "sqlite3", "~> 1.7"
end

appraise "rails_7.2" do
gem "rails", "~> 7.2.0"
gem "rspec", "~> 3.13"
gem "rspec-rails", "~> 7.0"
gem "sqlite3", "~> 2.0"
end

appraise "rails_8.0" do
gem "rails", "~> 8.0.0"
gem "rspec", "~> 3.13"
gem "rspec-rails", "~> 8.0"
gem "sqlite3", "~> 2.0"
end
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

Expand Down
49 changes: 39 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,20 @@ It is recommended to use the provided `docker-compose` environment for developme

### Tests

Tests are written using [RSpec](https://rspec.info/) and are setup to use [Appraisal](https://github.com/thoughtbot/appraisal) to run tests over multiple rails versions.
Tests are written using [RSpec](https://rspec.info/) and are setup to use [Appraisal](https://github.com/thoughtbot/appraisal) to run tests over multiple Rails versions. Supported runtimes are Ruby 3.2+ and Rails 7.0 through 8.0.

$ bin/run_tests
or for individual tests:
$ bin/ssh_to_container
$ bundle exec appraisal rspec spec/path/to/spec.rb

To run just a particular rails version:
$ bundle exec appraisal rails_7.0 rspec
To run just a particular Rails version:

$ bundle exec appraisal rails_7.0 rspec

Linting uses [standardrb](https://github.com/standardrb/standard):

$ bundle exec standardrb

### Console

Expand All @@ -462,13 +467,38 @@ An interactive prompt that will allow you to experiment with the gem.

### Local Install

Run `bin/setup` to install dependencies. Then, run `bundle exec appraisal rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run linting and tests. 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`.

### Versioning
### Releases

Releases are driven by git tags. The version lives in `lib/phi_attrs/version.rb`, and the gemspec reads `PhiAttrs::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.

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).
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.


## Contributing
Expand All @@ -479,10 +509,9 @@ Any PRs should be accompanied with documentation in `README.md`.

### Releasing

* Squash and merge your PR, including a bump to `lib/phi_attrs/version.rb`
* Draft a new release, creating a new tag with the new version number from `version.rb`, i.e. `v0.3.2`
* Auto-generate release notes, add any context if necessary
* Publish release; release will be automatically built and published to rubygems
* Squash and merge your PR.
* Run `bin/release patch`, `bin/release minor`, `bin/release major`, or `bin/release rc X.Y.Z`.
* The pushed `v*` tag will be automatically built and published to RubyGems.

## License

Expand Down
19 changes: 13 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# frozen_string_literal: true

require 'rubygems'
require 'bundler/setup'
require 'bundler/gem_tasks'

require 'rake'
require "rubygems"
require "bundler/setup"
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rake"

namespace :dummy do
require_relative 'spec/dummy/application'
require_relative "spec/dummy/application"
Dummy::Application.load_tasks
end

RSpec::Core::RakeTask.new(:spec)
Rake::Task[:spec].enhance(["dummy:db:create", "dummy:db:migrate"])

require "standard/rake"

task default: [:standard, :spec]
Loading