initial version #1
This file contains 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: [main] | |
tags: ["*"] | |
pull_request: | |
branches: [main] | |
jobs: | |
# Build package on every commit on main. | |
build: | |
name: Build package | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.build.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: astral-sh/setup-uv@v3 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version-file: "pyproject.toml" | |
- name: Build package | |
id: build | |
run: | | |
uv build --no-sources | |
uvx check-wheel-contents dist/*.whl | |
echo "version=$(@uvx --from setuptools-scm python -m setuptools_scm)" | tee -a $GITHUB_OUTPUT | |
- name: Print package contents summary | |
run: | | |
echo -e '<details open><summary>sdist contents</summary>\n' >> $GITHUB_STEP_SUMMARY | |
tar -tf dist/*.tar.gz | tree -a --fromfile . | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY | |
echo -e '</details>\n' >> $GITHUB_STEP_SUMMARY | |
echo -e '<details open><summary>wheel contents</summary>\n' >> $GITHUB_STEP_SUMMARY | |
unzip -Z1 dist/*.whl | tree -a --fromfile . | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY | |
echo -e '</details>\n' >> $GITHUB_STEP_SUMMARY | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: ./dist | |
# Draft a new release on tagged commit on main. | |
draft-release: | |
name: Draft release | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | |
needs: [build] | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/download-artifact@v4 | |
- name: Draft a new release | |
run: gh release create --draft --repo ${{ github.repository }} ${{ github.ref_name }} dist/* | |
env: | |
GH_TOKEN: ${{ github.token }} | |
# Publish to PyPI on tagged commit on main. | |
publish-pypi: | |
name: Publish to PyPI | |
runs-on: ubuntu-latest | |
if: | | |
github.repository_owner == 'tahv' | |
&& github.event_name == 'push' | |
&& startsWith(github.ref, 'refs/tags') | |
needs: [build] | |
environment: | |
name: publish-pypi | |
url: https://pypi.org/project/maya-attribs/${{ needs.build.outputs.version }} | |
permissions: | |
id-token: write | |
steps: | |
- uses: actions/download-artifact@v4 | |
- name: Upload package to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
# Publish to Test PyPI on commit on main. | |
publish-test-pypi: | |
name: Publish to Test PyPI | |
runs-on: ubuntu-latest | |
if: | | |
github.repository_owner == 'tahv' | |
&& github.event_name == 'push' | |
&& github.ref == 'refs/heads/main' | |
needs: [build] | |
environment: | |
name: publish-test-pypi | |
url: https://test.pypi.org/project/maya-attribs/${{ needs.build.outputs.version }} | |
permissions: | |
id-token: write | |
steps: | |
- uses: actions/download-artifact@v4 | |
- name: Upload package to Test PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ |