Skip to content

Commit

Permalink
Use new github action for getting changed files (#6114)
Browse files Browse the repository at this point in the history
<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
[Github Action that we use for getting changed files is
deprecated](https://github.com/jitterbit/get-changed-files), as a
result, we receive warning messages in our linter workflows (e.g.
[1](https://github.com/opencv/cvat/actions/runs/4906955272),
[2](https://github.com/opencv/cvat/actions/runs/4894049447),
[3](https://github.com/opencv/cvat/actions/runs/4890905271)). This
workflow rid of these warnings by using another Github Action for
getting changed files.

If do not do this our linter workflows will stop working this summer
[link1](https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/)
[link2](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/)

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [ ] I submit my changes into the `develop` branch
- [ ] I have added a description of my changes into the
[CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md)
file
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [ ] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [ ] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))

### License

- [ ] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
  • Loading branch information
Kirill Sizov authored May 25, 2023
1 parent f93cbba commit 6d7050d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 121 deletions.
20 changes: 7 additions & 13 deletions .github/workflows/bandit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@ jobs:
steps:
- uses: actions/checkout@v3
- id: files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
uses: tj-actions/changed-files@v35.9.2
with:
files: |
**/*.py
files_ignore: |
**/cvat-sdk/*
- name: Run checks
env:
PR_FILES_AM: ${{ steps.files.outputs.added_modified }}
PR_FILES_RENAMED: ${{ steps.files.outputs.renamed }}
run: |
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
for FILE in $PR_FILES; do
EXTENSION="${FILE##*.}"
DIRECTORY="${FILE%%/*}"
if [[ "$EXTENSION" == 'py' && "$DIRECTORY" != 'cvat-sdk' ]]; then
CHANGED_FILES+=" $FILE"
fi
done
CHANGED_FILES=${{steps.files.outputs.all_changed_files}}
if [[ ! -z $CHANGED_FILES ]]; then
sudo apt-get --no-install-recommends install -y build-essential curl python3-dev python3-pip python3-venv
Expand Down
45 changes: 8 additions & 37 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ jobs:
steps:
- uses: actions/checkout@v3
- id: files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
uses: tj-actions/changed-files@v35.9.2
with:
files: |
cvat-sdk/**/*.py
cvat-cli/**/*.py
tests/python/**/*.py
dir_names: true

- name: Run checks
env:
Expand All @@ -17,42 +22,8 @@ jobs:
# If different modules use different Black configs,
# we need to run Black for each python component group separately.
# Otherwise, they all will use the same config.
ENABLED_DIRS=("cvat-sdk" "cvat-cli" "tests/python")
isValueIn () {
# Checks if a value is in an array
# https://stackoverflow.com/a/8574392
# args: value, array
local e match="$1"
shift
for e; do
[[ "$e" == "$match" ]] && return 0;
done
return 1
}
startswith () {
# Inspired by https://stackoverflow.com/a/2172367
# Checks if the first arg starts with the second one
local value="$1"
local beginning="$2"
return $([[ $value == ${beginning}* ]])
}
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
UPDATED_DIRS=""
for FILE in $PR_FILES; do
EXTENSION="${FILE##*.}"
DIRECTORY="$(dirname $FILE)"
if [[ "$EXTENSION" == "py" ]]; then
for EDIR in ${ENABLED_DIRS[@]}; do
if startswith "${DIRECTORY}/" "${EDIR}/" && ! isValueIn "${EDIR}" ${UPDATED_DIRS[@]};
then
UPDATED_DIRS+=" ${EDIR}"
fi
done
fi
done
UPDATED_DIRS=${{steps.files.outputs.all_changed_files}}
if [[ ! -z $UPDATED_DIRS ]]; then
sudo apt-get --no-install-recommends install -y build-essential curl python3-dev python3-pip python3-venv
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/hadolint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ jobs:
steps:
- uses: actions/checkout@v3
- id: files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
uses: tj-actions/changed-files@v35.9.2
with:
files: |
**/Dockerfile*
- name: Run checks
env:
HADOLINT: "${{ github.workspace }}/hadolint"
HADOLINT_VER: "2.1.0"
VERIFICATION_LEVEL: "error"
PR_FILES_AM: ${{ steps.files.outputs.added_modified }}
PR_FILES_RENAMED: ${{ steps.files.outputs.renamed }}
run: |
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
for FILE in $PR_FILES; do
if [[ $FILE =~ 'Dockerfile' ]]; then
CHANGED_FILES+=" $FILE"
fi
done
CHANGED_FILES=${{steps.files.outputs.all_changed_files}}
if [[ ! -z $CHANGED_FILES ]]; then
curl -sL -o $HADOLINT "https://github.com/hadolint/hadolint/releases/download/v$HADOLINT_VER/hadolint-Linux-x86_64" && chmod 700 $HADOLINT
Expand Down
48 changes: 8 additions & 40 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,21 @@ jobs:
steps:
- uses: actions/checkout@v3
- id: files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
uses: tj-actions/changed-files@v35.9.2
with:
files: |
cvat-sdk/**/*.py
cvat-cli/**/*.py
tests/python/**/*.py
dir_names: true

- name: Run checks
env:
PR_FILES_AM: ${{ steps.files.outputs.added_modified }}
PR_FILES_RENAMED: ${{ steps.files.outputs.renamed }}
run: |
# If different modules use different isort configs,
# we need to run isort for each python component group separately.
# Otherwise, they all will use the same config.
ENABLED_DIRS=("cvat-sdk" "cvat-cli" "tests/python")
isValueIn () {
# Checks if a value is in an array
# https://stackoverflow.com/a/8574392
# args: value, array
local e match="$1"
shift
for e; do
[[ "$e" == "$match" ]] && return 0;
done
return 1
}
startswith () {
# Inspired by https://stackoverflow.com/a/2172367
# Checks if the first arg starts with the second one
local value="$1"
local beginning="$2"
return $([[ $value == ${beginning}* ]])
}
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
UPDATED_DIRS=""
for FILE in $PR_FILES; do
EXTENSION="${FILE##*.}"
DIRECTORY="$(dirname $FILE)"
if [[ "$EXTENSION" == "py" ]]; then
for EDIR in ${ENABLED_DIRS[@]}; do
if startswith "${DIRECTORY}/" "${EDIR}/" && ! isValueIn "${EDIR}" ${UPDATED_DIRS[@]};
then
UPDATED_DIRS+=" ${EDIR}"
fi
done
fi
done
UPDATED_DIRS=${{steps.files.outputs.all_changed_files}}
if [[ ! -z $UPDATED_DIRS ]]; then
sudo apt-get --no-install-recommends install -y build-essential curl python3-dev python3-pip python3-venv
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ jobs:
steps:
- uses: actions/checkout@v3
- id: files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
uses: tj-actions/changed-files@v35.9.2
with:
files: |
**/*.py
- name: Run checks
env:
PR_FILES_AM: ${{ steps.files.outputs.added_modified }}
PR_FILES_RENAMED: ${{ steps.files.outputs.renamed }}
run: |
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
for FILE in $PR_FILES; do
EXTENSION="${FILE##*.}"
if [[ "$EXTENSION" == 'py' ]]; then
CHANGED_FILES+=" $FILE"
fi
done
CHANGED_FILES=${{steps.files.outputs.all_changed_files}}
if [[ ! -z $CHANGED_FILES ]]; then
sudo apt-get --no-install-recommends install -y build-essential curl python3-dev python3-pip python3-venv
Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/stylelint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ jobs:
with:
node-version: '16.x'
- id: files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
uses: tj-actions/changed-files@v35.9.2
with:
files: |
**/*.css
**/*.scss
- name: Run checks
env:
PR_FILES_AM: ${{ steps.files.outputs.added_modified }}
PR_FILES_RENAMED: ${{ steps.files.outputs.renamed }}
run: |
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
for FILE in $PR_FILES; do
EXTENSION="${FILE##*.}"
if [[ $EXTENSION == 'css' || $EXTENSION == 'scss' ]]; then
CHANGED_FILES+=" $FILE"
fi
done
CHANGED_FILES=${{steps.files.outputs.all_changed_files}}
if [[ ! -z $CHANGED_FILES ]]; then
yarn install --frozen-lockfile
Expand Down

0 comments on commit 6d7050d

Please sign in to comment.