Repository navigation
python-publish #16
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
| name: python-publish | |
| on: | |
| schedule: | |
| - cron: '17 8 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| channel: | |
| description: Package channel to publish | |
| required: true | |
| default: nightly | |
| type: choice | |
| options: | |
| - nightly | |
| - stable | |
| concurrency: | |
| group: python-publish-${{ inputs.channel || 'nightly' }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| env: | |
| NIGHTLY_VERSION: 0.3.0 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| channel: ${{ steps.version.outputs.channel }} | |
| version: ${{ steps.version.outputs.version }} | |
| commit: ${{ steps.version.outputs.commit }} | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| with: | |
| persist-credentials: false | |
| - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 | |
| with: | |
| python-version: '3.12' | |
| - name: Select the publication version | |
| id: version | |
| env: | |
| DISPATCH_CHANNEL: ${{ inputs.channel }} | |
| run: | | |
| commit="$(git rev-parse --short=12 HEAD)" | |
| source_version="$(python -c 'import cmax; print(cmax.__version__)')" | |
| channel="${DISPATCH_CHANNEL:-nightly}" | |
| case "$channel" in | |
| stable) | |
| version="$source_version" | |
| ;; | |
| nightly) | |
| date_utc="$(date -u +%Y%m%d)" | |
| version="$(python .github/scripts/nightly_version.py \ | |
| --release-version "$NIGHTLY_VERSION" \ | |
| --date "$date_utc" \ | |
| --run-number "$GITHUB_RUN_NUMBER")" | |
| ;; | |
| *) | |
| echo "Unknown publication channel: $channel" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| echo "channel=$channel" >> "$GITHUB_OUTPUT" | |
| echo "commit=$commit" >> "$GITHUB_OUTPUT" | |
| echo "source_version=$source_version" >> "$GITHUB_OUTPUT" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "### ClusterMAX publication" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Channel: \`$channel\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Version: \`$version\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Commit: \`$commit\`" >> "$GITHUB_STEP_SUMMARY" | |
| - name: Build the distributions | |
| env: | |
| CLUSTERMAX_BUILD_VERSION: ${{ steps.version.outputs.version }} | |
| SOURCE_VERSION: ${{ steps.version.outputs.source_version }} | |
| run: | | |
| python -m pip install \ | |
| --require-hashes \ | |
| --only-binary=:all: \ | |
| --disable-pip-version-check \ | |
| -r .github/requirements/release.txt | |
| python -m build --no-isolation | |
| python -m twine check dist/* | |
| check-wheel-contents dist/clustermax-*.whl | |
| test "$(python -c 'import cmax; print(cmax.__version__)')" = "$SOURCE_VERSION" | |
| - name: Verify the wheel | |
| env: | |
| EXPECTED_VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| python -m venv /tmp/clustermax-publication | |
| /tmp/clustermax-publication/bin/pip install dist/clustermax-*.whl | |
| cd /tmp | |
| test "$(/tmp/clustermax-publication/bin/cmax --version)" = "cmax ${EXPECTED_VERSION}" | |
| /tmp/clustermax-publication/bin/cmax audit --show | |
| /tmp/clustermax-publication/bin/cmax audit security --show | |
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: clustermax-${{ steps.version.outputs.version }}-${{ steps.version.outputs.commit }} | |
| path: dist/ | |
| if-no-files-found: error | |
| retention-days: 14 | |
| publish: | |
| if: github.repository == 'SemiAnalysisAI/ClusterMAX' && github.ref == 'refs/heads/master' | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: ${{ needs.build.outputs.channel == 'nightly' && 'pypi-nightly' || 'pypi' }} | |
| url: https://pypi.org/project/clustermax/ | |
| permissions: | |
| id-token: write | |
| steps: | |
| - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: clustermax-${{ needs.build.outputs.version }}-${{ needs.build.outputs.commit }} | |
| path: dist/ | |
| - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1 | |
| with: | |
| packages-dir: dist/ |