chore: release 0.3.1 #3
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: Publish OpenEnv to PyPI | |
| # Requires a PyPI Trusted Publisher for: | |
| # - repository: huggingface/OpenEnv | |
| # - workflow: publish-pypi.yml | |
| # - environment: pypi | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| permissions: | |
| contents: read | |
| env: | |
| PACKAGE_NAME: openenv | |
| jobs: | |
| build: | |
| name: Build release distribution | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Validate release tag | |
| id: version | |
| run: | | |
| if [[ ! "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "ERROR: release tag must be stable and match vX.Y.Z" | |
| exit 1 | |
| fi | |
| VERSION="${GITHUB_REF_NAME#v}" | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| PYPROJECT_VERSION=$(python3 - <<'PY' | |
| import tomllib | |
| with open("pyproject.toml", "rb") as f: | |
| print(tomllib.load(f)["project"]["version"]) | |
| PY | |
| ) | |
| echo "pyproject.toml: ${PYPROJECT_VERSION} | tag: ${VERSION}" | |
| if [ "${PYPROJECT_VERSION}" != "${VERSION}" ]; then | |
| echo "ERROR: version mismatch; bump pyproject.toml before tagging" | |
| exit 1 | |
| fi | |
| - name: Verify tag commit is on main | |
| run: | | |
| git fetch origin main | |
| if ! git merge-base --is-ancestor "${GITHUB_SHA}" origin/main; then | |
| echo "ERROR: release tag commit must be reachable from origin/main" | |
| exit 1 | |
| fi | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Check package metadata | |
| run: python -m twine check dist/* | |
| - name: Smoke-test built wheel | |
| run: | | |
| python -m venv .pkg-smoke | |
| . .pkg-smoke/bin/activate | |
| python -m pip install --upgrade pip | |
| python -m pip install dist/*.whl | |
| python - <<'PY' | |
| import importlib.metadata | |
| import openenv | |
| installed = importlib.metadata.version("openenv") | |
| assert openenv.__version__ == installed, (openenv.__version__, installed) | |
| print(f"openenv {installed}") | |
| PY | |
| openenv --help | |
| - name: Upload release distribution artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: openenv-${{ steps.version.outputs.version }}-dist | |
| path: dist/ | |
| if-no-files-found: error | |
| publish-to-pypi: | |
| name: Publish to PyPI | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/project/openenv/${{ needs.build.outputs.version }}/ | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Download release distribution artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: openenv-${{ needs.build.outputs.version }}-dist | |
| path: dist/ | |
| - name: Publish package distributions to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| create-github-release: | |
| name: Create GitHub Release | |
| needs: | |
| - build | |
| - publish-to-pypi | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download release distribution artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: openenv-${{ needs.build.outputs.version }}-dist | |
| path: dist/ | |
| - name: Create or update GitHub Release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| if gh release view "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then | |
| gh release upload "${GITHUB_REF_NAME}" dist/* \ | |
| --repo "${GITHUB_REPOSITORY}" \ | |
| --clobber | |
| else | |
| gh release create "${GITHUB_REF_NAME}" dist/* \ | |
| --repo "${GITHUB_REPOSITORY}" \ | |
| --title "${GITHUB_REF_NAME}" \ | |
| --generate-notes | |
| fi |