44 push :
55 branches :
66 - main
7+ - ' release-*'
78
89permissions :
910 contents : write
1011 packages : write
1112
1213jobs :
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 :
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 }}
0 commit comments