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
31 changes: 25 additions & 6 deletions .github/workflows/sync-starter-kits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Sync starter kits
# Regenerates each published starter kit from the current generator and opens a PR
# on the kit repo. Runs on a version tag (deliberate, versioned) or on demand.
#
# Every kit has two branches: main, and teams (the same kit generated with
# INERTIA_TEAMS=1). Each gets its own PR.
#
# Auth: a GitHub App (inertia-rails-generator-sync) installed on the three kit repos.
# Its installation token is short-lived AND its PRs trigger the kit's CI — unlike the
# default GITHUB_TOKEN, whose PRs do not. App id + private key live in this repo's
Expand Down Expand Up @@ -45,8 +48,11 @@ jobs:
fail-fast: false
matrix:
kit: ${{ fromJSON(needs.select.outputs.kits) }}
branch: [main, teams]
env:
SYNC_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || format('manual-{0}', github.run_id) }}
# main keeps the historical branch name; teams gets a suffix so both PRs can coexist
SYNC_BRANCH: generator-sync/${{ github.ref_type == 'tag' && github.ref_name || format('manual-{0}', github.run_id) }}${{ matrix.branch != 'main' && format('-{0}', matrix.branch) || '' }}
steps:
- name: Checkout generator
uses: actions/checkout@v4
Expand All @@ -65,6 +71,18 @@ jobs:
GH_TOKEN: ${{ steps.token.outputs.token }}
run: git clone "https://x-access-token:${GH_TOKEN}@github.com/inertia-rails/${{ matrix.kit }}-starter-kit.git" kit

# The first teams sync starts the branch from main.
- name: Check out the ${{ matrix.branch }} branch
if: matrix.branch != 'main'
working-directory: kit
run: |
if git ls-remote --exit-code --heads origin "${{ matrix.branch }}" >/dev/null; then
git checkout "${{ matrix.branch }}"
else
git checkout -b "${{ matrix.branch }}"
git push -u origin "${{ matrix.branch }}"
fi

# Generation and validation both run on the latest stable ruby ("ruby" in
# setup-ruby): rails new stamps .ruby-version and the Dockerfile's
# ARG RUBY_VERSION from the running ruby, so every sync moves the kit to the
Expand All @@ -88,6 +106,7 @@ jobs:
- name: Generate ${{ matrix.kit }} starter kit (rspec)
env:
INERTIA_TEST_FRAMEWORK: rspec
INERTIA_TEAMS: ${{ matrix.branch == 'teams' && '1' || '0' }}
run: bundle exec rake starter:${{ matrix.kit }}

- name: Apply generator output over the kit
Expand All @@ -102,7 +121,7 @@ jobs:
run: |
git config user.name "inertia-rails-generator-sync[bot]"
git config user.email "inertia-rails-generator-sync[bot]@users.noreply.github.com"
git checkout -b "generator-sync/${SYNC_VERSION}"
git checkout -b "${SYNC_BRANCH}"
git add -A
if git diff --cached --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -171,7 +190,7 @@ jobs:
working-directory: kit
env:
GH_TOKEN: ${{ steps.token.outputs.token }}
run: git push -u origin "generator-sync/${SYNC_VERSION}"
run: git push -u origin "${SYNC_BRANCH}"

- name: Open PR
if: steps.sync.outputs.changed == 'true' || steps.deps.outputs.changed == 'true'
Expand All @@ -185,16 +204,16 @@ jobs:
verdict="⚠️ **validation failed — opened as draft.** See the workflow run logs. Do not merge until green."
fi
body=$(cat <<EOF
Automated sync of \`${{ matrix.kit }}-starter-kit\` with generator \`${SYNC_VERSION}\`.
Automated sync of \`${{ matrix.kit }}-starter-kit\` (\`${{ matrix.branch }}\` branch) with generator \`${SYNC_VERSION}\`.

Up to two commits: **Sync with generator** — regenerated from [inertia-rails/generator](https://github.com/inertia-rails/generator) and applied over this repo (\`bin/sync_apply.sh\`; includes shadcn \`ui/*\` and \`db/\`) — and **Update dependencies** (\`bundle update --all\` + \`npm update\`, run in this repo's own context so lockfile platforms are preserved). The keep-list (README, deploy.yml, per-repo credentials, repo meta) is untouched.

Validation (runtime SSR is checked here because the kit's own CI cannot): $verdict
EOF
)
gh pr create \
--title "Sync with generator ${SYNC_VERSION}" \
--title "Sync with generator ${SYNC_VERSION}${{ matrix.branch != 'main' && format(' ({0})', matrix.branch) || '' }}" \
--body "$body" \
--base main \
--head "generator-sync/${SYNC_VERSION}" \
--base "${{ matrix.branch }}" \
--head "${SYNC_BRANCH}" \
$DRAFT
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- 5-day Dependabot cooldown on the JS ecosystem entry
- Starter kit rate-limits sign-in, sign-up, password reset, and password update (10 attempts per 3 minutes per IP)
- Stamp the compiled template with the commit SHA it was built from and print it at startup, so bug reports can name the build
- Opt-in teams for the starter kit (`INERTIA_TEAMS=1` or the prompt): personal and shared teams, owner/admin/member roles with Action Policy, email invitations, a team switcher, and team pages under `/:team_id`. The published kits carry it on a `teams` branch

### Fixed

Expand Down
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ to get you started.
### Starter Kit

The Starter Kit forces TypeScript, Tailwind, shadcn/ui, ESLint, and Typelizer
on, asks about SSR and browser system tests (default: yes for both), and adds
full authentication:
on, asks about SSR and browser system tests (default: yes for both), offers
teams (default: no), and adds full authentication:

```sh
INERTIA_FRAMEWORK=react INERTIA_STARTER_KIT=1 \
Expand All @@ -100,13 +100,40 @@ The Starter Kit includes:
- Controller and mailer test suites (Minitest or RSpec)
- Flake-free browser system tests with capybara-lockstep (optional)
- Alba + Typelizer for typed serializers (optional)
- Teams (optional, see below)

Pre-built starter kit apps are also available as standalone repos:

- [inertia-rails/react-starter-kit](https://github.com/inertia-rails/react-starter-kit)
- [inertia-rails/vue-starter-kit](https://github.com/inertia-rails/vue-starter-kit)
- [inertia-rails/svelte-starter-kit](https://github.com/inertia-rails/svelte-starter-kit)

Each repo has a `teams` branch with the teams variant.

#### Teams

Answer yes to the teams prompt, or set `INERTIA_TEAMS=1`:

```sh
INERTIA_FRAMEWORK=react INERTIA_STARTER_KIT=1 INERTIA_TEAMS=1 \
rails new myapp -m https://inertia-rails.dev
```

This adds:

- A personal team for every user, plus any number of shared teams
- Three roles, checked with [Action Policy](https://actionpolicy.evilmartians.io):
owner (everything), admin (rename, invite), member (view, leave)
- Email invitations: the email links to the sign in page, and the invitation
is accepted or declined from the dashboard; expired ones are deleted daily
- Deleting an account is refused while it owns a team other people belong to
- A team switcher, and team settings under Settings → Teams
- Team pages under `/:team_id/...`, so links and browser tabs keep pointing
at the same team; `/dashboard` redirects to the current team

To put a page of your own under a team, add its route to the
`scope ":team_id"` block and include `TeamScoped` in the controller.

## Features

Both setup paths share the following features:
Expand Down Expand Up @@ -194,6 +221,8 @@ bundle exec rake starter:svelte # tmp/svelte-starter-kit/
bundle exec rake starter:all # all three
```

Set `INERTIA_TEAMS=1` to generate the teams variant.

Run the detect + prompts phase without making changes (useful for debugging):

```sh
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ end
# the published kits (react/vue/svelte-starter-kit all use rspec).
STARTER_COMMON_ENV = {
"INERTIA_TEST_FRAMEWORK" => ENV.fetch("INERTIA_TEST_FRAMEWORK", "minitest"),
# INERTIA_TEAMS=1 generates the teams variant (the kits' `teams` branch)
"INERTIA_TEAMS" => ENV.fetch("INERTIA_TEAMS", "0"),
"INERTIA_ALBA" => "0",
"BUNDLE_IGNORE_MESSAGES" => "1"
}.freeze
Expand Down
11 changes: 10 additions & 1 deletion template/_alba.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
# and re-export from typelizer's serializers barrel instead.
types_index = "#{js_destination_path}/types/index.ts"
if use_starter_kit && File.exist?(types_index)
gsub_file types_index, /^export interface (Auth|User|Session|SharedProps) \{[^}]*\}\n\n?/m, ""
generated_types = %w[
Auth User Session SharedProps
Team TeamMember TeamInvitation TeamPermissions TeamInvitationContext PendingInvitation
SettingsSessionsIndex IdentityPasswordResetsEdit
DashboardShow SessionsNew UsersNew SettingsTeamsShow
]
gsub_file types_index, /^export interface (#{generated_types.join("|")}) \{[^}]*\}\n\n?/m, ""
gsub_file types_index, /^\/\/ Props of each page, .*\n\n?/, ""
# Enums come from the models (Enums.ts)
gsub_file types_index, /^export type MembershipRole = .*\n\n?/, "" if use_teams
append_with_blank_line.(types_index, "export * from \"./serializers\"\n")
end

Expand Down
10 changes: 10 additions & 0 deletions template/_prompts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@
use_system_tests = true
say " System tests: yes (default)"
end

# Teams: members, roles and invitations on top of the starter kit (opt-in)
if ENV.key?("INERTIA_TEAMS")
use_teams = ENV["INERTIA_TEAMS"] == "1"
say " Teams: #{use_teams ? 'yes' : 'no'} (from env)"
elsif interactive
use_teams = ask("Add teams (members, roles, invitations)?", :green,
limited_to: %w[y n], default: "n") == "y"
end
else
# Foundation: individual option prompts
use_typescript = prompt_bool.("INERTIA_TS", "TypeScript", "Use TypeScript?", detected: typescript_detected)
Expand Down Expand Up @@ -166,5 +175,6 @@
say " Test framework: #{test_framework}"
say " System tests: #{use_system_tests ? 'yes' : 'no'}"
say " Authentication: #{auth_strategy}"
say " Teams: #{use_teams ? 'yes' : 'no'}" if use_starter_kit
say "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", :cyan
say ""
5 changes: 4 additions & 1 deletion template/_shadcn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@

case framework
when "react"
# spinner and select are only available in the React shadcn registry
# spinner is only available in the React shadcn registry
shadcn_components.push("spinner", "select")
else
# the invite form picks a role
shadcn_components << "select" if use_teams
end

pm_exec = pm_install[package_manager][:exec]
Expand Down
29 changes: 28 additions & 1 deletion template/_starter_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
# Any version: the line is written by the inertia step and its constraint changes
inertia_gem_anchor = /^gem "inertia_rails".*\n/
if gemfile_body.match?(inertia_gem_anchor)
action_policy_gem = use_teams ?
"\n# Authorization framework for Ruby and Rails applications [https://actionpolicy.evilmartians.io]\ngem \"action_policy\"\n" : ""
insert_into_file "Gemfile",
"\n# An authentication system generator for Rails applications\n# we leave gem here to watch for security updates\ngem \"authentication-zero\"\n",
"\n# An authentication system generator for Rails applications\n# we leave gem here to watch for security updates\ngem \"authentication-zero\"\n#{action_policy_gem}",
after: inertia_gem_anchor
else
gems_to_add << "authentication-zero"
gems_to_add << "action_policy" if use_teams
end

web_console_anchor = " # Use console on exceptions pages [https://github.com/rails/web-console]\n gem \"web-console\"\n"
Expand All @@ -41,12 +44,32 @@
# ─── Models, Controllers, Mailers, Views, Routes ───────────────
<%= copy_dir("shared/starter_backend", force: true) %>

# ─── Teams: models, policy, controllers, mailer ────────────────
if use_teams
<%= copy_dir("shared/starter_teams", force: true) %>

# Delete expired invitations once a day (Solid Queue recurring task).
# `rails new` writes config/recurring.yml after the template has run
# (solid_queue:install), so edit it in after_bundle.
after_bundle do
recurring_anchor = "production:\n"
if File.exist?("config/recurring.yml") && File.read("config/recurring.yml").include?(recurring_anchor)
insert_into_file "config/recurring.yml",
" delete_expired_invitations:\n command: \"Invitation.expired.delete_all\"\n schedule: every day at 4am\n",
after: recurring_anchor
end
end
end

# ─── Migrations (fixed timestamps: output must be deterministic) ─
# A Time.now stamp made every generation differ, which forced the starter-kit
# sync to skip db/ entirely. New starter migrations get the next stamp in order.
timestamp = "20250801153827"
file "db/migrate/#{timestamp}_create_users.rb", <%= code("shared/starter/migrations/create_users.rb") %>
file "db/migrate/#{timestamp.to_i + 1}_create_sessions.rb", <%= code("shared/starter/migrations/create_sessions.rb") %>
if use_teams
file "db/migrate/#{timestamp.to_i + 2}_create_teams.rb", <%= code("shared/starter/migrations/create_teams.rb") %>
end

# ─── Preview emails in the browser in development (letter_opener) ─
dev_env = "config/environments/development.rb"
Expand Down Expand Up @@ -112,6 +135,10 @@
# ─── Alba Serializers (if enabled) ──────────────────────────────
if use_alba
<%= copy_dir("shared/starter_alba", force: true) %>

if use_teams
<%= copy_dir("shared/starter_teams_alba", force: true) %>
end
end

say " Starter Kit backend configured ✓", :green
Expand Down
14 changes: 14 additions & 0 deletions template/_starter_frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,28 @@
file "#{js_destination_path}/lib/browser.ts", <%= code("shared/starter_lib/browser.ts") %>, force: true
file "#{js_destination_path}/lib/storage.ts", <%= code("shared/starter_lib/storage.ts") %>, force: true

file "#{js_destination_path}/lib/dashboard-route.ts", <%= code("shared/starter_lib/dashboard-route.ts") %>, force: true if use_teams

# ─── Framework-specific files (auto-generated from directory tree) ─
case framework
when "react"
<%= copy_dir("react/starter", "js_destination_path", force: true) %>

if use_teams
<%= copy_dir("react/starter_teams", "js_destination_path", force: true) %>
end
when "vue"
<%= copy_dir("vue/starter", "js_destination_path", force: true) %>

if use_teams
<%= copy_dir("vue/starter_teams", "js_destination_path", force: true) %>
end
when "svelte"
<%= copy_dir("svelte/starter", "js_destination_path", force: true) %>

if use_teams
<%= copy_dir("svelte/starter_teams", "js_destination_path", force: true) %>
end
end

# ─── Dark-mode guard: set the theme class inline before assets load (avoids FOUC) ─
Expand Down
2 changes: 2 additions & 0 deletions template/_system_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
if use_starter_kit
if test_framework == "rspec"
file "spec/system/sessions_spec.rb", <%= code("shared/starter_system/sessions_spec.rb") %>
file "spec/system/teams_spec.rb", <%= code("shared/starter_system/teams_spec.rb") %> if use_teams
else
file "test/system/sessions_test.rb", <%= code("shared/starter_system/sessions_test.rb") %>
file "test/system/teams_test.rb", <%= code("shared/starter_system/teams_test.rb") %> if use_teams
end
end

Expand Down
8 changes: 8 additions & 0 deletions template/_test_framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
if test_framework == "minitest"
<%= copy_dir("shared/starter_test_minitest", force: true) %>

if use_teams
<%= copy_dir("shared/starter_teams_test_minitest", force: true) %>
end

# Add session helper require to test_helper.rb
if File.exist?("test/test_helper.rb")
insert_into_file "test/test_helper.rb",
Expand All @@ -41,6 +45,10 @@
file ".rspec", "--require spec_helper\n", force: true
<%= copy_dir("shared/starter_test_rspec", force: true) %>

if use_teams
<%= copy_dir("shared/starter_teams_test_rspec", force: true) %>
end

# Remove Rails-scaffolded minitest structure
%w[
test/application_system_test_case.rb
Expand Down
1 change: 1 addition & 0 deletions template/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use_typelizer = false
use_alba = false
use_system_tests = false
use_teams = false
test_framework = "minitest"
auth_strategy = "none"
vite_gem = "rails_vite"
Expand Down
Loading
Loading