Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sp1thas committed Nov 21, 2021
1 parent 0945968 commit 06f7a65
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
62 changes: 62 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: python-prefect
author: sp1thas
description: Run prefect commands on a Python project
branding:
icon: check
color: blue

inputs:
projectName:
description: The name of the Prefect project to register this flow in
required: true
prefectVersion:
description: Version of prefect to use
required: false
default: "-"
flowPath:
description: A path to a file or a directory containing the flow(s) to register.
required: false
default: "-"
flowModulePath:
description: A python module name containing the flow(s) to register.
required: false
default: "-"
jsonPath:
description: A path or URL to a JSON file created by `prefect build` containing the flow(s) to register.
required: false
default: "-"
flowName:
description:
The name of a flow to register from the specified paths/modules.
If provided, only flows with a matching name will be registered.
required: false
default: "-"
flowLabel:
description: A label to add on all registered flow(s).
required: false
default: "-"
requirementsFiles:
description:
path(s) to requirements files that should be installed to properly
configure third-party imports
required: false
default: "-"

outputs:
prefect-result:
description: prefect result
value: ${{ steps.run-isort.outputs.isort-output }}

runs:
using: composite
steps:
- run: ${{ github.action_path }}/bin/ensure_python
shell: bash
- run:
${{ github.action_path }}/bin/install_packages ${{ inputs.prefectVersion
}} ${{ inputs.requirementsFiles }}
shell: bash
- id: run-prefect
run:
${{ github.action_path }}/bin/run_register ${{ inputs.projectName }} ${{ inputs.flowPath }} ${{ inputs.flowModulePath }} ${{ inputs.jsonPath }} ${{ inputs.flowName }} ${{ inputs.flowLabel }}
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

prefect_version=$1
requirements_files=$2

echo "::group::Install prefect"
if [ -z "$prefect_version" ]; then
echo "Installing latest version of prefect"
pip3 install "prefect"
else
echo "Installing prefect==$prefect_version"
pip3 install "prefect==$prefect_version"
fi
echo "::endgroup::"

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

echo "Running prefect $*"

args="--project ${1}"

if [ ! "${2}" == "-" ];
then
args="${args} -p ${2}"
fi
if [ ! "${3}" == "-" ];
then
args="${args} -m ${3}"
fi
if [ ! "${4}" == "-" ];
then
args="${args} -j ${4}"
fi
if [ ! "${5}" == "-" ];
then
args="${args} -n ${5}"
fi
if [ ! "${6}" == "-" ];
then
args="${args} -l ${6}"
fi

prefect_result=$(prefect register "${args}")
exit_code=$?

echo "::set-output name=prefect-output::${prefect_result}"
exit $exit_code

0 comments on commit 06f7a65

Please sign in to comment.