From 55f438489adaec0830f699931cc92e4b82ff1ed5 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Tue, 3 Sep 2024 13:13:18 +0200 Subject: [PATCH] Run GitHub Actions on PRs Also: - Set explicit permissions to read for better security. Workflows run with extended set of permissions by default. By specifying any permission explicitly, all others are set to none. - Update actions to prevent deprecation warning messages - Remove redundant `gem install bundler` (bundler is already available after setup-ruby action) - Move Shakapacker checks to the main integration workflow Ref: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions --- .github/workflows/integration_test.yml | 35 ++++++++--- .../rails_6_webpacker_integration_tests.yaml | 62 ------------------- .github/workflows/ruby.yml | 16 +++-- 3 files changed, 37 insertions(+), 76 deletions(-) delete mode 100644 .github/workflows/rails_6_webpacker_integration_tests.yaml diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 28b8032..f1d2835 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -1,35 +1,41 @@ name: Integration Tests -on: [push] +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read jobs: build: runs-on: ubuntu-latest strategy: matrix: - test-branch: [rails5, rails6, rails7] + test-branch: [rails6, rails7, rails7-shakapacker] timeout-minutes: 20 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Checkout test app - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: jamesmartin/inline_svg_test_app ref: ${{ matrix.test-branch }} path: test_app - - name: Set up Ruby 2.7 + - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7.7 + ruby-version: 3.3.4 + bundler-cache: true - name: Build local gem run: | - gem install bundler - bundle install --jobs 4 --retry 3 bundle exec rake build - name: Use the local gem in the test App id: uselocalgem - uses: jacobtomlinson/gha-find-replace@0.1.1 + uses: jacobtomlinson/gha-find-replace@v3 with: find: "gem 'inline_svg'" replace: "gem 'inline_svg', path: '${{github.workspace}}'" @@ -41,6 +47,17 @@ jobs: run: | cd $GITHUB_WORKSPACE/test_app bundle install --jobs 4 --retry 3 + - name: Set up Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20 + if: matrix.test-branch == 'rails7-shakapacker' + - name: Generate Shakapacker config + run: | + cd $GITHUB_WORKSPACE/test_app + yarn install --check-files + bundle exec rake shakapacker:compile + if: matrix.test-branch == 'rails7-shakapacker' - name: Test run: | cd $GITHUB_WORKSPACE/test_app diff --git a/.github/workflows/rails_6_webpacker_integration_tests.yaml b/.github/workflows/rails_6_webpacker_integration_tests.yaml deleted file mode 100644 index 05149bc..0000000 --- a/.github/workflows/rails_6_webpacker_integration_tests.yaml +++ /dev/null @@ -1,62 +0,0 @@ -name: Rails 6 Webpacker Integration Tests (unreliable) - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - matrix: - test-branch: [rails6-webpacker] - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Checkout test app - uses: actions/checkout@v2 - with: - repository: jamesmartin/inline_svg_test_app - ref: ${{ matrix.test-branch }} - path: test_app - - name: Set up Ruby 3.1 - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.1 - - name: Build local gem - run: | - gem install bundler - bundle install --jobs 4 --retry 3 - bundle exec rake build - - name: Use the local gem in the test App - id: uselocalgem - uses: jacobtomlinson/gha-find-replace@0.1.1 - with: - find: "gem 'inline_svg'" - replace: "gem 'inline_svg', path: '${{github.workspace}}'" - - name: Check local gem in use - run: | - test "${{ steps.uselocalgem.outputs.modifiedFiles }}" != "0" - grep "inline_svg" $GITHUB_WORKSPACE/test_app/Gemfile - - name: Bundle - run: | - cd $GITHUB_WORKSPACE/test_app - bundle install --jobs 4 --retry 3 - - name: Set up Node.js 16.x - uses: actions/setup-node@v2 - with: - node-version: 16 - if: matrix.test-branch == 'rails6-webpacker' - - name: Set up Python 2.7 - uses: actions/setup-python@v4 - with: - python-version: '2.7' - - name: Generate Webpacker config - run: | - cd $GITHUB_WORKSPACE/test_app - CXXFLAGS="--std=c++17" yarn install --check-files - bundle exec rake webpacker:compile - if: matrix.test-branch == 'rails6-webpacker' - - name: Test - run: | - cd $GITHUB_WORKSPACE/test_app - bundle exec rake test diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 4b983f0..7f795a0 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -1,6 +1,13 @@ name: Ruby -on: [push] +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read jobs: build: @@ -8,13 +15,12 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby 2.7 uses: ruby/setup-ruby@v1 with: ruby-version: 2.7.7 - - name: Build and test with Rake + bundler-cache: true + - name: Test with Rake run: | - gem install bundler - bundle install --jobs 4 --retry 3 bundle exec rake