Skip to content

Commit

Permalink
Make setup-python an optional flag
Browse files Browse the repository at this point in the history
Set the flag dynamically based on command check
  • Loading branch information
dormant-user committed May 19, 2024
1 parent 6e327b3 commit e01dab0
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
- `skip-existing` - Avoids failing if distribution exists in package index.
- `verbose` - Runs in verbose mode. Defaults to `false`
- `print-hash` - Show hash values of distribution files. Defaults to `true`
- `setup-python` - Uses the GH action `setup-python`. Defaults to `false`,
but gets overridden dynamically based on `python` command's availability.

## License & copyright

Expand Down
80 changes: 76 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ inputs:
description: Show hash values of distribution files
required: false
default: 'true'
setup-python:
description: Use setup python to load python env.
required: false
default: 'false'
branding:
color: gray-dark
icon: package
Expand All @@ -56,33 +60,97 @@ runs:
with:
fetch-depth: 0

- name: Detect OS and Architecture
run: |
# NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname
unamem="$(uname -m)"
case $unamem in
*aarch64*|arm64)
architecture="arm64";;
*64*)
architecture="amd64";;
*86*)
architecture="386";;
*armv5*)
architecture="armv5";;
*armv6*)
architecture="armv6";;
*armv7*)
architecture="armv7";;
*)
echo "Unknown architecture: $unamem"
;;
esac
unameu="$(tr '[:lower:]' '[:upper:]' <<<$(uname))"
if [[ $unameu == *DARWIN* ]]; then
os_name="darwin"
elif [[ $unameu == *LINUX* ]]; then
os_name="linux"
elif [[ $unameu == *FREEBSD* ]]; then
os_name="freebsd"
elif [[ $unameu == *NETBSD* ]]; then
os_name="netbsd"
elif [[ $unameu == *OPENBSD* ]]; then
os_name="openbsd"
elif [[ $unameu == *WIN* || $unameu == MSYS* ]]; then
# Should catch cygwin
os_name="windows"
else
echo "Unknown OS: $(uname)"
fi
echo "architecture=$architecture" >> $GITHUB_ENV
echo "os_name=$os_name" >> $GITHUB_ENV
echo "::notice title=Runner Platform::$os_name-$architecture"
shell: bash

- name: Setup Arguments
run: |
TWINE_EXTRA_ARGS=--disable-progress-bar
if [[ ${{ inputs.skip-existing }} != "false" ]] ; then
if [[ ${{ inputs.skip-existing }} != "false" ]]; then
TWINE_EXTRA_ARGS="${TWINE_EXTRA_ARGS} --skip-existing"
fi
if [[ ${{ inputs.verbose }} != "false" ]] ; then
if [[ ${{ inputs.verbose }} != "false" ]]; then
TWINE_EXTRA_ARGS="--verbose $TWINE_EXTRA_ARGS"
fi
echo "TWINE_EXTRA_ARGS=$TWINE_EXTRA_ARGS" >> $GITHUB_ENV
if [[ ${{ inputs.test-upload }} == "true" ]] ; then
if [[ ${{ inputs.test-upload }} == "true" ]]; then
echo "repository_url=https://test.pypi.org/simple/" >> $GITHUB_ENV
else
echo "repository_url=https://upload.pypi.org/legacy/" >> $GITHUB_ENV
fi
if [[ ${{ inputs.setup-python }} == "true" ]]; then
if [[ ${{ env.os_name }} == "darwin" ]]; then
# Discussion: https://github.com/orgs/community/discussions/26239
# Issue: https://github.com/actions/setup-python/issues/792
# Fix: https://github.com/actions/setup-python/pull/708
echo "::warning title=Unsupported Warning::setup-python may not run on macOS due to a misconfiguration"
fi
echo "setup_python=true" >> $GITHUB_ENV
else
if [[ ! $(command -v python) ]]; then
echo "::warning title=Command404::'python' could not be found, using 'setup-python'"
echo "setup_python=true" >> $GITHUB_ENV
else
echo "setup_python=false" >> $GITHUB_ENV
fi
fi
shell: bash

- name: Set up Python
if: env.setup_python == true
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
python -m pip install build twine
shell: bash

- name: Create packages
Expand Down Expand Up @@ -146,3 +214,7 @@ runs:
TWINE_REPOSITORY_URL: ${{ env.repository_url }}
run: twine upload ${{ env.TWINE_EXTRA_ARGS }} ${{ inputs.packages-dir }}/*.whl
shell: bash

- name: Cleanup
run: rm -rf ${{ inputs.packages-dir }} *.egg-info
shell: bash

0 comments on commit e01dab0

Please sign in to comment.