Skip to content

Commit

Permalink
Adapt isort-action more closely
Browse files Browse the repository at this point in the history
  • Loading branch information
obscurerichard committed May 14, 2024
1 parent f125ba1 commit c99bc11
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 4 deletions.
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
MIT License

Copyright (c) 2024 Tweag I/O Limited.
Copyright (c) 2022 James W. Curtin and Contributors
Copyright (c) 2018 Łukasz Langa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ More advanced example with extra command line options:

## Documentation

This action was inspired by the [black]() and [isort-action]() GitHub actions. It currently uses the Docker method of executing actions.
This action was inspired by and partially derived from the MIT-licensed [black](https://black.readthedocs.io/en/stable/integrations/github_actions.html) and [isort-action](https://github.com/isort/isort-action) GitHub actions.

## Development

Expand Down
45 changes: 42 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
name: 'FawltyDeps'
description: 'Check a Python project for _undeclared_ and _unused_ 3rd party dependencies'
# Inspired by and adapted from https://github.com/psf/black/blob/main/action.yml
# Inspired by and adapted from:
# https://github.com/psf/black/blob/main/action.yml
# https://github.com/isort/isort-action
inputs:
options:
description: "Options passed to fawltydeps. Use `fawltydeps --help` to see available options. Default:
''"
required: false
default: ""
requirements-files:
description: >
path(s) to requirements files that should be installed to properly
configure third-party imports
required: false
paths:
description: >
files or directories to scan for dependency issues
required: false
default: .
branding:
color: "purple"
icon: "check-circle"
outputs:
fawltydeps-result:
description: fawltydeps result
value: ${{ steps.run-fawltydeps.outputs.fawltydeps-output }}
runs:
using: 'docker'
image: 'Dockerfile'
using: 'composite'
steps:
- run: $GITHUB_ACTION_PATH/bin/ensure_python
shell: bash

args:
- fawltydeps
- ${{ inputs.options }}

runs:
using: composite
steps:
- run: $GITHUB_ACTION_PATH/bin/ensure_python
shell: bash
- run: >
$GITHUB_ACTION_PATH/bin/install_packages
${{ inputs.fawltydeps-version }}
${{ inputs.requirements-files || inputs.requirementsFiles }}
shell: bash
- run: echo "::add-matcher::$GITHUB_ACTION_PATH/fawltydeps-matcher.json"
shell: bash
- id: run-isort
run: >
$GITHUB_ACTION_PATH/bin/run_fawltydeps
${{ inputs.options }}
${{ inputs.paths }}
shell: bash
- run: echo "::remove-matcher owner=fawltydeps-matcher::"
shell: bash
12 changes: 12 additions & 0 deletions bin/ensure_python
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# If Python 3 isn't installed, exit
python3 -V > /dev/null 2>&1 || (echo "python3 is not available. Use the setup-python action" && exit 1)

# Make sure we're using a supported version of Python
major_version=$(python3 -c 'import sys; print(sys.version_info[0])')
minor_version=$(python3 -c 'import sys; print(sys.version_info[1])')
if [ "$major_version" -lt 3 ] || [ "$minor_version" -lt 6 ]; then
echo "Minimum supported version of python is 3.6, but $(python3 -V) is installed"
exit 1
fi
22 changes: 22 additions & 0 deletions bin/install_packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

isort_version=$1
requirements_files=$2

echo "::group::Install isort"
if [ -z "$isort_version" ] || [ "$isort_version" == "latest" ]; then
echo "Installing latest version of isort"
python3 -m pip install "isort[requirements_deprecated_finder,pipfile_deprecated_finder]"
else
echo "Installing isort==$isort_version"
python3 -m pip install "isort[requirements_deprecated_finder,pipfile_deprecated_finder]==$isort_version"
fi
echo "::endgroup::"

if [ -n "$requirements_files" ]; then
echo "::group::Install modules from requirements arg"
for file in $requirements_files; do
python3 -m pip install -r "$file"
done
echo "::endgroup::"
fi
18 changes: 18 additions & 0 deletions bin/run_fawltydeps
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

echo "Running fawltydeps $*"
fawltydeps_result=$(fawltydeps "$@")
exit_code=$?

# The fawltydeps output can be a multiline string. By default, GITHUB_OUTPUT expects
# output to be on a single line, so a (random) delimiter needs to be used
# so that the output is parsed properly.
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
DELIMITER=$(echo $RANDOM | md5sum | head -c 20)
{
echo "fawltydeps-output<<${DELIMITER}"
echo "${fawltydeps_result}"
echo "${DELIMITER}"
} >> "${GITHUB_OUTPUT}"

exit $exit_code
23 changes: 23 additions & 0 deletions fawltydeps-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"problemMatcher": [
{
"owner": "fawltydeps-matcher",
"pattern": [
{
"regexp": "(These imports appear to be .* dependencies):$",
"message": 1
},
{
"regexp": "^- '([^']+)' imported at:$",
"message": 1
},
{
"regexp": "^ (.+):([0-9]+)$",
"file": 1,
"line": 2,
"loop": true
}
]
}
]
}

0 comments on commit c99bc11

Please sign in to comment.