|
| 1 | +name: Assets Precompile Check |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'master' |
| 7 | + pull_request: |
| 8 | + paths-ignore: |
| 9 | + - '**.md' |
| 10 | + - 'docs/**' |
| 11 | + - 'react_on_rails_pro/**' |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + force_run: |
| 15 | + description: 'Force run all jobs (bypass detect-changes)' |
| 16 | + required: false |
| 17 | + type: boolean |
| 18 | + default: false |
| 19 | + |
| 20 | +jobs: |
| 21 | + detect-changes: |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + actions: read |
| 25 | + runs-on: ubuntu-22.04 |
| 26 | + outputs: |
| 27 | + docs_only: ${{ steps.detect.outputs.docs_only }} |
| 28 | + run_dummy_tests: ${{ steps.detect.outputs.run_dummy_tests }} |
| 29 | + has_full_ci_label: ${{ steps.check-label.outputs.result }} |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 50 |
| 34 | + persist-credentials: false |
| 35 | + - name: Check for full-ci label |
| 36 | + id: check-label |
| 37 | + uses: ./.github/actions/check-full-ci-label |
| 38 | + - name: Detect relevant changes |
| 39 | + id: detect |
| 40 | + run: | |
| 41 | + if [ "${{ inputs.force_run }}" = "true" ] || [ "${{ steps.check-label.outputs.result }}" = "true" ]; then |
| 42 | + echo "run_dummy_tests=true" >> "$GITHUB_OUTPUT" |
| 43 | + echo "docs_only=false" >> "$GITHUB_OUTPUT" |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + BASE_REF="${{ github.event.pull_request.base.sha || github.event.before || 'origin/master' }}" |
| 48 | + script/ci-changes-detector "$BASE_REF" |
| 49 | + shell: bash |
| 50 | + - name: Guard docs-only master pushes |
| 51 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 52 | + uses: ./.github/actions/ensure-master-docs-safety |
| 53 | + with: |
| 54 | + docs-only: ${{ steps.detect.outputs.docs_only }} |
| 55 | + previous-sha: ${{ github.event.before }} |
| 56 | + |
| 57 | + precompile-check: |
| 58 | + needs: detect-changes |
| 59 | + # Skip only if: master push AND docs-only changes |
| 60 | + # Otherwise run if: on master OR workflow_dispatch OR dummy tests needed |
| 61 | + if: | |
| 62 | + !( |
| 63 | + github.event_name == 'push' && |
| 64 | + github.ref == 'refs/heads/master' && |
| 65 | + needs.detect-changes.outputs.docs_only == 'true' |
| 66 | + ) && ( |
| 67 | + github.ref == 'refs/heads/master' || |
| 68 | + github.event_name == 'workflow_dispatch' || |
| 69 | + needs.detect-changes.outputs.run_dummy_tests == 'true' |
| 70 | + ) |
| 71 | + runs-on: ubuntu-22.04 |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v4 |
| 74 | + with: |
| 75 | + persist-credentials: false |
| 76 | + - name: Setup Ruby |
| 77 | + uses: ruby/setup-ruby@v1 |
| 78 | + with: |
| 79 | + ruby-version: '3.4' |
| 80 | + bundler: 2.5.9 |
| 81 | + # libyaml-dev is needed for psych v5 |
| 82 | + - name: Fix dependency for libyaml-dev |
| 83 | + run: sudo apt install libyaml-dev |
| 84 | + - name: Setup Node |
| 85 | + uses: ./.github/actions/setup-node-with-retry |
| 86 | + with: |
| 87 | + node-version: '22' |
| 88 | + - name: Setup pnpm |
| 89 | + uses: pnpm/action-setup@v4 |
| 90 | + - name: Get pnpm store directory |
| 91 | + shell: bash |
| 92 | + run: echo "STORE_PATH=$(pnpm store path --silent)" >> "$GITHUB_ENV" |
| 93 | + - name: Setup pnpm cache |
| 94 | + uses: actions/cache@v4 |
| 95 | + with: |
| 96 | + path: ${{ env.STORE_PATH }} |
| 97 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 98 | + restore-keys: | |
| 99 | + ${{ runner.os }}-pnpm-store- |
| 100 | + - name: Print system information |
| 101 | + run: | |
| 102 | + echo "Linux release: "; cat /etc/issue |
| 103 | + echo "Current user: "; whoami |
| 104 | + echo "Current directory: "; pwd |
| 105 | + echo "Ruby version: "; ruby -v |
| 106 | + echo "Node version: "; node -v |
| 107 | + echo "pnpm version: "; pnpm --version |
| 108 | + echo "Bundler version: "; bundle --version |
| 109 | + - name: Install Node modules with pnpm for renderer package |
| 110 | + run: | |
| 111 | + pnpm install --frozen-lockfile |
| 112 | + pnpm add -g yalc |
| 113 | + - name: yalc publish for react-on-rails |
| 114 | + run: cd packages/react-on-rails && yalc publish |
| 115 | + - name: yalc add react-on-rails |
| 116 | + run: cd react_on_rails/spec/dummy && yalc add react-on-rails |
| 117 | + - name: Install Node modules with pnpm for dummy app |
| 118 | + run: cd react_on_rails/spec/dummy && pnpm install --ignore-workspace |
| 119 | + - name: Save dummy app ruby gems to cache |
| 120 | + uses: actions/cache@v4 |
| 121 | + with: |
| 122 | + path: react_on_rails/spec/dummy/vendor/bundle |
| 123 | + key: dummy-app-gem-cache-${{ hashFiles('react_on_rails/spec/dummy/Gemfile.lock') }}-precompile |
| 124 | + - name: Install Ruby Gems for dummy app |
| 125 | + run: | |
| 126 | + cd react_on_rails/spec/dummy |
| 127 | + bundle lock --add-platform 'x86_64-linux' |
| 128 | + if ! bundle check --path=vendor/bundle; then |
| 129 | + bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 |
| 130 | + fi |
| 131 | + - name: Run assets:precompile and check output |
| 132 | + run: | |
| 133 | + cd react_on_rails/spec/dummy |
| 134 | +
|
| 135 | + echo "Running RAILS_ENV=production bin/rake assets:precompile..." |
| 136 | + echo "==========================================" |
| 137 | +
|
| 138 | + # Run precompile and capture both stdout and stderr |
| 139 | + RAILS_ENV=production bin/rake assets:precompile 2>&1 | tee precompile_output.txt |
| 140 | +
|
| 141 | + echo "==========================================" |
| 142 | + echo "Precompile finished. Checking output for known issues..." |
| 143 | + echo "" |
| 144 | +
|
| 145 | + # Check for known failure patterns |
| 146 | + FAILURES_FOUND=0 |
| 147 | +
|
| 148 | + # Pattern 1: Duplicate webpack compilation (indicates rake tasks running twice) |
| 149 | + WEBPACK_COMPILE_COUNT=$(grep -c "Compiled" precompile_output.txt || true) |
| 150 | + if [ "$WEBPACK_COMPILE_COUNT" -gt 1 ]; then |
| 151 | + # Check if these are genuinely different compilations or duplicates |
| 152 | + # If the same "Compiled" message appears multiple times for the same bundle, it's a problem |
| 153 | + DUPLICATE_COMPILES=$(sort precompile_output.txt | uniq -d | grep -c "Compiled" || true) |
| 154 | + if [ "$DUPLICATE_COMPILES" -gt 0 ]; then |
| 155 | + echo "::error::FAILURE: Detected duplicate webpack compilations. Tasks may be running twice." |
| 156 | + echo " Found $DUPLICATE_COMPILES duplicate compilation messages." |
| 157 | + FAILURES_FOUND=1 |
| 158 | + fi |
| 159 | + fi |
| 160 | +
|
| 161 | + # Pattern 2: Duplicate task execution messages |
| 162 | + if grep -q "react_on_rails:generate_packs" precompile_output.txt; then |
| 163 | + GENERATE_PACKS_COUNT=$(grep -c "react_on_rails:generate_packs" precompile_output.txt || true) |
| 164 | + if [ "$GENERATE_PACKS_COUNT" -gt 1 ]; then |
| 165 | + echo "::error::FAILURE: react_on_rails:generate_packs task ran $GENERATE_PACKS_COUNT times (should only run once)." |
| 166 | + FAILURES_FOUND=1 |
| 167 | + fi |
| 168 | + fi |
| 169 | +
|
| 170 | + # Pattern 3: Module not found errors |
| 171 | + if grep -Ei "module not found|cannot find module|can't resolve" precompile_output.txt; then |
| 172 | + echo "::error::FAILURE: Module resolution errors detected in precompile output." |
| 173 | + FAILURES_FOUND=1 |
| 174 | + fi |
| 175 | +
|
| 176 | + # Pattern 4: Webpack build errors |
| 177 | + if grep -Ei "error in |failed to compile|compilation failed" precompile_output.txt; then |
| 178 | + echo "::error::FAILURE: Webpack compilation errors detected." |
| 179 | + FAILURES_FOUND=1 |
| 180 | + fi |
| 181 | +
|
| 182 | + # Pattern 5: Ruby/Rails errors during precompile |
| 183 | + if grep -Ei "NameError|LoadError|NoMethodError|SyntaxError" precompile_output.txt; then |
| 184 | + echo "::error::FAILURE: Ruby errors detected during precompile." |
| 185 | + FAILURES_FOUND=1 |
| 186 | + fi |
| 187 | +
|
| 188 | + # Pattern 6: Asset pipeline errors |
| 189 | + if grep -Ei "sprockets::filenotfound|asset .* was not declared" precompile_output.txt; then |
| 190 | + echo "::error::FAILURE: Asset pipeline errors detected." |
| 191 | + FAILURES_FOUND=1 |
| 192 | + fi |
| 193 | +
|
| 194 | + # Pattern 7: Memory issues |
| 195 | + if grep -Ei "javascript heap out of memory|killed|out of memory" precompile_output.txt; then |
| 196 | + echo "::error::FAILURE: Memory-related errors detected." |
| 197 | + FAILURES_FOUND=1 |
| 198 | + fi |
| 199 | +
|
| 200 | + # Pattern 8: Check for warnings that might indicate problems |
| 201 | + WARNING_COUNT=$(grep -ci "warning" precompile_output.txt || true) |
| 202 | + if [ "$WARNING_COUNT" -gt 10 ]; then |
| 203 | + echo "::warning::High number of warnings detected: $WARNING_COUNT warnings found. Please review." |
| 204 | + fi |
| 205 | +
|
| 206 | + if [ "$FAILURES_FOUND" -eq 1 ]; then |
| 207 | + echo "" |
| 208 | + echo "==========================================" |
| 209 | + echo "PRECOMPILE CHECK FAILED" |
| 210 | + echo "==========================================" |
| 211 | + echo "Review the output above for details." |
| 212 | + exit 1 |
| 213 | + fi |
| 214 | +
|
| 215 | + echo "" |
| 216 | + echo "==========================================" |
| 217 | + echo "PRECOMPILE CHECK PASSED" |
| 218 | + echo "==========================================" |
| 219 | + echo "No known failure patterns detected in precompile output." |
| 220 | + - name: Upload precompile output |
| 221 | + if: always() |
| 222 | + uses: actions/upload-artifact@v4 |
| 223 | + with: |
| 224 | + name: precompile-output-${{ github.run_id }} |
| 225 | + path: react_on_rails/spec/dummy/precompile_output.txt |
| 226 | + retention-days: 7 |
0 commit comments