|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: # Manual trigger for testing builds |
| 8 | + inputs: |
| 9 | + dry_run: |
| 10 | + description: "Dry run (build only, skip publish)" |
| 11 | + type: boolean |
| 12 | + default: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build Package |
| 17 | + if: github.repository == 'dnv-opensource/solarfarmer-python-sdk' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Install uv |
| 23 | + uses: astral-sh/setup-uv@v4 |
| 24 | + with: |
| 25 | + enable-cache: true |
| 26 | + cache-dependency-glob: "pyproject.toml" |
| 27 | + |
| 28 | + - name: Verify tag matches pyproject.toml version |
| 29 | + if: github.event_name == 'push' |
| 30 | + run: | |
| 31 | + TAG_VERSION=${GITHUB_REF#refs/tags/v} |
| 32 | + PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') |
| 33 | + echo "Tag version: $TAG_VERSION" |
| 34 | + echo "pyproject version: $PYPROJECT_VERSION" |
| 35 | + if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then |
| 36 | + echo "ERROR: git tag v${TAG_VERSION} does not match pyproject.toml version ${PYPROJECT_VERSION}." |
| 37 | + echo "Bump the version in pyproject.toml and commit before tagging." |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + - name: Build package |
| 42 | + run: uv build --sdist --wheel --out-dir dist/ |
| 43 | + |
| 44 | + - name: List distribution file sizes |
| 45 | + run: du -h dist/* |
| 46 | + |
| 47 | + - name: Check distribution metadata |
| 48 | + run: uv run --with twine twine check --strict dist/* |
| 49 | + |
| 50 | + - name: Install wheel into isolated directory |
| 51 | + run: | |
| 52 | + mkdir ./tmp_install |
| 53 | + uv pip install --target=./tmp_install $(find dist -type f -name "*.whl" | head -1) |
| 54 | +
|
| 55 | + - name: Verify package imports and list installed sizes |
| 56 | + run: | |
| 57 | + PYTHONPATH=./tmp_install uv run python -c "import solarfarmer; print(solarfarmer.__version__)" |
| 58 | + du -h solarfarmer |
| 59 | + working-directory: ./tmp_install |
| 60 | + |
| 61 | + - name: Upload artifacts |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: dist |
| 65 | + path: dist/ |
| 66 | + if-no-files-found: error |
| 67 | + |
| 68 | + publish-pypi: |
| 69 | + name: Publish to PyPI |
| 70 | + needs: build |
| 71 | + runs-on: ubuntu-latest |
| 72 | + if: github.event_name == 'push' && !inputs.dry_run |
| 73 | + environment: |
| 74 | + name: pypi |
| 75 | + url: https://pypi.org/p/dnv-solarfarmer |
| 76 | + permissions: |
| 77 | + id-token: write |
| 78 | + steps: |
| 79 | + - uses: actions/download-artifact@v4 |
| 80 | + with: |
| 81 | + name: dist |
| 82 | + path: dist/ |
| 83 | + |
| 84 | + - name: Publish to PyPI |
| 85 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments