Skip to content

Commit d8420a0

Browse files
committed
Run action in its own Ruby environment
This action has its own Ruby dependencies that may or may not be included in the consumer Gemfile. To avoid colliding dependencies, we should run within the same Ruby setup as the consumer application, but run our own `bundle install`, running anything that redirects to the consumer application using `Bundler.with_unbundled_env` to opt out of our Gemfile.
1 parent 993922e commit d8420a0

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

.github/workflows/integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
github-token: ${{ secrets.GITHUB_TOKEN }}
5656
dry-run: "true"
57-
working-directory: /tmp/test-app
57+
rails-root: /tmp/test-app
5858

5959
- name: Assert all outdated packages appear in dry-run output
6060
run: |

action.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,27 @@ inputs:
3232
description: "Git author email for commits."
3333
required: false
3434
default: "github-actions[bot]@users.noreply.github.com"
35-
working-directory:
35+
rails-root:
3636
description: "Directory containing the Rails app to run against. Useful when the app lives in a subdirectory or for integration testing."
3737
required: false
3838
default: "."
3939

4040
runs:
4141
using: "composite"
4242
steps:
43-
- name: Set up Ruby
44-
uses: ruby/setup-ruby@v1
45-
with:
46-
bundler-cache: true
47-
ruby-version: ${{ inputs.ruby-version }}
48-
4943
- name: Run importmap-update
5044
shell: bash
51-
working-directory: ${{ inputs.working-directory }}
45+
working-directory: ${{ github.action_path }}
5246
env:
47+
BUNDLE_GEMFILE: ${{ github.action_path }}/Gemfile
48+
RAILS_ROOT: ${{ inputs.rails-root }}
5349
GITHUB_TOKEN: ${{ inputs.github-token }}
5450
GITHUB_REPOSITORY: ${{ github.repository }}
5551
INPUT_CONFIG_FILE: ${{ inputs.config-file }}
5652
IMPORTMAP_BASE_BRANCH: ${{ inputs.base-branch }}
5753
IMPORTMAP_DRY_RUN: ${{ inputs.dry-run }}
5854
IMPORTMAP_AUTHOR_NAME: ${{ inputs.author-name }}
5955
IMPORTMAP_AUTHOR_EMAIL: ${{ inputs.author-email }}
60-
run: ${{ github.action_path }}/exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"
56+
run: |
57+
bundle install
58+
bundle exec exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"

exe/importmap-update

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

165-
runner = Importmap::Update::Commands::ShellRunner.new
165+
runner = Importmap::Update::Commands::ShellRunner.new(cwd: ENV.fetch("RAILS_ROOT", "."))
166166
gh = Importmap::Update::GitHubClient.new(repo: repo, token: token)
167167
git = Importmap::Update::GitClient.new(
168168
runner: runner,

lib/commands.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ def initialize(cwd: nil, env: nil)
4747
def run(*argv)
4848
opts = {}
4949
opts[:chdir] = @cwd if @cwd
50-
stdout, stderr, status = Open3.capture3(@env, *argv, **opts)
51-
Result.new(stdout: stdout, stderr: stderr, exit_code: status.exitstatus)
50+
Bundler.with_unbundled_env do
51+
stdout, stderr, status = Open3.capture3(@env, *argv, opts)
52+
Result.new(stdout: stdout, stderr: stderr, exit_code: status.exitstatus)
53+
end
5254
end
5355

5456
# Raises on non-zero exit. Use when you have no recovery strategy

0 commit comments

Comments
 (0)