Publish distributions to PyPI or TestPyPI #653
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 distributions to PyPI or TestPyPI | |
# TestPyPI upload is scheduled in each weekday. | |
# PyPI upload is only activated if the release is published. | |
on: | |
schedule: | |
- cron: '0 15 * * *' | |
release: | |
types: | |
- published | |
jobs: | |
build-n-publish: | |
name: Build and publish Python distributions to PyPI or TestPyPI | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
# Not intended for forks. | |
if: github.repository == 'optuna/optuna-integration' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Install twine and build | |
run: | | |
python -m pip install -U pip | |
python -m pip install -U twine build | |
- name: Output installed packages | |
run: | | |
pip freeze --all | |
- name: Output dependency tree | |
run: | | |
pip install pipdeptree | |
pipdeptree | |
- name: Change the version file for scheduled TestPyPI upload | |
if: github.event_name == 'schedule' | |
run: | | |
OPTUNA_VERSION=$(cut -d '"' -f 2 optuna_integration/version.py) | |
DATE=`date +"%Y%m%d"` | |
echo "__version__ = \"${OPTUNA_VERSION}${DATE}\"" > optuna_integration/version.py | |
- name: Build a tar ball | |
run: | | |
python -m build | |
- name: Verify the distributions | |
run: twine check dist/* | |
- name: Publish distribution to TestPyPI | |
# The following upload action cannot be executed in the forked repository. | |
if: (github.event_name == 'schedule') || (github.event_name == 'release') | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
- name: Publish distribution to PyPI | |
# The following upload action cannot be executed in the forked repository. | |
if: github.event_name == 'release' | |
uses: pypa/gh-action-pypi-publish@release/v1 |