Skip to content

Commit 256f15e

Browse files
committed
Add integration test against a real Rails app
1 parent 400ddef commit 256f15e

4 files changed

Lines changed: 84 additions & 4 deletions

File tree

.github/workflows/integration.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
- name: Create test Rails app
24+
run: |
25+
gem install rails --no-document
26+
rails new /tmp/test-app \
27+
--skip-git \
28+
--skip-action-mailer \
29+
--skip-action-mailbox \
30+
--skip-action-text \
31+
--skip-active-record \
32+
--skip-active-storage \
33+
--skip-action-cable \
34+
--skip-bootsnap \
35+
--skip-test \
36+
--quiet
37+
38+
- name: Pin outdated packages
39+
run: |
40+
cat >> /tmp/test-app/config/importmap.rb << 'EOF'
41+
42+
pin "is-svg", to: "https://cdn.jsdelivr.net/npm/is-svg@3.0.0/index.js"
43+
pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.2.0/dist/md5.min.js"
44+
pin "local-time", to: "https://cdn.jsdelivr.net/npm/local-time@3.0.2/app/assets/javascripts/local-time.es2017-esm.js"
45+
pin "hotkeys-js", to: "https://cdn.jsdelivr.net/npm/hotkeys-js@4.0.3/dist/hotkeys.esm.js"
46+
pin "tom-select", to: "https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/esm/tom-select.complete.js"
47+
pin "just-extend", to: "https://cdn.jsdelivr.net/npm/just-extend@5.1.1/index.mjs"
48+
EOF
49+
50+
- name: Run in dry-run mode
51+
uses: ./
52+
env:
53+
IMPORTMAP_RUN_LOG: /tmp/dry-run-output.txt
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
dry-run: "true"
57+
working-directory: /tmp/test-app
58+
59+
- name: Assert all outdated packages appear in dry-run output
60+
run: |
61+
failed=0
62+
for pkg in hotkeys-js is-svg just-extend local-time md5 tom-select; do
63+
if grep -q "$pkg" /tmp/dry-run-output.txt; then
64+
echo "✓ $pkg"
65+
else
66+
echo "✗ $pkg not found in output"
67+
failed=1
68+
fi
69+
done
70+
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)