From d0860d7fc97bbd7d926da4197906dcd95a1b3fca Mon Sep 17 00:00:00 2001 From: Neil Carvalho Date: Mon, 25 May 2026 11:43:29 -0300 Subject: [PATCH] Read audit/outdated output from files in the run mode This action has two separate ways of reading the importmap output: from a file, mostly for testing, and from running `importmap` directly. This commit simplifies that by adding a first step that saves the importmap outputs in textfiles, so it can be read in the following step. That removes the need for having two separate ways, so the code is now combined. --- .github/workflows/integration.yml | 10 ++++++---- action.yml | 14 ++++++++++++-- exe/importmap-update | 20 ++++++-------------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 05935bd..b409c9b 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -17,9 +17,6 @@ jobs: - uses: actions/checkout@v6 - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - - name: Create test Rails app run: | gem install rails --no-document @@ -43,7 +40,9 @@ jobs: - name: Pin outdated packages run: | - cat >> /tmp/test-app/config/importmap.rb << 'EOF' + cd /tmp/test-app + + cat >> config/importmap.rb << 'EOF' pin "is-svg", to: "https://cdn.jsdelivr.net/npm/is-svg@3.0.0/index.js" pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.2.0/dist/md5.min.js" @@ -53,6 +52,9 @@ jobs: pin "just-extend", to: "https://cdn.jsdelivr.net/npm/just-extend@5.1.1/index.mjs" EOF + git add . + git commit -m "Pin outdated packages" + - name: Run in dry-run mode uses: ./ env: diff --git a/action.yml b/action.yml index 7c9498a..833a65a 100644 --- a/action.yml +++ b/action.yml @@ -35,11 +35,18 @@ inputs: rails-root: description: "Directory containing the Rails app to run against. Useful when the app lives in a subdirectory or for integration testing." required: false - default: "." + default: "${{ github.workspace }}" runs: using: "composite" steps: + - name: Save importmap outputs + shell: bash + working-directory: ${{ inputs.rails-root }} + run: | + bin/importmap audit 2>&1 | tee /tmp/importmap-audit.txt || true + bin/importmap outdated 2>&1 | tee /tmp/importmap-outdated.txt || true + - name: Run importmap-update shell: bash working-directory: ${{ github.action_path }} @@ -55,4 +62,7 @@ runs: IMPORTMAP_AUTHOR_EMAIL: ${{ inputs.author-email }} run: | bundle install - bundle exec exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}" + bundle exec exe/importmap-update \ + --outdated-file /tmp/importmap-outdated.txt \ + --audit-file /tmp/importmap-audit.txt \ + 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}" diff --git a/exe/importmap-update b/exe/importmap-update index 6a2d151..5e434db 100755 --- a/exe/importmap-update +++ b/exe/importmap-update @@ -79,7 +79,7 @@ def require_files!(opts, *keys) exit 2 end -def build_plan_from_files(opts, config) +def build_plan(opts, config) outdated_output = File.read(opts[:outdated_file]) audit_output = File.read(opts[:audit_file]) outdated = Importmap::Update::Parsers::OutdatedParser.parse(outdated_output) @@ -89,16 +89,6 @@ def build_plan_from_files(opts, config) ).call end -def build_plan_from_live(config, runner) - outdated_result = runner.run("bin/importmap", "outdated") - audit_result = runner.run("bin/importmap", "audit") - outdated = Importmap::Update::Parsers::OutdatedParser.parse(outdated_result.stdout) - vulnerabilities = Importmap::Update::Parsers::AuditParser.parse(audit_result.stdout) - Importmap::Update::Planner.new( - outdated: outdated, vulnerabilities: vulnerabilities, config: config - ).call -end - def load_existing_prs_from_file(path) return [] if path.nil? || !File.exist?(path) raw = YAML.safe_load_file(path, permitted_classes: [], aliases: false) || [] @@ -117,7 +107,7 @@ when :print_config when :print_plan require_files!(options, :outdated_file, :audit_file) - plan = build_plan_from_files(options, config) + plan = build_plan(options, config) puts({ "pr_specs" => plan.pr_specs.map { |s| { @@ -134,7 +124,7 @@ when :print_plan when :print_actions require_files!(options, :outdated_file, :audit_file) - plan = build_plan_from_files(options, config) + plan = build_plan(options, config) existing_prs = load_existing_prs_from_file(options[:existing_prs_file]) result = Importmap::Update::Reconciler.new(plan: plan, existing_prs: existing_prs).call puts({ @@ -151,6 +141,8 @@ when :print_actions }.to_yaml) when :run + require_files!(options, :outdated_file, :audit_file) + repo = ENV["GITHUB_REPOSITORY"] if repo.nil? || repo.empty? warn "GITHUB_REPOSITORY is not set; refusing to run." @@ -172,7 +164,7 @@ when :run author_email: ENV.fetch("IMPORTMAP_AUTHOR_EMAIL", "github-actions[bot]@users.noreply.github.com") ) - plan = build_plan_from_live(config, runner) + plan = build_plan(options, config) existing_prs = gh.list_open_prs(branch_prefix: config.branch_prefix) reconciled = Importmap::Update::Reconciler.new(plan: plan, existing_prs: existing_prs).call