Skip to content

Commit c99fd90

Browse files
committed
Install action's own gems via ruby/setup-ruby before running
The exe needs octokit, which isn't in the consumer's Gemfile. A second ruby/setup-ruby step pointed at the action's own Gemfile handles the install and caches it keyed on Gemfile.lock. BUNDLE_GEMFILE in the run step ensures bundle exec picks up the action's gems rather than the consumer's.
1 parent 74caeb8 commit c99fd90

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

action.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,28 @@ inputs:
4040
runs:
4141
using: "composite"
4242
steps:
43-
- name: Set up Ruby
43+
- name: Set up Ruby (consumer)
4444
uses: ruby/setup-ruby@v1
4545
with:
4646
bundler-cache: true
4747
ruby-version: ${{ inputs.ruby-version }}
4848

49+
- name: Set up Ruby (action)
50+
uses: ruby/setup-ruby@v1
51+
with:
52+
bundler-cache: true
53+
working-directory: ${{ github.action_path }}
54+
4955
- name: Run importmap-update
5056
shell: bash
5157
working-directory: ${{ inputs.working-directory }}
5258
env:
59+
BUNDLE_GEMFILE: ${{ github.action_path }}/Gemfile
5360
GITHUB_TOKEN: ${{ inputs.github-token }}
5461
GITHUB_REPOSITORY: ${{ github.repository }}
5562
INPUT_CONFIG_FILE: ${{ inputs.config-file }}
5663
IMPORTMAP_BASE_BRANCH: ${{ inputs.base-branch }}
5764
IMPORTMAP_DRY_RUN: ${{ inputs.dry-run }}
5865
IMPORTMAP_AUTHOR_NAME: ${{ inputs.author-name }}
5966
IMPORTMAP_AUTHOR_EMAIL: ${{ inputs.author-email }}
60-
run: ${{ github.action_path }}/exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"
67+
run: bundle exec ${{ github.action_path }}/exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"

exe/importmap-update

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ when :run
162162
exit 2
163163
end
164164

165-
runner = Importmap::Update::Commands::ShellRunner.new
165+
# Unset BUNDLE_GEMFILE for all child processes (bin/importmap, git, …).
166+
# The action is invoked with BUNDLE_GEMFILE pointing at its own Gemfile so
167+
# that `bundle exec` loads octokit; if that leaks into bin/importmap the
168+
# Rails app's boot.rb will try to use the action's Gemfile instead of its
169+
# own, which doesn't have Rails.
170+
runner = Importmap::Update::Commands::ShellRunner.new(env: {"BUNDLE_GEMFILE" => nil})
166171
gh = Importmap::Update::GitHubClient.new(repo: repo, token: token)
167172
git = Importmap::Update::GitClient.new(
168173
runner: runner,

0 commit comments

Comments
 (0)