Publish #6
Workflow file for this run
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 | |
on: | |
release: | |
types: [created] | |
# These are needed because secrets can not be used in 'if' expressions | |
env: | |
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | |
TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_TOKEN }} | |
RTD_WEBHOOK_URL: ${{ secrets.RTD_WEBHOOK_URL }} | |
RTD_WEBHOOK_TOKEN: ${{ secrets.RTD_WEBHOOK_TOKEN }} | |
jobs: | |
# Useful for workflow debugging | |
# printJob: | |
# name: Print event | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Dump GitHub context | |
# env: | |
# GITHUB_CONTEXT: ${{ toJson(github) }} | |
# run: | | |
# echo "$GITHUB_CONTEXT" | |
check_configuration: | |
name: Check for service configuration secrets | |
runs-on: ubuntu-latest | |
steps: | |
# Report on which services are configured | |
- name: Read the Docs URL | |
if: "!(env.RTD_WEBHOOK_URL)" | |
run: echo "::warning title=RTD_WEBHOOK_URL not set::Read the Docs functionality not enabled. Add RTD_WEBHOOK_URL to your repo secrets if you want it enabled." | |
- name: Read the Docs Token | |
if: "!(env.RTD_WEBHOOK_TOKEN)" | |
run: echo "::warning title=RTD_WEBHOOK_TOKEN not set::Read the Docs functionality not enabled. Add RTD_WEBHOOK_TOKEN to your repo secrets if you want it enabled." | |
- name: test.PyPI Token | |
if: "!(env.TEST_PYPI_TOKEN)" | |
run: echo "::warning title=TEST_PYPI_TOKEN not Set::PyPI functionality not enabled. Add PYPI_TOKEN to your repo secrets if you want it enabled." | |
- name: test.PyPI Token | |
if: "!(env.TEST_PYPI_TOKEN)" | |
run: echo "::warning title=TEST_PYPI_TOKEN not Set::test.PyPI functionality not enabled. Add TEST_PYPI_TOKEN to your repo secrets if you want it enabled." | |
publish: | |
name: Publish code and documentation | |
runs-on: ubuntu-latest | |
steps: | |
# Set-up dependencies | |
- name: Check-out repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Needed for tags to be fetched; see https://github.com/actions/checkout/issues/290 | |
# Uncomment if you need mpi | |
# - name: Set-up MPI | |
# uses: mpi4py/setup-mpi@v1 | |
# Uncomment if you need Cuda | |
# - name: Set-up Cuda Toolkit | |
# run: sudo apt-get install nvidia-cuda-toolkit nvidia-cuda-toolkit-gcc | |
- name: Set-up Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
installer-parallel: true | |
- name: Set-up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
cache: 'poetry' | |
# Configure project | |
- name: Set project version | |
run: | | |
poetry version $(git describe --tags --abbrev=0) | |
# Configure repository for test.PyPI | |
- name: Configure Poetry for test.PyPI | |
if: "github.event.release.prerelease && env.TEST_PYPI_TOKEN" | |
run: | | |
poetry config repositories.testpypi https://test.pypi.org/legacy/ | |
poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_TOKEN }} | |
# Configure repository for PyPI | |
- name: Configure Poetry for PyPI | |
if: "!github.event.release.prerelease && env.PYPI_TOKEN" | |
run: | | |
poetry config http-basic.pypi "__token__" ${{ secrets.PYPI_TOKEN }} | |
# Publish docs | |
- name: Trigger RTDs build | |
if: "!github.event.release.prerelease && env.RTD_WEBHOOK_URL && env.RTD_WEBHOOK_TOKEN" | |
run: | | |
curl -X POST \ | |
-d "token=${{ secrets.RTD_WEBHOOK_TOKEN }}" \ | |
${{ secrets.RTD_WEBHOOK_URL }} | |
# Publish project to test.PyPI | |
- name: Publish to test.PyPI | |
if: "github.event.release.prerelease && env.TEST_PYPI_TOKEN" | |
run: poetry publish --build -r testpypi | |
# ... else publish project to PyPI | |
- name: Publish to PyPI | |
if: "!github.event.release.prerelease && env.PYPI_TOKEN" | |
run: poetry publish --build | |