Merge branch 'main' into cd_pipeline #23
Workflow file for this run
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
name: Publish to PyPI | |
on: | |
push: | |
# paths: | |
# # - src/mrpro/VERSION # only trigger if VERSION file changed | |
jobs: | |
build-testpypi-package: | |
name: Modify version and build package for TestPyPI | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Set environment variable for version suffix | |
run: echo "MRPROVERSIONSUFFIX=.pre$(date +%s)" >> $GITHUB_ENV | |
- name: Build package with version suffix | |
run: | | |
python -m pip install --upgrade build | |
python -m build | |
- name: Store TestPyPi distribution | |
uses: actions/upload-artifact@v4 | |
with: | |
name: testpypi-package-distribution | |
path: dist/ | |
testpypi-deployment: | |
name: Deploy to TestPyPI | |
needs: | |
- build-testpypi-package | |
runs-on: ubuntu-latest | |
environment: | |
name: testpypi | |
url: https://test.pypi.org/p/mrpro | |
permissions: | |
id-token: write | |
steps: | |
- name: Download TestPyPi distribution | |
uses: actions/download-artifact@v4 | |
with: | |
name: testpypi-package-distribution | |
path: dist/ | |
- name: Publish to TestPyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
verbose: true | |
test-install-from-testpypi: | |
name: Test installation from TestPyPI | |
needs: | |
- testpypi-deployment | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Install MRpro from TestPyPI | |
run: | | |
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ mrpro | |
build-pypi-package: | |
name: Build package for PyPI | |
runs-on: ubuntu-latest | |
needs: | |
- test-install-from-testpypi | |
outputs: | |
version: ${{ steps.get_version.outputs.version }} # Declare the version output | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Install setuptools_git_versioning | |
run: | | |
python -m pip install setuptools-git-versioning | |
- name: Get current version | |
id: get_version | |
run: | | |
VERSION=$(python -m setuptools_git_versioning) | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "::set-output name=version::$VERSION" | |
- name: Build package | |
run: | | |
python -m pip install --upgrade build | |
python -m build | |
- name: Store PyPi distribution | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pypi-package-distribution | |
path: dist/ | |
pypi-deployment: | |
name: Deploy to PyPI | |
needs: | |
- build-pypi-package | |
# if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/project/mrpro | |
permissions: | |
contents: write | |
id-token: write | |
steps: | |
- name: Download PyPi distribution | |
uses: actions/download-artifact@v4 | |
with: | |
name: pypi-package-distribution | |
path: dist/ | |
- name: Create tag | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/v${{ needs.build-pypi-package.outputs.version }}', | |
sha: context.sha | |
}) | |
- name: Create release | |
uses: actions/github-script@v6 | |
with: | |
github-token: "${{ secrets.GITHUB_TOKEN }}" | |
script: | | |
github.rest.repos.createRelease({ | |
draft: false, | |
generate_release_notes: true, | |
name: "v${{ needs.build-pypi-package.outputs.version }}", | |
owner: context.repo.owner, | |
prerelease: false, | |
repo: context.repo.repo, | |
tag_name: "v${{ needs.build-pypi-package.outputs.version }}", | |
}); | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
if: github.ref == 'refs/heads/main' | |
with: | |
repository-url: https://upload.pypi.org/legacy/ | |
verbose: true |