From 256f15e8ae08ebc13f1889388bf1370694bb998b Mon Sep 17 00:00:00 2001 From: Neil Carvalho Date: Mon, 18 May 2026 10:22:52 -0300 Subject: [PATCH] Add integration test against a real Rails app --- .github/workflows/integration.yml | 70 +++++++++++++++++++++++++++++++ action.yml | 7 +++- lib/executor.rb | 6 ++- test/executor_test.rb | 5 ++- 4 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/integration.yml diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 0000000..9ae35f3 --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,70 @@ +name: Integration test + +on: + push: + branches: [main] + pull_request: + +jobs: + integration: + runs-on: ubuntu-latest + + permissions: + contents: read + pull-requests: read + + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Create test Rails app + run: | + gem install rails --no-document + rails new /tmp/test-app \ + --skip-git \ + --skip-action-mailer \ + --skip-action-mailbox \ + --skip-action-text \ + --skip-active-record \ + --skip-active-storage \ + --skip-action-cable \ + --skip-bootsnap \ + --skip-test \ + --quiet + + - name: Pin outdated packages + run: | + cat >> /tmp/test-app/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" + pin "local-time", to: "https://cdn.jsdelivr.net/npm/local-time@3.0.2/app/assets/javascripts/local-time.es2017-esm.js" + pin "hotkeys-js", to: "https://cdn.jsdelivr.net/npm/hotkeys-js@4.0.3/dist/hotkeys.esm.js" + pin "tom-select", to: "https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/esm/tom-select.complete.js" + pin "just-extend", to: "https://cdn.jsdelivr.net/npm/just-extend@5.1.1/index.mjs" + EOF + + - name: Run in dry-run mode + uses: ./ + env: + IMPORTMAP_RUN_LOG: /tmp/dry-run-output.txt + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + dry-run: "true" + working-directory: /tmp/test-app + + - name: Assert all outdated packages appear in dry-run output + run: | + failed=0 + for pkg in hotkeys-js is-svg just-extend local-time md5 tom-select; do + if grep -q "$pkg" /tmp/dry-run-output.txt; then + echo "✓ $pkg" + else + echo "✗ $pkg not found in output" + failed=1 + fi + done + exit $failed diff --git a/action.yml b/action.yml index 44049de..c271563 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,10 @@ inputs: description: "Git author email for commits." required: false default: "github-actions[bot]@users.noreply.github.com" + working-directory: + description: "Directory containing the Rails app to run against. Useful when the app lives in a subdirectory or for integration testing." + required: false + default: "." runs: using: "composite" @@ -44,6 +48,7 @@ runs: - name: Run importmap-update shell: bash + working-directory: ${{ inputs.working-directory }} env: GH_TOKEN: ${{ inputs.github-token }} GITHUB_TOKEN: ${{ inputs.github-token }} @@ -53,4 +58,4 @@ runs: IMPORTMAP_DRY_RUN: ${{ inputs.dry-run }} IMPORTMAP_AUTHOR_NAME: ${{ inputs.author-name }} IMPORTMAP_AUTHOR_EMAIL: ${{ inputs.author-email }} - run: ${{ github.action_path }}/exe/importmap-update + run: ${{ github.action_path }}/exe/importmap-update 2>&1 | tee "${IMPORTMAP_RUN_LOG:-/dev/null}" diff --git a/lib/executor.rb b/lib/executor.rb index 7890d13..ce8f806 100644 --- a/lib/executor.rb +++ b/lib/executor.rb @@ -105,9 +105,10 @@ def handle_noop(action) def handle_open(action) spec = action.pr_spec if @dry_run + names = spec.packages.map(&:name).join(", ") return Outcome.new( type: :open, status: :skipped, branch: spec.branch, - detail: "DRY RUN: would open PR for #{spec.packages.size} package(s)." + detail: "DRY RUN: would open PR for #{names}." ) end @@ -134,9 +135,10 @@ def handle_force_push(action) existing = action.existing_pr if @dry_run + names = spec.packages.map(&:name).join(", ") return Outcome.new( type: :force_push, status: :skipped, branch: spec.branch, pr_number: existing.number, - detail: "DRY RUN: would force-push (#{action.reason})." + detail: "DRY RUN: would force-push #{names} (#{action.reason})." ) end diff --git a/test/executor_test.rb b/test/executor_test.rb index 52f1fe1..81e59ad 100644 --- a/test/executor_test.rb +++ b/test/executor_test.rb @@ -230,8 +230,11 @@ def test_dry_run_records_skipped_outcomes_and_invokes_nothing assert_empty @gh.created assert_empty @gh.updated assert_empty @gh.closed - # All "would have" details should be informative. assert(report.outcomes.all? { |o| o.detail.start_with?("DRY RUN") }) + open_outcome = report.outcomes.find { |o| o.type == :open } + fp_outcome = report.outcomes.find { |o| o.type == :force_push } + assert_includes open_outcome.detail, "lodash" + assert_includes fp_outcome.detail, "stim" end # ---- failure isolation ----