Skip to content

Commit 501ac13

Browse files
committed
Simplify options with environment variables
1 parent e2f7c12 commit 501ac13

3 files changed

Lines changed: 15 additions & 26 deletions

File tree

.github/workflows/integration.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Create test Rails app
2121
run: |
2222
gem install rails --no-document
23-
rails new /tmp/test-app \
23+
rails new $RUNNER_TEMP/test-app \
2424
--skip-git \
2525
--skip-action-mailer \
2626
--skip-action-mailbox \
@@ -31,7 +31,7 @@ jobs:
3131
--skip-bootsnap \
3232
--skip-test \
3333
--quiet
34-
cd /tmp/test-app
34+
cd $RUNNER_TEMP/test-app
3535
git init
3636
git add .
3737
git config user.email "test@example.com"
@@ -40,7 +40,7 @@ jobs:
4040
4141
- name: Pin outdated packages
4242
run: |
43-
cd /tmp/test-app
43+
cd $RUNNER_TEMP/test-app
4444
4545
cat >> config/importmap.rb << 'EOF'
4646
@@ -58,17 +58,17 @@ jobs:
5858
- name: Run in dry-run mode
5959
uses: ./
6060
env:
61-
IMPORTMAP_RUN_LOG: /tmp/dry-run-output.txt
61+
IMPORTMAP_RUN_LOG: ${{ runner.temp }}/dry-run-output.txt
6262
with:
6363
github-token: ${{ secrets.GITHUB_TOKEN }}
6464
dry-run: "true"
65-
rails-root: /tmp/test-app
65+
rails-root: ${{ runner.temp }}/test-app
6666

6767
- name: Assert all outdated packages appear in dry-run output
6868
run: |
6969
failed=0
7070
for pkg in hotkeys-js is-svg just-extend local-time md5 tom-select; do
71-
if grep -q "$pkg" /tmp/dry-run-output.txt; then
71+
if grep -q "$pkg" $RUNNER_TEMP/dry-run-output.txt; then
7272
echo "✓ $pkg"
7373
else
7474
echo "✗ $pkg not found in output"

action.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ inputs:
2121
description: "When 'true', run end-to-end but skip all side effects (no commits, pushes, or PR operations)."
2222
required: false
2323
default: "false"
24-
ruby-version:
25-
description: "Ruby version to set up. Defaults to the consuming repo's .ruby-version."
26-
required: false
2724
author-name:
2825
description: "Git author name for commits."
2926
required: false
@@ -44,8 +41,8 @@ runs:
4441
shell: bash
4542
working-directory: ${{ inputs.rails-root }}
4643
run: |
47-
bin/importmap audit 2>&1 | tee /tmp/importmap-audit.txt || true
48-
bin/importmap outdated 2>&1 | tee /tmp/importmap-outdated.txt || true
44+
bin/importmap audit 2>&1 | tee "${{ runner.temp }}/importmap-audit.txt" || true
45+
bin/importmap outdated 2>&1 | tee "${{ runner.temp }}/importmap-outdated.txt" || true
4946
5047
- name: Run importmap-update
5148
shell: bash
@@ -60,9 +57,8 @@ runs:
6057
IMPORTMAP_DRY_RUN: ${{ inputs.dry-run }}
6158
IMPORTMAP_AUTHOR_NAME: ${{ inputs.author-name }}
6259
IMPORTMAP_AUTHOR_EMAIL: ${{ inputs.author-email }}
60+
IMPORTMAP_OUTDATED_FILE: ${{ runner.temp }}/importmap-outdated.txt
61+
IMPORTMAP_AUDIT_FILE: ${{ runner.temp }}/importmap-audit.txt
6362
run: |
6463
bundle install
65-
bundle exec exe/importmap-update \
66-
--outdated-file /tmp/importmap-outdated.txt \
67-
--audit-file /tmp/importmap-audit.txt \
68-
2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"
64+
bundle exec exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"

exe/importmap-update

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ require "parsers/audit_parser"
3131

3232
options = {
3333
config_path: ENV.fetch("INPUT_CONFIG_FILE", ".github/importmap-updates.yml"),
34-
outdated_file: nil,
35-
audit_file: nil,
3634
dry_run: %w[true 1 yes].include?(ENV["IMPORTMAP_DRY_RUN"].to_s.downcase)
3735
}
3836

3937
OptionParser.new do |opts|
4038
opts.banner = "Usage: importmap-update [options]"
4139
opts.on("-c", "--config PATH", "Path to config YAML") { |p| options[:config_path] = p }
42-
opts.on("--outdated-file PATH", "Captured `bin/importmap outdated` output") { |p| options[:outdated_file] = p }
43-
opts.on("--audit-file PATH", "Captured `bin/importmap audit` output") { |p| options[:audit_file] = p }
4440
opts.on("--dry-run", "Do not perform side effects; log what would happen") { options[:dry_run] = true }
4541
opts.on("-h", "--help") {
4642
puts opts
@@ -55,11 +51,8 @@ rescue Importmap::Update::Config::ConfigError => e
5551
exit 2
5652
end
5753

58-
missing = [:outdated_file, :audit_file].select { |k| options[k].nil? }
59-
unless missing.empty?
60-
warn "Missing required option(s): #{missing.map { |k| "--#{k.to_s.tr("_", "-")}" }.join(", ")}"
61-
exit 2
62-
end
54+
outdated_file = ENV.fetch("IMPORTMAP_OUTDATED_FILE")
55+
audit_file = ENV.fetch("IMPORTMAP_AUDIT_FILE")
6356

6457
repo = ENV["GITHUB_REPOSITORY"]
6558
if repo.nil? || repo.empty?
@@ -82,8 +75,8 @@ git = Importmap::Update::GitClient.new(
8275
author_email: ENV.fetch("IMPORTMAP_AUTHOR_EMAIL", "github-actions[bot]@users.noreply.github.com")
8376
)
8477

85-
outdated_output = File.read(options[:outdated_file])
86-
audit_output = File.read(options[:audit_file])
78+
outdated_output = File.read(outdated_file)
79+
audit_output = File.read(audit_file)
8780
outdated = Importmap::Update::Parsers::OutdatedParser.parse(outdated_output)
8881
vulnerabilities = Importmap::Update::Parsers::AuditParser.parse(audit_output)
8982
plan = Importmap::Update::Planner.new(

0 commit comments

Comments
 (0)