Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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:
Expand Down
14 changes: 12 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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}"
20 changes: 6 additions & 14 deletions exe/importmap-update
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) || []
Expand All @@ -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|
{
Expand All @@ -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({
Expand All @@ -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."
Expand All @@ -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

Expand Down