From 894fc9d14caf165ccc15b7251c90d89d1b57c3cd Mon Sep 17 00:00:00 2001 From: Ryan Melton Date: Thu, 1 Oct 2026 17:05:44 -0600 Subject: [PATCH] feat(plugin-unit-tests): add a gemfile input for the Ruby specs Some plugins keep their test gems in a separate Gemfile so the deployed plugin doesn't try to install them; openc3-cosmos-cfdp's Rails microservice uses Gemfile.dev for this. With only the plugin's own Gemfile, bundle exec rspec fails because rspec is not in the bundle. The new gemfile input (default Gemfile) selects the Gemfile through BUNDLE_GEMFILE for setup-ruby's cache, bundle install and the spec run. A gemfile that was asked for but doesn't exist is an error. The default behaves exactly as before. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../workflows/plugin-unit-tests-reusable.yml | 23 ++++++++++++++++--- workflow-templates/plugin-unit-tests.yml | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/plugin-unit-tests-reusable.yml b/.github/workflows/plugin-unit-tests-reusable.yml index 72d83c9..8860069 100644 --- a/.github/workflows/plugin-unit-tests-reusable.yml +++ b/.github/workflows/plugin-unit-tests-reusable.yml @@ -38,6 +38,11 @@ on: required: false type: boolean default: false + gemfile: + description: 'Gemfile for the Ruby specs, relative to plugin_directory (e.g. a Gemfile.dev that adds the test gems)' + required: false + type: string + default: 'Gemfile' permissions: contents: read @@ -188,14 +193,26 @@ jobs: working-directory: ${{ inputs.plugin_directory }} # Caching bundler needs a lockfile to key on, and most plugins have no # Gemfile at all, in which case the gems are installed directly below - bundler-cache: ${{ hashFiles(format('{0}/Gemfile.lock', inputs.plugin_directory)) != '' }} + bundler-cache: ${{ hashFiles(format('{0}/{1}.lock', inputs.plugin_directory, inputs.gemfile)) != '' }} + env: + # Only set for a non-default gemfile, so the default keeps setup-ruby's own lookup + BUNDLE_GEMFILE: ${{ inputs.gemfile != 'Gemfile' && format('{0}/{1}/{2}', github.workspace, inputs.plugin_directory, inputs.gemfile) || '' }} - name: Install dependencies working-directory: ${{ inputs.plugin_directory }} + env: + GEMFILE: ${{ inputs.gemfile }} run: | set -euo pipefail - if [ -f Gemfile ]; then + if [ -f "$GEMFILE" ]; then + # Exported for the spec run too, and for a Rails app's config/boot.rb + export BUNDLE_GEMFILE="$PWD/$GEMFILE" + echo "BUNDLE_GEMFILE=$BUNDLE_GEMFILE" >> "$GITHUB_ENV" bundle install --jobs 4 --retry 3 + elif [ "$GEMFILE" != "Gemfile" ]; then + # A gemfile that was asked for but is missing is a mistake, not a plugin without a Gemfile + echo "::error::gemfile '$GEMFILE' does not exist in ${{ inputs.plugin_directory }}" + exit 1 else gem install --no-document rspec openc3 fi @@ -206,7 +223,7 @@ jobs: SPEC_DIR: ${{ needs.detect.outputs.ruby-dir }} run: | set -euo pipefail - if [ -f Gemfile ]; then + if [ -n "${BUNDLE_GEMFILE:-}" ]; then bundle exec rspec "$SPEC_DIR" --format documentation else rspec "$SPEC_DIR" --format documentation diff --git a/workflow-templates/plugin-unit-tests.yml b/workflow-templates/plugin-unit-tests.yml index a395e22..9b2159e 100644 --- a/workflow-templates/plugin-unit-tests.yml +++ b/workflow-templates/plugin-unit-tests.yml @@ -34,3 +34,4 @@ jobs: # python_version: '3.12' # Uncomment and update if needed # ruby_version: '3.4' # Uncomment and update if needed # require_tests: true # Uncomment to fail the build when the plugin has no tests + # gemfile: Gemfile.dev # Uncomment if the specs need a different Gemfile than the plugin's own