-
Notifications
You must be signed in to change notification settings - Fork 3
ci: gate PyPI publish behind full CI + environment approval #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+145
−79
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,85 +1,16 @@ | ||
| name: Publish Python 🐍 distribution 📦 to PyPI | ||
|
|
||
| on: push | ||
| on: | ||
| push: | ||
| tags: | ||
| - "v*.*.*" | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build distribution 📦 | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: "3.x" | ||
| - name: Install pypa/build | ||
| run: >- | ||
| python3 -m | ||
| pip install | ||
| build | ||
| --user | ||
| - name: Build a binary wheel and a source tarball | ||
| run: python3 -m build | ||
| - name: Store the distribution packages | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: python-package-distributions | ||
| path: dist/ | ||
|
|
||
| publish-to-pypi: | ||
| name: >- | ||
| Publish Python 🐍 distribution 📦 to PyPI | ||
| if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes | ||
| needs: | ||
| - build | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: pypi | ||
| url: https://pypi.org/p/teslemetry-stream | ||
| release: | ||
| name: Release | ||
| uses: ./.github/workflows/release.yml | ||
| with: | ||
| pypi-project-url: https://pypi.org/p/teslemetry-stream | ||
| permissions: | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Download all the dists | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: python-package-distributions | ||
| path: dist/ | ||
| - name: Publish distribution 📦 to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
|
|
||
| github-release: | ||
| name: >- | ||
| Upload to GitHub Release | ||
| needs: | ||
| - publish-to-pypi | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: write # IMPORTANT: mandatory for making GitHub Releases | ||
|
|
||
| steps: | ||
| - name: Download all the dists | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: python-package-distributions | ||
| path: dist/ | ||
| - name: Create GitHub Release | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| run: >- | ||
| gh release create | ||
| '${{ github.ref_name }}' | ||
| --repo '${{ github.repository }}' | ||
| --notes "" | ||
| - name: Upload artifacts to GitHub Release | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| # Upload to GitHub Release using the `gh` CLI. | ||
| # `dist/` contains the built packages, and the | ||
| # sigstore-produced signatures and certificates. | ||
| run: >- | ||
| gh release upload | ||
| '${{ github.ref_name }}' dist/** | ||
| --repo '${{ github.repository }}' | ||
| contents: write |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| name: Release gate & publish | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| python-version: | ||
| description: Python version to build/test/publish with | ||
| required: false | ||
| type: string | ||
| default: "3.13" | ||
| pypi-project-url: | ||
| description: PyPI project URL shown on the environment deployment | ||
| required: true | ||
| type: string | ||
| environment-name: | ||
| description: Protected GitHub environment gating the publish step | ||
| required: false | ||
| type: string | ||
| default: pypi | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Lint & type-check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v5 | ||
| with: | ||
| enable-cache: true | ||
| - name: Install dependencies | ||
| run: uv sync | ||
| - name: Ruff | ||
| run: uv run --with ruff ruff check teslemetry_stream | ||
| - name: Mypy | ||
| run: uv run --with mypy mypy teslemetry_stream | ||
|
|
||
| test: | ||
| name: Test (Python ${{ matrix.python-version }}) | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v5 | ||
| with: | ||
| enable-cache: true | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| run: uv python install ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: uv sync --python ${{ matrix.python-version }} | ||
| - name: Run tests | ||
| run: | | ||
| shopt -s nullglob | ||
| files=(tests/test_*.py) | ||
| if [ ${#files[@]} -eq 0 ]; then | ||
| echo "No test files found under tests/ - failing." >&2 | ||
| exit 1 | ||
| fi | ||
| for f in "${files[@]}"; do | ||
| echo "Running $f" | ||
| uv run python "$f" | ||
| done | ||
|
|
||
| build: | ||
| name: Build distribution | ||
| needs: [lint, test] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v5 | ||
| with: | ||
| enable-cache: true | ||
| - name: Set up Python ${{ inputs.python-version }} | ||
| run: uv python install ${{ inputs.python-version }} | ||
| - name: Build | ||
| run: uv build | ||
| - name: Check distribution | ||
| run: uv run --with twine twine check dist/* | ||
| - name: Upload artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: python-package-distributions | ||
| path: dist/ | ||
|
|
||
| publish-to-pypi: | ||
| name: Publish distribution to PyPI | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: ${{ inputs.environment-name }} | ||
| url: ${{ inputs.pypi-project-url }} | ||
| permissions: | ||
| id-token: write | ||
| steps: | ||
| - name: Download all the dists | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: python-package-distributions | ||
| path: dist/ | ||
| - name: Publish distribution to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
|
|
||
| github-release: | ||
| name: Upload distribution to GitHub Release | ||
| needs: publish-to-pypi | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write # mandatory for making GitHub Releases | ||
| steps: | ||
| - name: Download all the dists | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: python-package-distributions | ||
| path: dist/ | ||
| - name: Create GitHub Release | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| run: >- | ||
| gh release create | ||
| '${{ github.ref_name }}' | ||
| --repo '${{ github.repository }}' | ||
| --generate-notes | ||
| - name: Upload artifacts to GitHub Release | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| run: >- | ||
| gh release upload | ||
| '${{ github.ref_name }}' dist/** | ||
| --repo '${{ github.repository }}' | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package supports Python 3.9+, and the normal CI test job covers 3.9 through 3.13, but this release gate runs the suite only on the single default of 3.13. A tag containing a compatibility regression on 3.9–3.12 can therefore pass this purported full-CI gate and be published; use the same version matrix as
.github/workflows/ci.ymlbefore allowing the publish job to proceed.AGENTS.md reference: AGENTS.md:L6-L6
Useful? React with 👍 / 👎.