Skip to content

Commit

Permalink
Fetch target branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Nov 14, 2023
1 parent 6194c7a commit 573a0ac
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,31 @@ 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
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
- 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
Expand Down

0 comments on commit 573a0ac

Please sign in to comment.