Skip to content

Publish distributions to PyPI or TestPyPI #1357

Publish distributions to PyPI or TestPyPI

Publish distributions to PyPI or TestPyPI #1357

Workflow file for this run

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'
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install twine
run: |
python -m pip install -U pip
python -m pip install -U twine wheel 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/version.py)
DATE=`date +"%Y%m%d"`
echo "__version__ = \"${OPTUNA_VERSION}${DATE}\"" > optuna/version.py
- name: Build a tar ball
run: |
python -m build --sdist --wheel
- 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/
# Temporary workaround to bypass Twine's bug with attestation support
# See https://github.com/pypa/gh-action-pypi-publish/issues/283
# TODO(c-bata): Once a new version of twine is released, delete this line.
# https://github.com/pypa/twine/pull/1172
attestations: false
- 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
with:
# Temporary workaround to bypass Twine's bug with attestation support
# See https://github.com/pypa/gh-action-pypi-publish/issues/283
# TODO(c-bata): Once a new version of twine is released, delete this line.
# https://github.com/pypa/twine/pull/1172
attestations: false