fix: improve dynamic versioning and condition syntax #6
Workflow file for this run
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: Release | |
| on: | |
| push: | |
| branches: | |
| - 'feat/release-automation' # temporary for testing | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Deploy to environment' | |
| required: true | |
| default: 'test' | |
| type: choice | |
| options: | |
| - test | |
| - production | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Poetry | |
| uses: snok/install-poetry@v1 | |
| with: | |
| version: latest | |
| virtualenvs-create: true | |
| virtualenvs-in-project: true | |
| - name: Install dependencies | |
| run: poetry install --with dev | |
| - name: Get version | |
| id: version | |
| run: | | |
| # Build first to trigger dynamic versioning | |
| poetry build | |
| # Extract version from built wheel filename | |
| VERSION=$(ls dist/*.whl | head -1 | sed 's/.*-\([0-9][^-]*\)-.*/\1/') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Version: $VERSION" | |
| - name: Run tests | |
| run: poetry run python scripts/run_tests.py --layer smoke --layer unit | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-${{ steps.version.outputs.version }} | |
| path: dist/ | |
| deploy-test: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'test') || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) | |
| environment: test-pypi | |
| steps: | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist-${{ needs.build.outputs.version }} | |
| path: dist/ | |
| - name: Publish to Test PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| - name: Test installation from Test PyPI | |
| run: | | |
| sleep 60 # Wait for package to be available | |
| pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ memfuse==${{ needs.build.outputs.version }} | |
| python -c "import memfuse; print(f'Installed version: {memfuse.__version__}')" | |
| deploy-production: | |
| needs: [build, deploy-test] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production' | |
| environment: production-pypi | |
| steps: | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist-${{ needs.build.outputs.version }} | |
| path: dist/ | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| create-release: | |
| needs: [build, deploy-production] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| # Get the previous tag | |
| PREV_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") | |
| if [ -n "$PREV_TAG" ]; then | |
| echo "## Changes since $PREV_TAG" > changelog.md | |
| git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD >> changelog.md | |
| else | |
| echo "## Initial Release" > changelog.md | |
| fi | |
| cat changelog.md | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| release_name: Release ${{ github.ref_name }} | |
| body_path: changelog.md | |
| draft: false | |
| prerelease: false |