Merge pull request #78 from DataFog/sidmohan0-patch-1 #15
This file contains hidden or 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: PyPI Release | |
| on: | |
| # Manual trigger with version input | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version to release (e.g., 1.2.3)" | |
| required: true | |
| confirm_tests: | |
| description: "Confirm all tests have passed" | |
| type: boolean | |
| required: true | |
| is_prerelease: | |
| description: "Is this a pre-release?" | |
| type: boolean | |
| default: false | |
| required: false | |
| # Auto-trigger for beta releases when merged to dev | |
| push: | |
| branches: | |
| - dev | |
| jobs: | |
| # Job for manual releases (stable or pre-release) | |
| manual_release: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.confirm_tests == 'true' | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Create GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.pypi }} | |
| run: | | |
| git config user.name github-actions | |
| git config user.email [email protected] | |
| git tag v${{ github.event.inputs.version }} | |
| git push origin v${{ github.event.inputs.version }} | |
| if [ "${{ github.event.inputs.is_prerelease }}" == "true" ]; then | |
| gh release create v${{ github.event.inputs.version }} --prerelease --generate-notes | |
| else | |
| gh release create v${{ github.event.inputs.version }} --generate-notes | |
| fi | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload dist/* | |
| # Job for automatic beta releases on merge to dev | |
| auto_beta_release: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/dev' | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine setuptools-scm | |
| - name: Generate beta version | |
| id: beta_version | |
| run: | | |
| # Get the latest tag | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") | |
| # Remove the 'v' prefix if present | |
| LATEST_VERSION=${LATEST_TAG#v} | |
| # Split version into components | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION" | |
| # Extract any existing beta suffix | |
| PATCH_NUM=${PATCH%%b*} | |
| # Get commit count since last tag for unique beta number | |
| COMMIT_COUNT=$(git rev-list --count $LATEST_TAG..HEAD 2>/dev/null || echo "1") | |
| # Generate beta version | |
| BETA_VERSION="$MAJOR.$MINOR.$(($PATCH_NUM))b$COMMIT_COUNT" | |
| echo "Generated beta version: $BETA_VERSION" | |
| echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT | |
| # Update version in setup.py or pyproject.toml if needed | |
| # This depends on how your versioning is configured | |
| - name: Build package | |
| run: python -m build | |
| - name: Create GitHub Pre-Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.pypi }} | |
| BETA_VERSION: ${{ steps.beta_version.outputs.version }} | |
| run: | | |
| git config user.name github-actions | |
| git config user.email [email protected] | |
| git tag v$BETA_VERSION | |
| git push origin v$BETA_VERSION | |
| gh release create v$BETA_VERSION --prerelease --title "Beta Release v$BETA_VERSION" --notes "Automated beta release from dev branch" | |
| - name: Publish to PyPI as Beta | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| BETA_VERSION: ${{ steps.beta_version.outputs.version }} | |
| run: | | |
| # Ensure package is marked as beta in PyPI | |
| twine upload --skip-existing dist/* |