Skip to content

Commit b7447d2

Browse files
committed
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.
1 parent 36b3ee5 commit b7447d2

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

.github/workflows/integration.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ jobs:
1717
- uses: actions/checkout@v6
1818

1919
- uses: ruby/setup-ruby@v1
20-
with:
21-
bundler-cache: true
22-
2320
- name: Create test Rails app
2421
run: |
2522
gem install rails --no-document

action.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ inputs:
4040
runs:
4141
using: "composite"
4242
steps:
43+
- name: Save importmap outputs
44+
shell: bash
45+
working-directory: ${{ inputs.rails-root }}
46+
run: |
47+
bundle install
48+
bundle exec importmap audit 2>&1 | tee /tmp/importmap-audit.txt
49+
bundle exec importmap outdated 2>&1 | tee /tmp/importmap-outdated.txt
50+
4351
- name: Run importmap-update
4452
shell: bash
4553
working-directory: ${{ github.action_path }}
@@ -55,4 +63,7 @@ runs:
5563
IMPORTMAP_AUTHOR_EMAIL: ${{ inputs.author-email }}
5664
run: |
5765
bundle install
58-
bundle exec exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"
66+
bundle exec exe/importmap-update \
67+
--outdated-file /tmp/importmap-outdated.txt \
68+
--audit-file /tmp/importmap-audit.txt \
69+
2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"

exe/importmap-update

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def require_files!(opts, *keys)
7979
exit 2
8080
end
8181

82-
def build_plan_from_files(opts, config)
82+
def build_plan(opts, config)
8383
outdated_output = File.read(opts[:outdated_file])
8484
audit_output = File.read(opts[:audit_file])
8585
outdated = Importmap::Update::Parsers::OutdatedParser.parse(outdated_output)
@@ -89,16 +89,6 @@ def build_plan_from_files(opts, config)
8989
).call
9090
end
9191

92-
def build_plan_from_live(config, runner)
93-
outdated_result = runner.run("bin/importmap", "outdated")
94-
audit_result = runner.run("bin/importmap", "audit")
95-
outdated = Importmap::Update::Parsers::OutdatedParser.parse(outdated_result.stdout)
96-
vulnerabilities = Importmap::Update::Parsers::AuditParser.parse(audit_result.stdout)
97-
Importmap::Update::Planner.new(
98-
outdated: outdated, vulnerabilities: vulnerabilities, config: config
99-
).call
100-
end
101-
10292
def load_existing_prs_from_file(path)
10393
return [] if path.nil? || !File.exist?(path)
10494
raw = YAML.safe_load_file(path, permitted_classes: [], aliases: false) || []
@@ -117,7 +107,7 @@ when :print_config
117107

118108
when :print_plan
119109
require_files!(options, :outdated_file, :audit_file)
120-
plan = build_plan_from_files(options, config)
110+
plan = build_plan(options, config)
121111
puts({
122112
"pr_specs" => plan.pr_specs.map { |s|
123113
{
@@ -134,7 +124,7 @@ when :print_plan
134124

135125
when :print_actions
136126
require_files!(options, :outdated_file, :audit_file)
137-
plan = build_plan_from_files(options, config)
127+
plan = build_plan(options, config)
138128
existing_prs = load_existing_prs_from_file(options[:existing_prs_file])
139129
result = Importmap::Update::Reconciler.new(plan: plan, existing_prs: existing_prs).call
140130
puts({
@@ -151,6 +141,8 @@ when :print_actions
151141
}.to_yaml)
152142

153143
when :run
144+
require_files!(options, :outdated_file, :audit_file)
145+
154146
repo = ENV["GITHUB_REPOSITORY"]
155147
if repo.nil? || repo.empty?
156148
warn "GITHUB_REPOSITORY is not set; refusing to run."
@@ -172,7 +164,7 @@ when :run
172164
author_email: ENV.fetch("IMPORTMAP_AUTHOR_EMAIL", "github-actions[bot]@users.noreply.github.com")
173165
)
174166

175-
plan = build_plan_from_live(config, runner)
167+
plan = build_plan(options, config)
176168
existing_prs = gh.list_open_prs(branch_prefix: config.branch_prefix)
177169
reconciled = Importmap::Update::Reconciler.new(plan: plan, existing_prs: existing_prs).call
178170

0 commit comments

Comments
 (0)