Skip to content

Commit e6100a0

Browse files
committed
add versioning
1 parent fa92c1c commit e6100a0

File tree

6 files changed

+99
-16
lines changed

6 files changed

+99
-16
lines changed

.github/workflows/checks.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: Python checks
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- main
7+
- 'release-*'
68
pull_request:
7-
branches: [main]
9+
branches:
10+
- main
11+
- 'release-*'
812

913
jobs:
1014
ruff:

.github/workflows/release.yml

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,65 @@ on:
44
push:
55
branches:
66
- main
7+
- 'release-*'
78

89
permissions:
910
contents: write
1011
packages: write
1112

1213
jobs:
14+
check-version:
15+
name: Detect version
16+
runs-on: ubuntu-latest
17+
outputs:
18+
name: ${{ steps.detect.outputs.name }}
19+
description: ${{ steps.detect.outputs.description }}
20+
prerelease: ${{ steps.detect.outputs.prerelease }}
21+
steps:
22+
- name: Checkout the repository
23+
uses: actions/checkout@v4
24+
- name: Detect version and release type
25+
id: detect
26+
run: |
27+
if [[ "${{ github.ref }}" == refs/heads/main ]]; then
28+
NAME="latest"
29+
DESCRIPTION="Latest development build"
30+
PRERELEASE="true"
31+
elif [[ "${{ github.ref }}" =~ refs/heads/release-.* ]]; then
32+
VERSION="${GITHUB_REF#refs/heads/release-}"
33+
34+
# Extract package version from the pyproject file.
35+
PYPROJECT_VERSION=$(grep -E '^version = ' pyproject.toml | cut -d '"' -f 2)
36+
37+
# Check that a version has been found.
38+
if [[ -z "$PYPROJECT_VERSION" ]]; then
39+
echo "Error: No package version found in pyproject.toml"
40+
exit 1
41+
fi
42+
43+
# Compare branch and package versions.
44+
if [[ "$VERSION" != "$PYPROJECT_VERSION" ]]; then
45+
echo "Error: Version mismatch"
46+
echo "Branch version: $VERSION"
47+
echo "Package version: $PYPROJECT_VERSION"
48+
exit 1
49+
fi
50+
51+
NAME="$VERSION"
52+
DESCRIPTION="Release $VERSION"
53+
PRERELEASE="false"
54+
else
55+
echo "Error: Unsupported branch"
56+
exit 1
57+
fi
58+
59+
echo "name=$NAME" >> $GITHUB_OUTPUT
60+
echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT
61+
echo "prerelease=$PRERELEASE" >> $GITHUB_OUTPUT
62+
1363
release-executable:
1464
name: Release executable
65+
needs: check-version
1566
runs-on: ubuntu-latest
1667

1768
steps:
@@ -30,29 +81,32 @@ jobs:
3081
mkdir dist
3182
docker run --mount type=bind,src=$(pwd)/dist,dst=/mni_7t_dicom_to_bids/dist compile_mni_7t_dicom_to_bids
3283
33-
- name: Delete old latest release
84+
- name: Delete existing release
3485
run: |
35-
gh release delete latest --yes || true
86+
gh release delete "${{ needs.check-version.outputs.name }}" --yes || true
3687
env:
3788
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3889

39-
- name: Create latest release
90+
- name: Create release
4091
uses: softprops/action-gh-release@v2
4192
with:
42-
tag_name: latest
43-
name: "Latest development build"
93+
tag_name: ${{ needs.check-version.outputs.name }}
94+
name: "${{ needs.check-version.outputs.description }}"
4495
body: |
45-
**Automated development build**
96+
**${{ needs.check-version.outputs.description }}**
4697
98+
- **Version:** ${{ needs.check-version.outputs.name }}
4799
- **Commit:** ${{ github.sha }}
48100
- **Date:** ${{ github.event.head_commit.timestamp }}
101+
- **Branch:** ${{ github.ref_name }}
49102
draft: false
50-
prerelease: true
103+
prerelease: ${{ needs.check-version.outputs.prerelease }}
51104
generate_release_notes: false
52105
files: dist/mni7t_dcm2bids
53106

54107
release-image:
55108
name: Release image
109+
needs: check-version
56110
runs-on: ubuntu-latest
57111

58112
steps:
@@ -66,7 +120,7 @@ jobs:
66120
username: ${{ github.actor }}
67121
password: ${{ secrets.GITHUB_TOKEN }}
68122

69-
- name: Build Inventory Image
123+
- name: Build and push Docker image
70124
run: |
71-
docker build . --tag ghcr.io/bic-mni/mni-7t-dicom-to-bids:latest
72-
docker push ghcr.io/bic-mni/mni-7t-dicom-to-bids:latest
125+
docker build . --tag ghcr.io/bic-mni/mni-7t-dicom-to-bids:${{ needs.check-version.outputs.name }}
126+
docker push ghcr.io/bic-mni/mni-7t-dicom-to-bids:${{ needs.check-version.outputs.name }}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "mni_7t_dicom_to_bids"
7-
version = "0.0.0"
7+
version = "0.1.0"
88
readme = "README.md"
99
license = "GPL-3.0-or-later"
1010
license-files = ["LICENSE"]

src/mni_7t_dicom_to_bids/pipeline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
print_found_ignored_dicom_series,
1010
print_found_mapped_bids_acquisitions,
1111
print_found_unknown_dicom_series,
12+
print_version,
1213
)
1314

1415

1516
def mni_7t_dicom_to_bids(args: Args):
17+
print_version()
18+
1619
check_dicom_to_niix()
1720

1821
dicom_series_list = group_dicom_series(args.dicom_study_path)

src/mni_7t_dicom_to_bids/print.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from importlib.metadata import version
23
from shlex import quote
34

45
from bic_util.print import print_error_exit, print_warning
@@ -7,6 +8,22 @@
78
from mni_7t_dicom_to_bids.dataclass import DicomBidsMapping, DicomSeriesInfo
89

910

11+
def get_version() -> str:
12+
"""
13+
Get the version of the current MNI 7T DICOM to BIDS package.
14+
"""
15+
16+
return version('mni_7t_dicom_to_bids')
17+
18+
19+
def print_version():
20+
"""
21+
Print the version of the current MNI 7T DICOM to BIDS package.
22+
"""
23+
24+
print(f"Running the MNI 7T DICOM to BIDS converter version {get_version()}.")
25+
26+
1027
def print_found_dicom_series(dicom_series_list: list[DicomSeriesInfo]):
1128
"""
1229
Print the DICOM series found in the DICOM study to the user.

src/mni_7t_dicom_to_bids/scripts/run_mni7t_dcm2bids.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66

77
from mni_7t_dicom_to_bids.args import ConvertUnknownsArg, process_args
88
from mni_7t_dicom_to_bids.pipeline import mni_7t_dicom_to_bids
9+
from mni_7t_dicom_to_bids.print import get_version
910

1011

1112
def main():
12-
13-
# Parse CLI arguments
13+
# Parse CLI arguments.
1414

1515
parser = argparse.ArgumentParser(
1616
prog='mni7t_dcm2bids',
1717
description="Convert a DICOM study to BIDS using the MNI 7T conversion configuration.",
1818
)
1919

20+
parser.add_argument('--version',
21+
action='version',
22+
version=get_version(),
23+
help="Print the MNI 7T DICOM to BIDS converter version number and exit.")
24+
2025
parser.add_argument('dicom_study_path',
2126
help="Path of the input DICOM study directory.")
2227

@@ -53,7 +58,7 @@ def main():
5358
action='store_true',
5459
help="Overwrite files in the BIDS dataset if they already exist.")
5560

56-
# Process CLI arguments
61+
# Process CLI arguments.
5762

5863
args = process_args(parser.parse_args())
5964

0 commit comments

Comments
 (0)