update VERSION #124
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: Build and Deploy Package | |
on: | |
push: | |
paths: | |
- src/mrpro/VERSION | |
jobs: | |
build-testpypi-package: | |
name: Build Package for TestPyPI | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.set_suffix.outputs.version }} | |
suffix: ${{ steps.set_suffix.outputs.suffix }} | |
version_changed: ${{ steps.changes.outputs.version_changed }} | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Check if VERSION file is modified compared to main | |
uses: dorny/paths-filter@v3 | |
id: changes | |
with: | |
base: main | |
filters: | | |
version_changed: | |
- 'src/mrpro/VERSION' | |
- name: Set Version Suffix | |
id: set_suffix | |
run: | | |
VERSION=$(cat src/mrpro/VERSION) | |
SUFFIX=rc$(date +%s) | |
echo "MRPROVERSIONSUFFIX=$SUFFIX" >> $GITHUB_ENV | |
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Build Package | |
run: | | |
python -m pip install --upgrade build | |
python -m build | |
- name: Upload TestPyPI Distribution Artifact | |
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 | |
if: needs.build-testpypi-package.outputs.version_changed == 'true' | |
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 | |
- build-testpypi-package | |
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: | | |
VERSION=${{ needs.build-testpypi-package.outputs.version }} | |
SUFFIX=${{ needs.build-testpypi-package.outputs.suffix }} | |
for i in {1..3}; do | |
if python -m pip install mrpro==$VERSION$SUFFIX --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/; then | |
echo "Package installed successfully." | |
break | |
else | |
echo "Attempt $i failed. Retrying in 10 seconds..." | |
sleep 10 | |
fi | |
done | |
build-pypi-package: | |
name: Build Package for PyPI | |
runs-on: ubuntu-latest | |
needs: | |
- test-install-from-testpypi | |
outputs: | |
version: ${{ steps.get_version.outputs.version }} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Install Automatic Versioning Tool | |
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_OUTPUT | |
- 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@v7 | |
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@v7 | |
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 | |
with: | |
repository-url: https://upload.pypi.org/legacy/ | |
verbose: true | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
# Cancel in-progress runs when a new workflow with the same group name is triggered | |
cancel-in-progress: true |