-
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.
Merge pull request #2 from MitchellAcoustics/switch-to-uv
Switch to uv
- Loading branch information
Showing
11 changed files
with
2,069 additions
and
788 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,145 @@ | ||
name: Tagged Release | ||
# based on: https://github.com/ArjanCodes/examples/blob/0b8c8ab74908be5ed9239fcdaed875548d3f595c/2024/publish_pypi/release.yaml | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v[0-9]+.[0-9]+.[0-9]+" # v1.2.3 | ||
- "v[0-9]+.[0-9]+.[0-9]+rc[0-9]+" # v1.2.3rc1 | ||
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" # v1.2.3-rc1 | ||
|
||
jobs: | ||
details: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
new_version: ${{ steps.release.outputs.new_version }} | ||
suffix: ${{ steps.release.outputs.suffix }} | ||
tag_name: ${{ steps.release.outputs.tag_name }} | ||
version_str: ${{ steps.release.outputs.version_str }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Extract tag and Details | ||
id: release | ||
run: | | ||
if [ "${{ github.ref_type }}" = "tag" ]; then | ||
TAG_NAME=${GITHUB_REF#refs/tags/} | ||
# Strip 'v' prefix if present | ||
VERSION_STR=${TAG_NAME#v} | ||
# Split on hyphen to separate version and suffix | ||
NEW_VERSION=$(echo $VERSION_STR | cut -d'-' -f1) | ||
# Get suffix if exists (everything after the hyphen) | ||
SUFFIX=$(echo "$VERSION_STR" | grep -o '[rd][ec][v1][0-9]*' | tr -d '\n') | ||
echo "version_str=$VERSION_STR" >> "$GITHUB_OUTPUT" | ||
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | ||
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT" | ||
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | ||
echo "Version is $VERSION_STR" | ||
echo "Suffix is $SUFFIX" | ||
echo "Tag name is $TAG_NAME" | ||
else | ||
echo "No tag found" | ||
exit 1 | ||
fi | ||
- name: Verify version matches pyproject.toml | ||
run: | | ||
VERSION_STR=${{ steps.release.outputs.version_str }} | ||
TOML_VERSION=$(grep -oP '^version = "\K[^"]+' pyproject.toml) | ||
if [ "${VERSION_STR}" != "${TOML_VERSION}" ]; then | ||
echo "Error: Tag version (${VERSION_STR}) does not match pyproject.toml version (${TOML_VERSION})" | ||
exit 1 | ||
fi | ||
setup_and_build: | ||
needs: | ||
- details | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install uv | ||
uses: astral-sh/setup-uv@v3 | ||
with: | ||
version: "0.4.29" | ||
enable-cache: true | ||
cache-dependency-glob: "uv.lock" | ||
|
||
- name: Setup Python | ||
run: uv python install 3.12 | ||
|
||
- name: Build source and wheel distribution | ||
run: | | ||
uv build | ||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: dist | ||
path: dist/ | ||
|
||
tests-pass: | ||
needs: [details] | ||
uses: ./.github/workflows/test.yml | ||
|
||
pypi_publish: | ||
name: Upload release to PyPI | ||
needs: [setup_and_build, details, tests-pass] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: dist | ||
path: dist/ | ||
|
||
- name: Publish distribution to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
|
||
- name: Install cityseg from TestPyPI | ||
uses: nick-fields/retry@v3 | ||
with: | ||
timeout_minutes: 5 | ||
max_attempts: 3 | ||
retry_wait_seconds: 30 | ||
command: python -m pip install "cityseg==${{ needs.details.outputs.version_str }}" | ||
- run: python -c "import cityseg; print(cityseg.__version__)" | ||
|
||
|
||
github_release: | ||
name: Create GitHub Release | ||
needs: [setup_and_build, details, tests-pass] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Download artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: dist | ||
path: dist/ | ||
|
||
- name: Create GitHub Release | ||
id: create_release | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
if [ ! -z "${{ needs.details.outputs.suffix }}" ]; then | ||
gh release create ${{ needs.details.outputs.tag_name }} dist/* --title ${{ needs.details.outputs.tag_name }} --generate-notes --prerelease | ||
else | ||
gh release create ${{ needs.details.outputs.tag_name }} dist/* --title ${{ needs.details.outputs.tag_name }} --generate-notes | ||
fi |
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,110 @@ | ||
name: Test Tagged Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v[0-9]+.[0-9]+.[0-9]+-dev[0-9]+" # v1.2.3-dev1 | ||
- "v[0-9]+.[0-9]+.[0-9]+dev[0-9]+" # v1.2.3dev1 | ||
|
||
|
||
jobs: | ||
# Reuse the details job with no changes | ||
details: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
new_version: ${{ steps.release.outputs.new_version }} | ||
version_str: ${{ steps.release.outputs.version_str }} | ||
suffix: ${{ steps.release.outputs.suffix }} | ||
tag_name: ${{ steps.release.outputs.tag_name }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Extract tag and Details | ||
id: release | ||
run: | | ||
if [ "${{ github.ref_type }}" = "tag" ]; then | ||
TAG_NAME=${GITHUB_REF#refs/tags/} | ||
VERSION_STR=${TAG_NAME#v} | ||
NEW_VERSION=$(echo $VERSION_STR | cut -d'-' -f1) | ||
SUFFIX=$(echo "$VERSION_STR" | grep -o '[rd][ec][v1][0-9]*' | tr -d '\n') | ||
echo "version_str=$VERSION_STR" >> "$GITHUB_OUTPUT" | ||
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | ||
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT" | ||
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | ||
echo "Version is $VERSION_STR" | ||
echo "Suffix is $SUFFIX" | ||
echo "Tag name is $TAG_NAME" | ||
else | ||
echo "No tag found" | ||
exit 1 | ||
fi | ||
- name: Verify version matches pyproject.toml | ||
run: | | ||
VERSION_STR=${{ steps.release.outputs.version_str }} | ||
TOML_VERSION=$(grep -oP '^version = "\K[^"]+' pyproject.toml) | ||
if [ "${VERSION_STR}" != "${TOML_VERSION}" ]; then | ||
echo "Error: Tag version (${VERSION_STR}) does not match pyproject.toml version (${TOML_VERSION})" | ||
exit 1 | ||
fi | ||
# Reuse setup_and_build job with no changes | ||
setup_and_build: | ||
needs: [details] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: astral-sh/setup-uv@v3 | ||
with: | ||
version: "0.4.29" | ||
enable-cache: true | ||
cache-dependency-glob: "uv.lock" | ||
- run: uv python install 3.12 | ||
- run: uv build | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: dist | ||
path: dist/ | ||
|
||
# Reuse existing test workflows | ||
tests-pass: | ||
needs: [details] | ||
uses: ./.github/workflows/test.yml | ||
|
||
# Modified to publish to TestPyPI | ||
testpypi_publish: | ||
name: Upload release to TestPyPI | ||
needs: [setup_and_build, details, tests-pass] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: dist | ||
path: dist/ | ||
- uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
repository-url: https://test.pypi.org/legacy/ | ||
|
||
testpypi_install: | ||
name: Install from TestPyPI | ||
needs: [testpypi_publish, details] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
- name: Install cityseg from TestPyPI | ||
uses: nick-fields/retry@v3 | ||
with: | ||
timeout_minutes: 5 | ||
max_attempts: 3 | ||
retry_wait_seconds: 30 | ||
command: python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ "cityseg==${{ needs.details.outputs.version_str }}" | ||
- run: python -c "import cityseg; print(cityseg.__version__)" |
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,46 @@ | ||
name: Test | ||
|
||
on: | ||
workflow_call: | ||
outputs: | ||
tests-pass: | ||
description: "Indicates if all tests passed" | ||
value: ${{ github.event.inputs.tests-pass }} | ||
push: | ||
branches: [ main, dev ] | ||
pull_request: | ||
branches: [ main, dev ] | ||
|
||
jobs: | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.10', '3.11', '3.12'] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install uv | ||
uses: astral-sh/setup-uv@v3 | ||
with: | ||
# install a specific version of uv | ||
version: "0.4.29" | ||
enable-cache: true | ||
cache-dependency-glob: "uv.lock" | ||
|
||
- name: Setup Python ${{ matrix.python-version }} | ||
run: uv python install ${{ matrix.python-version }} | ||
|
||
- name: Lint and format check # Run linting before wasting time on testing | ||
run: | | ||
uvx ruff check . | ||
uvx ruff format --check | ||
- name: Install optional dependencies | ||
run: uv sync --all-extras | ||
|
||
- name: Run tests for all dependencies | ||
run: uv run pytest |
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 |
---|---|---|
|
@@ -23,3 +23,6 @@ src/.DS_Store | |
scripts/ | ||
|
||
/.vscode/settings.json | ||
|
||
*.hdf5 | ||
.coverage |
Oops, something went wrong.