From 05e5ca933403abef7a04474fd2853f821c45e0b1 Mon Sep 17 00:00:00 2001 From: desiena Date: Thu, 19 Dec 2024 08:07:15 +0100 Subject: [PATCH] Added version --- .github/workflows/ci-cd.yml | 38 ++++++++++++++++++++++++++++++++----- setup.py | 6 +++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 1f419c3..6311414 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,4 +1,4 @@ -name: Publish Python 🐍 distribution 📦 to PyPI +name: Build and publish on: workflow_dispatch: @@ -7,6 +7,10 @@ on: - main tags: - 'v*.*.*' # Example: v1.2.3 +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + PRE_RELEASE_VERSION: true + DRAFT_VERSION: true jobs: build-and-publish: @@ -18,7 +22,30 @@ jobs: id-token: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - name: Sets env vars for main + if: ${{ env.BRANCH_NAME == 'main' }} + run: | + echo "PRE_RELEASE_VERSION=false" >> $GITHUB_ENV + echo "DRAFT_VERSION=false" >> $GITHUB_ENV + + - name: Get next version + uses: reecetech/version-increment@2024.10.1 + id: version + with: + scheme: semver + release_branch: main + + - name: Set PACKAGE_VERSION Environment Variable + run: echo "PACKAGE_VERSION=${{ steps.version.outputs.version }}" >> $GITHUB_ENV + + - name: Release version + uses: softprops/action-gh-release@v2 + with: + draft: ${{ env.DRAFT_VERSION }} + prerelease: ${{ env.PRE_RELEASE_VERSION }} + tag_name: "${{ steps.version.outputs.version }}" - name: Set up Python uses: actions/setup-python@v4 @@ -41,9 +68,9 @@ jobs: pip install -r requirements.txt # (Optional) Run tests -# - name: Run tests -# run: | -# pytest + # - name: Run tests + # run: | + # pytest # Build the package - name: Build package @@ -51,5 +78,6 @@ jobs: python setup.py sdist bdist_wheel - name: Publish package distributions to PyPI + if: ${{ env.PRE_RELEASE_VERSION == false }} uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/setup.py b/setup.py index e4f4169..8048c76 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,15 @@ +import os + from setuptools import setup with open('README.md', 'r', encoding='utf-8') as ld: long_description = ld.read() +version = os.getenv('PACKAGE_VERSION', '0.0.1-dev') + setup( name='fmdata', - version='0.0.1', + version=version, python_requires='>=3.8', author='Lorenzo De Siena', author_email='dev.lorenzo.desiena@gmail.com',