diff --git a/LICENSE b/LICENSE index 49d29e7..4e95194 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 8205e92..a9dc595 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Simple usage: steps: - uses: actions/checkout@v4 - - uses: tweag/FawltyDeps-action@v0.0.3 + - uses: tweag/FawltyDeps-action@v0.1.0 More advanced example with customized command line options: @@ -56,13 +56,15 @@ More advanced example with customized command line options: - name: checkout uses: actions/checkout@v4 - name: fawltydeps lint - uses: tweag/FawltyDeps-action@v0.0.3 + uses: tweag/FawltyDeps-action@v0.1.0 with: options: --list-sources --list-imports --list-deps --detailed +Invoking FawltyDeps Using `options: --detailed` yields good results when you just want to see what problems may be present. + ## 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 diff --git a/action.yml b/action.yml index 798a131..c546307 100644 --- a/action.yml +++ b/action.yml @@ -1,19 +1,48 @@ 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: "" + fawltydeps-version: + description: Version of fawltydeps to use + required: false + default: null + 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: null branding: color: "purple" icon: "check-circle" +outputs: + fawltydeps-result: + description: fawltydeps result + value: ${{ steps.run-fawltydeps.outputs.fawltydeps-output }} runs: - using: 'docker' - image: 'Dockerfile' - args: - - fawltydeps - - ${{ inputs.options }} - + 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 + - id: run-fawltydeps + run: > + $GITHUB_ACTION_PATH/bin/run_fawltydeps + ${{ inputs.options }} + ${{ inputs.paths }} + shell: bash diff --git a/bin/ensure_python b/bin/ensure_python new file mode 100755 index 0000000..f57215e --- /dev/null +++ b/bin/ensure_python @@ -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 diff --git a/bin/install_packages b/bin/install_packages new file mode 100755 index 0000000..274994f --- /dev/null +++ b/bin/install_packages @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +fawltydeps_version=$1 +requirements_files=$2 + +echo "::group::Install fawltydeps" +if [ -z "$fawltydeps_version" ] || [ "$fawltydeps_version" == "latest" ]; then + echo "Installing latest version of fawltydeps" + python3 -m pip install "fawltydeps" +else + echo "Installing fawltydeps==$fawltydeps_version" + python3 -m pip install "fawltydeps==$fawltydeps_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 diff --git a/bin/run_fawltydeps b/bin/run_fawltydeps new file mode 100755 index 0000000..10a48ee --- /dev/null +++ b/bin/run_fawltydeps @@ -0,0 +1,33 @@ +#!/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" + +{ + if [[ "$exit_code" -eq 0 ]]; then + echo "OK: 'fawltydeps $*' :rocket:" + else + echo "Error: 'fawltydeps $*' found issues:" + fi + if [[ -n "${fawltydeps_result}" ]]; then + # shellcheck disable=SC2006 + cat <> "$GITHUB_STEP_SUMMARY" +exit $exit_code