-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Publish on PyPI | ||
|
||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
|
||
jobs: | ||
fix_release_deps: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip pip-tools setuptools | ||
- name: Set configuration | ||
run: | | ||
git config --global user.name "${GITHUB_ACTOR}" | ||
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | ||
- name: Create requirements files | ||
run: | | ||
python tools/generate_requirements_txt.py | ||
pip-compile -o requirements_full.txt pyproject.toml | ||
git add requirements_full.txt requirements.txt | ||
git commit -m "Updated requirements.txt files" || true | ||
- name: Bump version to new tag | ||
run: | | ||
python -m pip install bump-my-version | ||
bump-my-version bump --new-version $GITHUB_REF_NAME patch | ||
git commit -am "Bump version to: $GITHUB_REF_NAME" | ||
- name: Push back changes to main and tag | ||
run: | | ||
git tag --force $GITHUB_REF_NAME HEAD | ||
git push --force --tags | ||
git switch -C main | ||
git push --set-upstream -f origin main | ||
deploy: | ||
needs: fix_release_deps | ||
runs-on: ubuntu-latest | ||
environment: release | ||
permissions: | ||
# IMPORTANT: this permission is mandatory for trusted publishing | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.ref_name }} | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install build setuptools>=61.2 wheel | ||
python -m build --no-isolation | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@release/v1 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
import tomllib | ||
|
||
this_script = Path(__file__) | ||
root = this_script.parents[1] | ||
pyproject = root / 'pyproject.toml' | ||
|
||
with open(pyproject, 'rb') as f: | ||
metadata = tomllib.load(f) | ||
dependencies = metadata['project']['dependencies'] | ||
|
||
with open('requirements.txt', 'w') as f: | ||
this_script_rel = this_script.relative_to(root) | ||
f.write(f'# generated by {this_script_rel}\n') | ||
f.write('\n'.join(dependencies)) | ||
f.write('\n') |