From 6dc49e8d0defaecea9f3b3fdbe65cd9a4ff0b5c2 Mon Sep 17 00:00:00 2001 From: Mac Siri Date: Thu, 7 Mar 2024 12:55:30 -0500 Subject: [PATCH] [CI] Simplify setup steps (#20742) --- .github/workflows/ci.yml | 74 ++++++------------- .../comments/user_edits_a_comment_spec.rb | 15 ++-- 2 files changed, 30 insertions(+), 59 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5fddb6650..e866d5889 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,83 +22,54 @@ env: KNAPSACK_PRO_LOG_LEVEL: info jobs: - bundle_install: + build: runs-on: ubuntu-latest + env: + E2E: true + YARN_ENABLE_HARDENED_MODE: 0 steps: - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 with: bundler-cache: true - - yarn_install: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Look up if node_module cache exist - id: cache + - name: Look up node_modules cache + id: nmcache uses: actions/cache/restore@v4 with: lookup-only: true path: node_modules key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }} restore-keys: ${{ runner.os }}-node-modules-v2- - - name: Cache node_modules + - name: Download node_modules cache if no exact cache-key match uses: actions/cache@v4 with: path: node_modules key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }} restore-keys: ${{ runner.os }}-node-modules-v2- - if: steps.cache.outputs.cache-hit != 'true' - - uses: actions/setup-node@v4 - if: steps.cache.outputs.cache-hit != 'true' - with: - node-version-file: '.nvmrc' - cache: yarn - - run: yarn install --immutable - if: steps.cache.outputs.cache-hit != 'true' - - precompile_assets: - needs: [bundle_install, yarn_install] - runs-on: ubuntu-latest - env: - E2E: true - - steps: - - uses: actions/checkout@v4 - - name: Look up if compiled assets exist + if: steps.nmcache.outputs.cache-hit != 'true' + - name: Cache pre-compiled assets uses: actions/cache@v4 - id: cache + id: assetscache with: - fail-on-cache-miss: false path: | public/assets key: ${{ runner.os }}-compiled-assets-v3-${{ hashFiles('app/assets/**', 'app/javascript/**', '**/package.json', '**/yarn.lock') }} restore-keys: ${{ runner.os }}-compiled-assets-v3- - - name: setup ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - if: steps.cache.outputs.cache-hit != 'true' - - name: Cache node_modules - uses: actions/cache/restore@v4 - with: - path: node_modules - key: ${{ runner.os }}-node-modules-v2-${{ hashFiles('**/yarn.lock') }} - restore-keys: ${{ runner.os }}-node-modules-v2- - if: steps.cache.outputs.cache-hit != 'true' - uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' cache: yarn - if: steps.cache.outputs.cache-hit != 'true' + if: steps.nmcache.outputs.cache-hit != 'true' || steps.assetscache.outputs.cache-hit != 'true' + - run: yarn install --immutable + if: steps.nmcache.outputs.cache-hit != 'true' || steps.assetscache.outputs.cache-hit != 'true' - run: bundle exec rails assets:precompile - if: steps.cache.outputs.cache-hit != 'true' + if: steps.assetscache.outputs.cache-hit != 'true' audit: runs-on: ubuntu-latest - needs: [bundle_install, yarn_install] + needs: [build] steps: - uses: actions/checkout@v4 @@ -127,7 +98,7 @@ jobs: rspec: runs-on: ubuntu-latest - needs: [precompile_assets] + needs: [build] timeout-minutes: 20 env: KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }} @@ -204,7 +175,7 @@ jobs: jest: runs-on: ubuntu-latest - needs: [yarn_install] + needs: [build] timeout-minutes: 20 steps: @@ -237,7 +208,7 @@ jobs: storybook: runs-on: ubuntu-latest - needs: [yarn_install] + needs: [build] timeout-minutes: 20 steps: - uses: actions/checkout@v4 @@ -255,7 +226,7 @@ jobs: build_test: runs-on: ubuntu-latest - needs: [bundle_install, yarn_install] + needs: [build] timeout-minutes: 20 env: RAILS_ENV: production @@ -297,13 +268,14 @@ jobs: uses: ruby/setup-ruby@v1 with: bundler-cache: true + - run: yarn install --immutable - run: bundle exec rails assets:precompile - run: RAILS_ENV=test bin/test-console-check cypress: runs-on: ubuntu-latest timeout-minutes: 20 - needs: [precompile_assets] + needs: [build] env: E2E: true diff --git a/spec/system/comments/user_edits_a_comment_spec.rb b/spec/system/comments/user_edits_a_comment_spec.rb index 5f4717bd7..14846df2c 100644 --- a/spec/system/comments/user_edits_a_comment_spec.rb +++ b/spec/system/comments/user_edits_a_comment_spec.rb @@ -1,9 +1,9 @@ require "rails_helper" -RSpec.describe "Editing A Comment", js: true do +RSpec.describe "Editing A Comment", :js do let(:user) { create(:user) } let!(:article) { create(:article, show_comments: true) } - let(:new_comment_text) { Faker::Lorem.paragraph } + let(:new_comment_text) { "This is an editted text" } let!(:comment) do create(:comment, commentable: article, @@ -19,13 +19,12 @@ RSpec.describe "Editing A Comment", js: true do def assert_updated expect(page).to have_css("textarea") expect(page).to have_text("Editing comment") - fill_in "text-area", with: new_comment_text + find("textarea").send_keys(new_comment_text) - click_button("Submit") + click_link_or_button("Submit") - expect(page).to have_text(new_comment_text) + expect(page).to have_text("Edited on").and have_text(new_comment_text) - expect(page).to have_text("Edited on") # using .last here because the first `