Publish to PyPI #43
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish to PyPI | |
on: | |
workflow_dispatch: | |
inputs: | |
test_publish: | |
description: "Publish to test PyPI" | |
type: boolean | |
default: true | |
push: | |
branches: | |
- "main" | |
paths: | |
- "aws_fusion/__init__.py" | |
pull_request: | |
branches: | |
- "main" | |
concurrency: publish | |
env: | |
PYTHON_VERSION: '3.11' | |
TEST_PUBLISH: ${{ inputs.test_publish && inputs.test_publish || github.event_name == 'pull_request' }} | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
name: Publish | |
permissions: | |
contents: write | |
id-token: write | |
environment: | |
name: pypi | |
url: "https://${{ env.TEST_PUBLISH && 'test.' || '' }}pypi.org/project/aws-fusion" | |
steps: | |
- name: Checkout 🔔 | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Package Info | |
id: package_info | |
run: | | |
current_version=$(./setup.py --version) | |
if [[ "${{ env.TEST_PUBLISH }}" == "true" ]]; then | |
updated_version="${current_version}.${{ github.run_number }}" | |
sed -i -E "s|(__version__\s+=\s['\"])${current_version}(['\"])|\1${updated_version}\2|g" aws_fusion/__init__.py | |
current_version="${updated_version}" | |
fi | |
echo "::notice file=aws_fusion/__init__.py::version=${current_version}" | |
echo "version=${current_version}" >> "$GITHUB_OUTPUT" | |
- name: Add git tag | |
if: ${{ env.TEST_PUBLISH == 'false' }} | |
run: | | |
tag="v${{ steps.package_info.outputs.version }}" | |
git tag ${tag} | |
git push origin ${tag} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install setuptools wheel twine | |
- name: Build | |
run: python setup.py sdist bdist_wheel | |
- name: Publish release distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: ${{ env.TEST_PUBLISH == 'true' && 'https://test.pypi.org/legacy/' || '' }} | |