diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ff4a426 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,76 @@ +name: Release + +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +permissions: + contents: read + +jobs: + build: + name: Build dist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: '3.14' + + - name: Check the tag matches nodeenv_version + run: | + set -euo pipefail + version=$(sed -n "s/^nodeenv_version = '\(.*\)'$/\1/p" nodeenv.py) + if [ -z "${version}" ]; then + echo "::error::could not read nodeenv_version from nodeenv.py" + exit 1 + fi + if [ "${GITHUB_REF_NAME}" != "${version}" ]; then + echo "::error::tag ${GITHUB_REF_NAME} does not match" \ + "nodeenv_version ${version}" + exit 1 + fi + echo "VERSION=${version}" >> "${GITHUB_ENV}" + + - name: Build sdist and wheel + run: | + python -m pip install --upgrade build twine + python -m build + + - name: Check the distribution metadata + run: python -m twine check dist/* + + - name: Smoke test the wheel + run: | + set -euo pipefail + python -m venv "${RUNNER_TEMP}/smoke" + "${RUNNER_TEMP}/smoke/bin/python" -m pip install --quiet dist/*.whl + "${RUNNER_TEMP}/smoke/bin/nodeenv" --version | grep -qx "${VERSION}" + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: dist + path: dist/ + if-no-files-found: error + retention-days: 7 + + publish: + name: Publish to PyPI + needs: build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/nodeenv + permissions: + id-token: write + steps: + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: dist + path: dist/ + + - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 + with: + packages-dir: dist/