Skip to content

Commit c6abbe9

Browse files
committed
Add integration test against a real Rails app in dry-run mode
1 parent 400ddef commit c6abbe9

4 files changed

Lines changed: 90 additions & 4 deletions

File tree

.github/workflows/integration.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Integration test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
integration:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
pull-requests: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: ruby/setup-ruby@v1
20+
with:
21+
bundler-cache: true
22+
23+
# A full `rails new` is the most realistic way to get a working
24+
# `bin/importmap outdated` target. We skip everything unrelated to
25+
# importmap so the setup stays as fast as possible.
26+
- name: Create test Rails app
27+
run: |
28+
gem install rails --no-document
29+
rails new /tmp/test-app \
30+
--skip-git \
31+
--skip-action-mailer \
32+
--skip-action-mailbox \
33+
--skip-action-text \
34+
--skip-active-record \
35+
--skip-active-storage \
36+
--skip-action-cable \
37+
--skip-bootsnap \
38+
--skip-test \
39+
--quiet
40+
41+
# Pin packages at deliberately outdated versions. URLs point directly
42+
# at CDN-hosted files so no download step is needed and the versions
43+
# are pinned exactly.
44+
- name: Pin outdated packages
45+
run: |
46+
cat >> /tmp/test-app/config/importmap.rb << 'EOF'
47+
48+
pin "is-svg", to: "https://cdn.jsdelivr.net/npm/is-svg@3.0.0/index.js"
49+
pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.2.0/dist/md5.min.js"
50+
pin "local-time", to: "https://cdn.jsdelivr.net/npm/local-time@3.0.2/app/assets/javascripts/local-time.es2017-esm.js"
51+
pin "hotkeys-js", to: "https://cdn.jsdelivr.net/npm/hotkeys-js@4.0.3/dist/hotkeys.esm.js"
52+
pin "tom-select", to: "https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/esm/tom-select.complete.js"
53+
pin "just-extend", to: "https://cdn.jsdelivr.net/npm/just-extend@5.1.1/index.mjs"
54+
EOF
55+
56+
- name: Run in dry-run mode
57+
uses: ./
58+
env:
59+
IMPORTMAP_RUN_LOG: /tmp/dry-run-output.txt
60+
with:
61+
github-token: ${{ secrets.GITHUB_TOKEN }}
62+
dry-run: "true"
63+
working-directory: /tmp/test-app
64+
65+
- name: Assert all outdated packages appear in dry-run output
66+
run: |
67+
failed=0
68+
for pkg in hotkeys-js is-svg just-extend local-time md5 tom-select; do
69+
if grep -q "$pkg" /tmp/dry-run-output.txt; then
70+
echo "✓ $pkg"
71+
else
72+
echo "✗ $pkg not found in output"
73+
failed=1
74+
fi
75+
done
76+
exit $failed

action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ inputs:
3232
description: "Git author email for commits."
3333
required: false
3434
default: "github-actions[bot]@users.noreply.github.com"
35+
working-directory:
36+
description: "Directory containing the Rails app to run against. Useful when the app lives in a subdirectory or for integration testing."
37+
required: false
38+
default: "."
3539

3640
runs:
3741
using: "composite"
@@ -44,6 +48,7 @@ runs:
4448

4549
- name: Run importmap-update
4650
shell: bash
51+
working-directory: ${{ inputs.working-directory }}
4752
env:
4853
GH_TOKEN: ${{ inputs.github-token }}
4954
GITHUB_TOKEN: ${{ inputs.github-token }}
@@ -53,4 +58,4 @@ runs:
5358
IMPORTMAP_DRY_RUN: ${{ inputs.dry-run }}
5459
IMPORTMAP_AUTHOR_NAME: ${{ inputs.author-name }}
5560
IMPORTMAP_AUTHOR_EMAIL: ${{ inputs.author-email }}
56-
run: ${{ github.action_path }}/exe/importmap-update
61+
run: ${{ github.action_path }}/exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}"

lib/executor.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ def handle_noop(action)
105105
def handle_open(action)
106106
spec = action.pr_spec
107107
if @dry_run
108+
names = spec.packages.map(&:name).join(", ")
108109
return Outcome.new(
109110
type: :open, status: :skipped, branch: spec.branch,
110-
detail: "DRY RUN: would open PR for #{spec.packages.size} package(s)."
111+
detail: "DRY RUN: would open PR for #{names}."
111112
)
112113
end
113114

@@ -134,9 +135,10 @@ def handle_force_push(action)
134135
existing = action.existing_pr
135136

136137
if @dry_run
138+
names = spec.packages.map(&:name).join(", ")
137139
return Outcome.new(
138140
type: :force_push, status: :skipped, branch: spec.branch, pr_number: existing.number,
139-
detail: "DRY RUN: would force-push (#{action.reason})."
141+
detail: "DRY RUN: would force-push #{names} (#{action.reason})."
140142
)
141143
end
142144

test/executor_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,11 @@ def test_dry_run_records_skipped_outcomes_and_invokes_nothing
230230
assert_empty @gh.created
231231
assert_empty @gh.updated
232232
assert_empty @gh.closed
233-
# All "would have" details should be informative.
234233
assert(report.outcomes.all? { |o| o.detail.start_with?("DRY RUN") })
234+
open_outcome = report.outcomes.find { |o| o.type == :open }
235+
fp_outcome = report.outcomes.find { |o| o.type == :force_push }
236+
assert_includes open_outcome.detail, "lodash"
237+
assert_includes fp_outcome.detail, "stim"
235238
end
236239

237240
# ---- failure isolation ----

0 commit comments

Comments
 (0)