From c24e39bec76c7cf6f81d06f3c9dbca074d6fe2ca Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 18:24:21 +0100 Subject: [PATCH 01/23] Only lint Rubocop for now (and only modified files) deleted files are excluded --- .github/workflows/linter.yml | 107 ++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ff55d914e..c0fc703ca 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,66 +1,67 @@ -on: [push] +name: Linting + +on: [push, pull_request] jobs: + + # RuboCop Linting + # Workflow adapted from Rails + # https://github.com/rails/rails/blob/main/.github/workflows/rubocop.yml rubocop: + name: RuboCop runs-on: ubuntu-latest - name: A job to check rubocop linter errors steps: - - uses: actions/checkout@v2 + - name: Checkout sources + uses: actions/checkout@v4 + - name: Set up Ruby 3 uses: ruby/setup-ruby@v1 with: ruby-version: 3.1.4 - - name: Install gems # usual step to install the gems. + bundler-cache: true + + # Scope Rubocop to files: + # https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b + - name: Run RuboCop run: | - bin/bundle config path vendor/bundle - bin/bundle config set without 'default doc job cable storage ujs test db' - bin/bundle install --jobs 4 --retry 3 - - name: Linter count - id: hello - uses: henrixapp/linter-less-or-equal-action@v1.19 - with: - name: Rubocop - command: bin/bundle exec rubocop app config lib spec - total_regexp: \d+ offenses detected - errors_regexp: \d+ offenses detected - warnings_regexp: \d+ offenses detected - compare_branch: mampf-next - mode: changed - include: .rb - eslint: - runs-on: ubuntu-latest - name: A job to check eslint linter errors - steps: - - uses: actions/checkout@v2 - - name: Linter count - id: hello - uses: henrixapp/linter-less-or-equal-action@v1.19 - with: - name: EsLint - command: npx eslint - total_regexp: \d+ problems - errors_regexp: \d+ errors - warnings_regexp: \d+ warnings - compare_branch: mampf-next - mode: changed - include: .js - coffee: - runs-on: ubuntu-latest - name: A job to check coffee linter errors - steps: - - uses: actions/checkout@v2 - - name: Linter count - id: hello - uses: henrixapp/linter-less-or-equal-action@v1.19 - with: - name: Coffee - command: npx coffeelint - total_regexp: \d+ errors - errors_regexp: \d+ errors - warnings_regexp: \d+ warnings - compare_branch: mampf-next - mode: changed - include: .coffee + git diff --diff-filter=d --name-only mampf-next... \ + | xargs bundle exec rubocop --parallel + + + # eslint: + # runs-on: ubuntu-latest + # name: A job to check eslint linter errors + # steps: + # - uses: actions/checkout@v2 + # - name: Linter count + # id: hello + # uses: henrixapp/linter-less-or-equal-action@v1.19 + # with: + # name: EsLint + # command: npx eslint + # total_regexp: \d+ problems + # errors_regexp: \d+ errors + # warnings_regexp: \d+ warnings + # compare_branch: mampf-next + # mode: changed + # include: .js + # coffee: + # runs-on: ubuntu-latest + # name: A job to check coffee linter errors + # steps: + # - uses: actions/checkout@v2 + # - name: Linter count + # id: hello + # uses: henrixapp/linter-less-or-equal-action@v1.19 + # with: + # name: Coffee + # command: npx coffeelint + # total_regexp: \d+ errors + # errors_regexp: \d+ errors + # warnings_regexp: \d+ warnings + # compare_branch: mampf-next + # mode: changed + # include: .coffee # erblint: # runs-on: ubuntu-latest # name: A job to check erblint linter errors From bd13f25a036333114dfabf1d3a675a195c490a8b Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 18:36:40 +0100 Subject: [PATCH 02/23] Scope action for PRs --- .github/workflows/linter.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index c0fc703ca..55e8895ef 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,6 +1,12 @@ name: Linting -on: [push, pull_request] +on: + push: + branches: + - '**' + pull_request: + branches: + - 'main' # Continuous Releases jobs: From f394dc75f7ef9d4336fb4d123ca1cf60aae1e0bf Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 18:38:36 +0100 Subject: [PATCH 03/23] Disable tests for now --- .github/workflows/tests.yml | 84 ------------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index ac0fb3280..000000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: Tests - -on: - push: - branches: - - main - - mampf-next - - production - - experimental - pull_request: - -jobs: - unit-test-job: - name: Execute unit tests & upload to Codecov - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Pull docker images - run: docker compose pull --ignore-buildable - working-directory: docker/run_cypress_tests - - - name: Use Docker layer caching # https://github.com/jpribyl/action-docker-layer-caching - uses: jpribyl/action-docker-layer-caching@v0.1.1 - continue-on-error: true - - - name: Build docker containers - run: docker compose build - working-directory: docker/run_cypress_tests - - name: Create and migrate DB - run: docker compose run --entrypoint "" mampf sh -c "rake db:create db:migrate db:test:prepare" - working-directory: docker/run_cypress_tests - - name: Reindex sunspot - working-directory: docker/run_cypress_tests - run: | - docker compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rake sunspot:reindex" - - - name: Run unit tests - working-directory: docker/run_cypress_tests - run: docker compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rails spec" - - name: Send test coverage report to Codecov - uses: codecov/codecov-action@v3 - with: - files: ./coverage/coverage.xml - fail_ci_if_error: true - verbose: true - e2e-test-job: - name: Run E2E tests & upload results to Cypress - runs-on: ubuntu-latest - timeout-minutes: 30 - needs: unit-test-job - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Pull docker images - run: docker compose pull --ignore-buildable - working-directory: docker/run_cypress_tests - - - name: Use Docker layer caching # https://github.com/jpribyl/action-docker-layer-caching - uses: jpribyl/action-docker-layer-caching@v0.1.1 - continue-on-error: true - - - name: Build docker containers - run: docker compose build - working-directory: docker/run_cypress_tests - - name: Create and migrate DB - run: docker compose run --entrypoint "" mampf sh -c "rake db:create db:migrate db:test:prepare" - working-directory: docker/run_cypress_tests - - name: Run integration tests - working-directory: docker/run_cypress_tests - env: - # pass the Dashboard record key as an environment variable - CYPRESS_baseUrl: http://mampf:3000 - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - # pass GitHub token to allow accurately detecting a build vs a re-run build - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: docker compose run -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} --entrypoint="" cypress_runner sh -c "while ! curl http://mampf:3000 ; do echo waiting for MaMpf to come online at http://mampf:3000; sleep 3; done; cypress run --record --key ${{ secrets.CYPRESS_RECORD_KEY }}" - From 3843c1ec7b76789a5e5d9c58d69188d00913b950 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 18:39:58 +0100 Subject: [PATCH 04/23] Run command in one line --- .github/workflows/linter.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 55e8895ef..e33a9f9fb 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -30,8 +30,7 @@ jobs: # https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b - name: Run RuboCop run: | - git diff --diff-filter=d --name-only mampf-next... \ - | xargs bundle exec rubocop --parallel + git diff --diff-filter=d --name-only mampf-next... | xargs bundle exec rubocop --parallel # eslint: From 24f4cb57049859c14ce6f2be9d3f27a971f75417 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 18:45:39 +0100 Subject: [PATCH 05/23] Fix RuboCop command --- .github/workflows/linter.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index e33a9f9fb..0bd5ce59c 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -20,6 +20,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 + - name: Fetch target branch + run: | + echo "TARGET_BRANCH=${{ github.base_ref || 'mampf-next' }}" >> $GITHUB_ENV && + echo "Target branch is: $TARGET_BRANCH" && + git fetch origin $TARGET_BRANCH -- depth 1 + - name: Set up Ruby 3 uses: ruby/setup-ruby@v1 with: @@ -30,7 +36,7 @@ jobs: # https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b - name: Run RuboCop run: | - git diff --diff-filter=d --name-only mampf-next... | xargs bundle exec rubocop --parallel + git diff --diff-filter=d --name-only $TARGET_BRANCH... | grep '\.rb$' | xargs bundle exec rubocop --parallel # eslint: From eed711beaef393b02a035a6b8c11139672ef2fa1 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 19:14:13 +0100 Subject: [PATCH 06/23] Further improve linting setup --- .github/workflows/linter.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0bd5ce59c..1e2882f64 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -10,7 +10,6 @@ on: jobs: - # RuboCop Linting # Workflow adapted from Rails # https://github.com/rails/rails/blob/main/.github/workflows/rubocop.yml rubocop: @@ -20,11 +19,19 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 - - name: Fetch target branch + # If this action is not triggered from a PR, we use 'mampf-next' as default + # target branch to compare against. This might not cover all use cases. + # But in the end, one has to open a PR anyways and then the correct target + # branch is identified. + # TODO: rename to 'dev' when 'mampf-next' branch is renamed. + - name: Find target branch run: | - echo "TARGET_BRANCH=${{ github.base_ref || 'mampf-next' }}" >> $GITHUB_ENV && - echo "Target branch is: $TARGET_BRANCH" && - git fetch origin $TARGET_BRANCH -- depth 1 + echo "TARGET_BRANCH=${{ github.base_ref || 'mampf-next' }}" >> $GITHUB_ENV + + - name: Fetch target branch (for later git diff) + run: | + echo "Fetching target branch: $TARGET_BRANCH" && + git fetch origin $TARGET_BRANCH --depth 1 - name: Set up Ruby 3 uses: ruby/setup-ruby@v1 @@ -32,7 +39,7 @@ jobs: ruby-version: 3.1.4 bundler-cache: true - # Scope Rubocop to files: + # Scope Rubocop to changed files: # https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b - name: Run RuboCop run: | From 74a397dcaa4996d04697bec50f99cb19135782bc Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 19:29:18 +0100 Subject: [PATCH 07/23] Simplify linter setup --- .github/workflows/linter.yml | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 1e2882f64..cfccf9c8d 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -18,20 +18,8 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v4 - - # If this action is not triggered from a PR, we use 'mampf-next' as default - # target branch to compare against. This might not cover all use cases. - # But in the end, one has to open a PR anyways and then the correct target - # branch is identified. - # TODO: rename to 'dev' when 'mampf-next' branch is renamed. - - name: Find target branch - run: | - echo "TARGET_BRANCH=${{ github.base_ref || 'mampf-next' }}" >> $GITHUB_ENV - - - name: Fetch target branch (for later git diff) - run: | - echo "Fetching target branch: $TARGET_BRANCH" && - git fetch origin $TARGET_BRANCH --depth 1 + with: + fetch-depth: 2 # to also fetch parent commit for git diff - name: Set up Ruby 3 uses: ruby/setup-ruby@v1 @@ -41,9 +29,11 @@ jobs: # Scope Rubocop to changed files: # https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b + # https://github.com/actions/checkout/issues/520#issuecomment-1167205721 + # Exclude deleted files - name: Run RuboCop run: | - git diff --diff-filter=d --name-only $TARGET_BRANCH... | grep '\.rb$' | xargs bundle exec rubocop --parallel + git diff-tree --name-only --diff-filter=d -r HEAD^1 HEAD | grep '\.rb$' | xargs bundle exec rubocop --parallel # eslint: From 7515717d7fe394ae0c5893da779d40b093102d4f Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 19:34:40 +0100 Subject: [PATCH 08/23] Print changed ruby files --- .github/workflows/linter.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index cfccf9c8d..bc1b55a41 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -26,14 +26,21 @@ jobs: with: ruby-version: 3.1.4 bundler-cache: true - + + # Deleted files are excluded + # adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721 + - name: Get changed ruby files (git diff) + run: | + changedFiles=$(git diff-tree --name-only --diff-filter=d -r HEAD^1 HEAD | grep '\.rb$') + echo "Changed ruby files: $changedFiles" + echo "CHANGED_FILES=$changedFiles" >> $GITHUB_ENV + # Scope Rubocop to changed files: # https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b - # https://github.com/actions/checkout/issues/520#issuecomment-1167205721 # Exclude deleted files - name: Run RuboCop run: | - git diff-tree --name-only --diff-filter=d -r HEAD^1 HEAD | grep '\.rb$' | xargs bundle exec rubocop --parallel + $CHANGED_FILES | xargs bundle exec rubocop --parallel # eslint: From 162416a4fed1edf610a20b85b791f6b2d6333656 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 19:42:50 +0100 Subject: [PATCH 09/23] Fix further errors and improve workflow file --- .github/workflows/linter.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index bc1b55a41..08eda31ad 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -10,8 +10,6 @@ on: jobs: - # Workflow adapted from Rails - # https://github.com/rails/rails/blob/main/.github/workflows/rubocop.yml rubocop: name: RuboCop runs-on: ubuntu-latest @@ -27,20 +25,22 @@ jobs: ruby-version: 3.1.4 bundler-cache: true - # Deleted files are excluded # adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721 + # and: https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b + # --diff-filter=d excludes deleted files + # "|| test $? = 1;" is used to ignore the exit code of grep when no files + # are found matching the pattern - name: Get changed ruby files (git diff) run: | - changedFiles=$(git diff-tree --name-only --diff-filter=d -r HEAD^1 HEAD | grep '\.rb$') + changedFiles=$(git diff-tree --name-only --diff-filter=d -r HEAD^1 HEAD | grep '\.rb$' || test $? = 1;) echo "Changed ruby files: $changedFiles" echo "CHANGED_FILES=$changedFiles" >> $GITHUB_ENV - # Scope Rubocop to changed files: - # https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b - # Exclude deleted files + # See RuboCop command line flags here: + # https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags - name: Run RuboCop - run: | - $CHANGED_FILES | xargs bundle exec rubocop --parallel + if: ${{ env.CHANGED_FILES != '' }} + run: $CHANGED_FILES | xargs bundle exec rubocop # eslint: From fe154da4b0a639d83a83e697955fc1d23d6a644d Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 20:03:21 +0100 Subject: [PATCH 10/23] Change random Rails files to see effects --- app/models/notion.rb | 1 + spec/rails_helper.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/models/notion.rb b/app/models/notion.rb index de98a93d9..93b7f6fb3 100644 --- a/app/models/notion.rb +++ b/app/models/notion.rb @@ -1,3 +1,4 @@ +# is it working? class Notion < ApplicationRecord belongs_to :tag, optional: true, touch: true belongs_to :aliased_tag, class_name: 'Tag', optional: true, touch: true diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 34043b89a..ae15b1905 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # This file is copied to spec/ when you run 'rails generate rspec:install' +# Test require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) # Prevent database truncation if the environment is production From 32965eb162d5f0ce6543b99344ba811ff256fd3d Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 20:13:46 +0100 Subject: [PATCH 11/23] Fix spaces in changed files --- .github/workflows/linter.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 08eda31ad..fe2b3424d 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -33,8 +33,8 @@ jobs: - name: Get changed ruby files (git diff) run: | changedFiles=$(git diff-tree --name-only --diff-filter=d -r HEAD^1 HEAD | grep '\.rb$' || test $? = 1;) - echo "Changed ruby files: $changedFiles" - echo "CHANGED_FILES=$changedFiles" >> $GITHUB_ENV + printf "Changed ruby files: \n$changedFiles" + echo "CHANGED_FILES=\"$changedFiles\"" >> $GITHUB_ENV # See RuboCop command line flags here: # https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags From 19f55e9d1b69c62f166e1a046b2b5bcdfc6a7594 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 20:48:16 +0100 Subject: [PATCH 12/23] Include target branch lookup --- .github/workflows/linter.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index fe2b3424d..031bdb483 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -32,7 +32,8 @@ jobs: # are found matching the pattern - name: Get changed ruby files (git diff) run: | - changedFiles=$(git diff-tree --name-only --diff-filter=d -r HEAD^1 HEAD | grep '\.rb$' || test $? = 1;) + targetBranch=${{ github.base_ref || 'mampf-next' }} + changedFiles=$(git diff --name-only --diff-filter=d -r $targetBranch | grep '\.rb$' || test $? = 1;) printf "Changed ruby files: \n$changedFiles" echo "CHANGED_FILES=\"$changedFiles\"" >> $GITHUB_ENV From 6194c7ad71cd42b3beb49379557cd7c8ba5a5d57 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 20:51:46 +0100 Subject: [PATCH 13/23] Remove unnecessary ${{}} syntax --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 031bdb483..b391234d4 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -40,7 +40,7 @@ jobs: # See RuboCop command line flags here: # https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags - name: Run RuboCop - if: ${{ env.CHANGED_FILES != '' }} + if: env.CHANGED_FILES != '' run: $CHANGED_FILES | xargs bundle exec rubocop From 573a0ace7148e9df13d1587c6ceeaf84df14d5c1 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 20:56:37 +0100 Subject: [PATCH 14/23] Fetch target branch --- .github/workflows/linter.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index b391234d4..2c0d2b682 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -16,8 +16,6 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v4 - with: - fetch-depth: 2 # to also fetch parent commit for git diff - name: Set up Ruby 3 uses: ruby/setup-ruby@v1 @@ -25,6 +23,17 @@ jobs: ruby-version: 3.1.4 bundler-cache: true + # If this action is not triggered from a PR, we use 'mampf-next' as default + # target branch to compare against. This might not cover all use cases. + # But in the end, one has to open a PR anyways and then the correct target + # branch is identified. + # TODO: rename to 'dev' when 'mampf-next' branch is renamed. + - name: Fetch target branch + run: | + targetBranch=${{ github.base_ref || 'mampf-next' }} + echo "Target branch is: $targetBranch" + git fetch origin $targetBranch:$targetBranch --depth=1 + # adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721 # and: https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b # --diff-filter=d excludes deleted files @@ -32,7 +41,6 @@ jobs: # are found matching the pattern - name: Get changed ruby files (git diff) run: | - targetBranch=${{ github.base_ref || 'mampf-next' }} changedFiles=$(git diff --name-only --diff-filter=d -r $targetBranch | grep '\.rb$' || test $? = 1;) printf "Changed ruby files: \n$changedFiles" echo "CHANGED_FILES=\"$changedFiles\"" >> $GITHUB_ENV From d9bd153a14df18cd61bf5cb8ab0c941bc0b452ae Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 21:36:07 +0100 Subject: [PATCH 15/23] Improve commit retrieval --- .github/workflows/linter.yml | 102 ++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 25 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 2c0d2b682..dcf6ff132 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,55 +1,107 @@ name: Linting +# Trigger each time HEAD branch is updated in a pull request +# see https://github.com/orgs/community/discussions/26366 on: - push: - branches: - - '**' pull_request: - branches: - - 'main' # Continuous Releases + types: [synchronize] jobs: + anothertest: + name: Try out + runs-on: ubuntu-latest + steps: + - name: 'Checkout PR branch (with test merge-commit)' + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: 'Get a list of changed files to process' + run: git diff-tree --name-only --diff-filter 'AM' -r HEAD^1 HEAD + + changedfiles: + name: Get changed files in PR + runs-on: ubuntu-latest + outputs: + changedFiles: ${{ steps.changes.outputs.files}} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Get changed files + id: changes + run: | + echo "files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '\.rb$' || test $? = 1;)" >> $GITHUB_OUTPUT + + # (!!!) https://github.com/actions/checkout/issues/520#issuecomment-1167205721 rubocop: name: RuboCop runs-on: ubuntu-latest + needs: changedfiles + if: ${{needs.changedfiles.outputs.changedFiles}} steps: - - name: Checkout sources - uses: actions/checkout@v4 + - name: Echo changed files + run: echo ${{needs.changedfiles.outputs.changedFiles}} - - name: Set up Ruby 3 - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.1.4 - bundler-cache: true + # - name: Determine target branch + # run: | + # target_branch=${{ github.base_ref || 'mampf-next' }} + # echo "Target branch is: $target_branch" + # echo "TARGET_BRANCH=$target_branch" >> $GITHUB_ENV + + # # for the " + 1", see: + # # https://github.com/actions/checkout/issues/552#issuecomment-1167086216 + # - name: Calculate fetch depth + # run: | + # depth=$(( ${{ github.pull_request.commits }} + 1 )) + # echo "Fetch depth is: $depth" + # echo "PR_FETCH_DEPTH=$depth" >> $GITHUB_ENV + + # - name: 'Checkout PR branch and all PR commits' + # uses: actions/checkout@v3 + # with: + # ref: ${{ github.pull_request.head.ref }} + # fetch-depth: ${{ env.PR_FETCH_DEPTH }} + + # - name: Fetch target branch with enough history for a common merge-base commit + # run: | + # git fetch origin ${{ github.pull_request.base.ref }} + + # - name: Set up Ruby 3 + # uses: ruby/setup-ruby@v1 + # with: + # ruby-version: 3.1.4 + # bundler-cache: true # If this action is not triggered from a PR, we use 'mampf-next' as default # target branch to compare against. This might not cover all use cases. # But in the end, one has to open a PR anyways and then the correct target # branch is identified. # TODO: rename to 'dev' when 'mampf-next' branch is renamed. - - name: Fetch target branch - run: | - targetBranch=${{ github.base_ref || 'mampf-next' }} - echo "Target branch is: $targetBranch" - git fetch origin $targetBranch:$targetBranch --depth=1 + # - name: Fetch target branch + # run: | + # targetBranch=${{ github.base_ref || 'mampf-next' }} + # echo "Target branch is: $targetBranch" + # git fetch origin $targetBranch:$targetBranch --depth=1 # adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721 # and: https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b # --diff-filter=d excludes deleted files # "|| test $? = 1;" is used to ignore the exit code of grep when no files # are found matching the pattern - - name: Get changed ruby files (git diff) - run: | - changedFiles=$(git diff --name-only --diff-filter=d -r $targetBranch | grep '\.rb$' || test $? = 1;) - printf "Changed ruby files: \n$changedFiles" - echo "CHANGED_FILES=\"$changedFiles\"" >> $GITHUB_ENV + # For the "three dots" ... syntax, see + # https://community.atlassian.com/t5/Bitbucket-questions/Git-diff-show-different-files-than-PR-Pull-Request/qaq-p/2331786 + # - name: Get changed ruby files (git diff) + # run: | + # changedFiles=$(git diff --name-only --diff-filter=d -r $targetBranch...HEAD | grep '\.rb$' || test $? = 1;) + # printf "Changed ruby files: \n$changedFiles" + # echo "CHANGED_FILES=\"$changedFiles\"" >> $GITHUB_ENV # See RuboCop command line flags here: # https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags - - name: Run RuboCop - if: env.CHANGED_FILES != '' - run: $CHANGED_FILES | xargs bundle exec rubocop + # - name: Run RuboCop + # if: env.CHANGED_FILES != '' + # run: $CHANGED_FILES | xargs bundle exec rubocop # eslint: From b44c28d7f7b6e01db12ff50e58b1207912b303c9 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 22:49:09 +0100 Subject: [PATCH 16/23] Redo whole workflow --- .github/workflows/linter.yml | 171 +++++------------------------------ 1 file changed, 25 insertions(+), 146 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index dcf6ff132..e021a806e 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -7,158 +7,37 @@ on: types: [synchronize] jobs: - anothertest: - name: Try out + + # Resources: + # number [1] being most important + # [1] https://github.com/actions/checkout/issues/520#issuecomment-1167205721 + # [2] https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b + # [3] https://community.atlassian.com/t5/Bitbucket-questions/Git-diff-show-different-files-than-PR-Pull-Request/qaq-p/2331786 + rubocop: + name: RuboCop runs-on: ubuntu-latest steps: - name: 'Checkout PR branch (with test merge-commit)' uses: actions/checkout@v3 with: - fetch-depth: 2 - - - name: 'Get a list of changed files to process' - run: git diff-tree --name-only --diff-filter 'AM' -r HEAD^1 HEAD - - changedfiles: - name: Get changed files in PR - runs-on: ubuntu-latest - outputs: - changedFiles: ${{ steps.changes.outputs.files}} - steps: - - name: Checkout repo - uses: actions/checkout@v4 - + fetch-depth: 2 # to also fetch parent of PR + + # Adapted from this great comment [1]. Git diff adapted from [2]. + # "|| test $? = 1;" is used to ignore the exit code of grep when no files + # are found matching the pattern. For the "three dots" ... syntax, see [3]. - name: Get changed files - id: changes run: | - echo "files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '\.rb$' || test $? = 1;)" >> $GITHUB_OUTPUT - - # (!!!) https://github.com/actions/checkout/issues/520#issuecomment-1167205721 - rubocop: - name: RuboCop - runs-on: ubuntu-latest - needs: changedfiles - if: ${{needs.changedfiles.outputs.changedFiles}} - steps: - - name: Echo changed files - run: echo ${{needs.changedfiles.outputs.changedFiles}} - - # - name: Determine target branch - # run: | - # target_branch=${{ github.base_ref || 'mampf-next' }} - # echo "Target branch is: $target_branch" - # echo "TARGET_BRANCH=$target_branch" >> $GITHUB_ENV - - # # for the " + 1", see: - # # https://github.com/actions/checkout/issues/552#issuecomment-1167086216 - # - name: Calculate fetch depth - # run: | - # depth=$(( ${{ github.pull_request.commits }} + 1 )) - # echo "Fetch depth is: $depth" - # echo "PR_FETCH_DEPTH=$depth" >> $GITHUB_ENV - - # - name: 'Checkout PR branch and all PR commits' - # uses: actions/checkout@v3 - # with: - # ref: ${{ github.pull_request.head.ref }} - # fetch-depth: ${{ env.PR_FETCH_DEPTH }} + files=$(git diff --name-only --diff-filter=ACMR -r HEAD^1...HEAD | grep '\.rb$' || test $? = 1;) + printf "🎴 Changed ruby files: \n$files" + echo "CHANGED_FILES=$(echo ${files} | xargs)" >> $GITHUB_ENV - # - name: Fetch target branch with enough history for a common merge-base commit - # run: | - # git fetch origin ${{ github.pull_request.base.ref }} - - # - name: Set up Ruby 3 - # uses: ruby/setup-ruby@v1 - # with: - # ruby-version: 3.1.4 - # bundler-cache: true - - # If this action is not triggered from a PR, we use 'mampf-next' as default - # target branch to compare against. This might not cover all use cases. - # But in the end, one has to open a PR anyways and then the correct target - # branch is identified. - # TODO: rename to 'dev' when 'mampf-next' branch is renamed. - # - name: Fetch target branch - # run: | - # targetBranch=${{ github.base_ref || 'mampf-next' }} - # echo "Target branch is: $targetBranch" - # git fetch origin $targetBranch:$targetBranch --depth=1 - - # adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721 - # and: https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b - # --diff-filter=d excludes deleted files - # "|| test $? = 1;" is used to ignore the exit code of grep when no files - # are found matching the pattern - # For the "three dots" ... syntax, see - # https://community.atlassian.com/t5/Bitbucket-questions/Git-diff-show-different-files-than-PR-Pull-Request/qaq-p/2331786 - # - name: Get changed ruby files (git diff) - # run: | - # changedFiles=$(git diff --name-only --diff-filter=d -r $targetBranch...HEAD | grep '\.rb$' || test $? = 1;) - # printf "Changed ruby files: \n$changedFiles" - # echo "CHANGED_FILES=\"$changedFiles\"" >> $GITHUB_ENV - - # See RuboCop command line flags here: - # https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags - # - name: Run RuboCop - # if: env.CHANGED_FILES != '' - # run: $CHANGED_FILES | xargs bundle exec rubocop - + - name: Set up Ruby 3 + if: env.CHANGED_FILES != '' + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1.4 + bundler-cache: true - # eslint: - # runs-on: ubuntu-latest - # name: A job to check eslint linter errors - # steps: - # - uses: actions/checkout@v2 - # - name: Linter count - # id: hello - # uses: henrixapp/linter-less-or-equal-action@v1.19 - # with: - # name: EsLint - # command: npx eslint - # total_regexp: \d+ problems - # errors_regexp: \d+ errors - # warnings_regexp: \d+ warnings - # compare_branch: mampf-next - # mode: changed - # include: .js - # coffee: - # runs-on: ubuntu-latest - # name: A job to check coffee linter errors - # steps: - # - uses: actions/checkout@v2 - # - name: Linter count - # id: hello - # uses: henrixapp/linter-less-or-equal-action@v1.19 - # with: - # name: Coffee - # command: npx coffeelint - # total_regexp: \d+ errors - # errors_regexp: \d+ errors - # warnings_regexp: \d+ warnings - # compare_branch: mampf-next - # mode: changed - # include: .coffee - # erblint: - # runs-on: ubuntu-latest - # name: A job to check erblint linter errors - # steps: - # - uses: actions/checkout@v2 - # - name: Set up Ruby 2.7 - # uses: ruby/setup-ruby@v1 - # with: - # ruby-version: 2.7 - # - name: Install gems # usual step to install the gems. - # run: | - # bin/bundle config path vendor/bundle - # bin/bundle config set without 'default doc job cable storage ujs test db' - # bin/bundle install --jobs 4 --retry 3 - # - name: Linter count - # id: hello - # uses: henrixapp/linter-less-or-equal-action@v1.1 - # with: - # name: Erblint - # command: bin/bundle exec erblint . - # total_regexp: \d+ error(s) - # errors_regexp: \d+ error(s) - # warnings_regexp: \d+ error(s) - # compare_branch: mampf-next + - name: Run RuboCop + if: env.CHANGED_FILES != '' + run: bundle exec rubocop --format github -- $CHANGED_FILES From 4f52f5ac7ebda2e74a000a67c966be228c6b1a4d Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 23:49:04 +0100 Subject: [PATCH 17/23] Revert dummy changes in Rails files --- app/models/notion.rb | 1 - spec/rails_helper.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/app/models/notion.rb b/app/models/notion.rb index 93b7f6fb3..de98a93d9 100644 --- a/app/models/notion.rb +++ b/app/models/notion.rb @@ -1,4 +1,3 @@ -# is it working? class Notion < ApplicationRecord belongs_to :tag, optional: true, touch: true belongs_to :aliased_tag, class_name: 'Tag', optional: true, touch: true diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ae15b1905..34043b89a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true # This file is copied to spec/ when you run 'rails generate rspec:install' -# Test require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) # Prevent database truncation if the environment is production From 8d39787f10287b363bac0cd7ac21574f875122f0 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 14 Nov 2023 23:52:55 +0100 Subject: [PATCH 18/23] Use checkout@v4 (instead of @v3) --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index e021a806e..ca809080e 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout PR branch (with test merge-commit)' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 2 # to also fetch parent of PR From 0bb85a59d4831f4f5c5574c168d275cf893159e8 Mon Sep 17 00:00:00 2001 From: Splines Date: Wed, 15 Nov 2023 21:01:04 +0100 Subject: [PATCH 19/23] Explicitly set fail level & force excluding files See command line flags here: https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ca809080e..d903f7b0f 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -40,4 +40,4 @@ jobs: - name: Run RuboCop if: env.CHANGED_FILES != '' - run: bundle exec rubocop --format github -- $CHANGED_FILES + run: bundle exec rubocop --format github --fail-level 'convention' --force-exclusion -- $CHANGED_FILES From 84d8af85b519a799dc2cdfbc6ad5fa644324be41 Mon Sep 17 00:00:00 2001 From: Splines Date: Wed, 15 Nov 2023 21:07:35 +0100 Subject: [PATCH 20/23] Add random changes & change severity --- .rubocop.yml | 1 + app/models/watchlist.rb | 1 + app/models/xkcd.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index d7b548944..ff2615408 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -178,6 +178,7 @@ Style/MethodCallWithoutArgsParentheses: Style/FrozenStringLiteralComment: Enabled: true + Severity: refactor EnforcedStyle: always Exclude: - 'actionview/test/**/*.builder' diff --git a/app/models/watchlist.rb b/app/models/watchlist.rb index 1602b95be..d956d61db 100644 --- a/app/models/watchlist.rb +++ b/app/models/watchlist.rb @@ -1,3 +1,4 @@ +# Random change class Watchlist < ApplicationRecord belongs_to :user has_many :watchlist_entries, dependent: :destroy diff --git a/app/models/xkcd.rb b/app/models/xkcd.rb index 55752c45b..15525c3ef 100644 --- a/app/models/xkcd.rb +++ b/app/models/xkcd.rb @@ -1,4 +1,5 @@ # Xkcd model for getting Xkcd images +# Random change class Xkcd def self.random max = JSON.parse(URI.open('https://xkcd.com/info.0.json').read)['num'] From 97d31ac68fd373aef2302621a2e9e11e482097b6 Mon Sep 17 00:00:00 2001 From: Splines Date: Wed, 15 Nov 2023 21:12:27 +0100 Subject: [PATCH 21/23] Add more events to trigger workflow See the docs here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index d903f7b0f..858699999 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -4,7 +4,7 @@ name: Linting # see https://github.com/orgs/community/discussions/26366 on: pull_request: - types: [synchronize] + types: [opened, reopened, synchronize, ready_for_review] jobs: From a86ee86c69532d0a4abf17ba354a2e9468561c00 Mon Sep 17 00:00:00 2001 From: Splines Date: Wed, 15 Nov 2023 21:17:07 +0100 Subject: [PATCH 22/23] Add printout to display RuboCop version used --- .github/workflows/linter.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 858699999..d0652ff32 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -40,4 +40,6 @@ jobs: - name: Run RuboCop if: env.CHANGED_FILES != '' - run: bundle exec rubocop --format github --fail-level 'convention' --force-exclusion -- $CHANGED_FILES + run: | + echo "🚨 Running RuboCop version: $(bundle info rubocop | head -1)" + bundle exec rubocop --format github --fail-level 'convention' --force-exclusion -- $CHANGED_FILES From 8a837bcdeb0a3ee90665e6d7067f04c530601814 Mon Sep 17 00:00:00 2001 From: Splines Date: Wed, 15 Nov 2023 21:17:28 +0100 Subject: [PATCH 23/23] Undo change in watchlist --- app/models/watchlist.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/watchlist.rb b/app/models/watchlist.rb index d956d61db..1602b95be 100644 --- a/app/models/watchlist.rb +++ b/app/models/watchlist.rb @@ -1,4 +1,3 @@ -# Random change class Watchlist < ApplicationRecord belongs_to :user has_many :watchlist_entries, dependent: :destroy