Skip to content

Commit

Permalink
Add .github/workflows/release.yml
Browse files Browse the repository at this point in the history
Official releases would be published to
https://pypi.org/project/ceph-nvmeof/
on every tag releases on github.

Dev releases would be published to
https://test.pypi.org/project/ceph-nvmeof/
on every merge to "devel" branch.

Package will override if the version already exists.
For example, if "1.2.15" already exists on test.pypi
and the new commit also has same version (in pyproject.toml),
then that package would be overwritten (by using a bigger
build number).

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Jul 17, 2024
1 parent 63b5eab commit 21e72eb
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Publishes official python package at https://pypi.org/project/ceph-nvmeof/
# This is official release, and will be pushed to pypi when a new tag is pushed in repo.
# Usage: pip install ceph-nvmeof==1.2.15

# Also publishes dev python package at https://test.pypi.org/p/ceph-nvmeof
# This is for dev releases, and will be pushed to test pypi on all merges to "devel" branch.
# Usage: `pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ceph-nvmeof==1.2.15`

name: Publish release to PyPI
on:
push:
tags:
- '*'
branches:
- 'devel'
release:
types:
- published
workflow_dispatch:
inputs:
python_version:
description: 'Python Version'
required: false
type: string
pdm_version:
description: 'PDM Version'
required: false
type: string
pypi_env:
description: 'Push to test.pypi (dev) or pypi (prod). And `dev-debug-version` pushes to test.pypi with a test package version.'
required: true
default: 'dev'
type: choice
options:
- dev
- prod
- dev-debug-version
ref:
description: 'Build using this branch, tag or SHA'
required: false
type: string

env:
DEFAULT_PYTHON: ${{ inputs.python_version || '3.9' }}
DEFAULT_PDM: ${{ inputs.pdm_version || '2.7.4' }}
REF: ${{ inputs.ref || 'devel' }}

jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{env.REF}}
- uses: pdm-project/setup-pdm@v3
with:
python-version: ${{env.DEFAULT_PYTHON}}
version: ${{env.DEFAULT_PDM}}

- name: Sync Dependencies
run: pdm sync -v --no-isolation --no-self --no-editable
- name: Compile Protocol Buffers
run: pdm run protoc

- name: Set current date as env variable
run: echo "NOW=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: (DEBUG) Set dev version number
# For debug-release, set version "<current_release>dev<timestamp>" (eg 1.2.15.dev20240710183756)
# (to avoid messing current releases versions like 1.2.15).
run: |
NEW_VERSION="$(pdm show --version).dev$NOW"
sed -i "s/^version = \".*\"/version = \"${NEW_VERSION}\"/" pyproject.toml
if: (inputs.pypi_env && inputs.pypi_env == 'dev-debug-version')
- name: Build package
run: pdm build --config-setting="--build-number=$NOW" --no-sdist

- name: Publish package distributions to PyPI
run: pdm publish --no-build
if: ( github.event_name == 'release' && github.event.action == 'published' ) || (github.event_name == 'workflow_dispatch' && inputs.pypi_env == 'prod')

- name: Publish package distributions to Test PyPI
run: pdm publish --no-build -r testpypi
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && (inputs.pypi_env == 'dev' || inputs.pypi_env == 'dev-debug-version'))

0 comments on commit 21e72eb

Please sign in to comment.