|
| 1 | +name: Update dcmqi |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 9 * * 1" # Every Monday at 9am UTC |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + check-update: |
| 14 | + name: Check for new dcmqi release |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Check for update and open PR |
| 20 | + env: |
| 21 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + run: | |
| 23 | + set -euo pipefail |
| 24 | +
|
| 25 | + # Get current version from dcmqiUrls.cmake |
| 26 | + current_version=$(grep 'set(version' dcmqiUrls.cmake | sed 's/set(version "\(.*\)")/\1/') |
| 27 | + echo "Current version: $current_version" |
| 28 | +
|
| 29 | + # Get latest upstream release (skip drafts and prereleases) |
| 30 | + latest_tag=$(gh api repos/QIICR/dcmqi/releases/latest --jq '.tag_name') |
| 31 | + latest_version="${latest_tag#v}" |
| 32 | + echo "Latest upstream version: $latest_version" |
| 33 | +
|
| 34 | + if [ "$current_version" = "$latest_version" ]; then |
| 35 | + echo "Already up-to-date at v$current_version" |
| 36 | + exit 0 |
| 37 | + fi |
| 38 | +
|
| 39 | + echo "Update available: v$current_version -> v$latest_version" |
| 40 | +
|
| 41 | + # Check if a PR already exists for this version |
| 42 | + existing_pr=$(gh pr list --search "dcmqi v$latest_version" --json number --jq '.[0].number // empty') |
| 43 | + if [ -n "$existing_pr" ]; then |
| 44 | + echo "PR #$existing_pr already exists for v$latest_version" |
| 45 | + exit 0 |
| 46 | + fi |
| 47 | +
|
| 48 | + # Get asset list |
| 49 | + assets=$(gh api "repos/QIICR/dcmqi/releases/tags/$latest_tag" --jq '.assets[].name') |
| 50 | + echo "Assets: $assets" |
| 51 | +
|
| 52 | + # Download assets and compute checksums |
| 53 | + declare -A checksums |
| 54 | + for asset in $assets; do |
| 55 | + echo "Downloading $asset..." |
| 56 | + url="https://github.com/QIICR/dcmqi/releases/download/$latest_tag/$asset" |
| 57 | + sha256=$(curl -sL "$url" | sha256sum | awk '{print $1}') |
| 58 | + checksums["$asset"]="$sha256" |
| 59 | + echo " SHA256: $sha256" |
| 60 | + done |
| 61 | +
|
| 62 | + # Determine macOS asset pattern |
| 63 | + has_mac_split=false |
| 64 | + for asset in $assets; do |
| 65 | + case "$asset" in |
| 66 | + *-mac-arm64*) has_mac_split=true ;; |
| 67 | + esac |
| 68 | + done |
| 69 | +
|
| 70 | + # Generate dcmqiUrls.cmake |
| 71 | + { |
| 72 | + echo '# Checksums computed from assets associated with the dcmqi GitHub release' |
| 73 | + echo '' |
| 74 | + echo "set(version \"$latest_version\")" |
| 75 | + echo '' |
| 76 | +
|
| 77 | + # Linux |
| 78 | + linux_file="dcmqi-${latest_version}-linux.tar.gz" |
| 79 | + echo "set(linux_filename \"$linux_file\")" |
| 80 | + echo "set(linux_sha256 \"${checksums[$linux_file]}\")" |
| 81 | + echo '' |
| 82 | +
|
| 83 | + # macOS |
| 84 | + if [ "$has_mac_split" = true ]; then |
| 85 | + mac_arm64_file="dcmqi-${latest_version}-mac-arm64.tar.gz" |
| 86 | + mac_x86_64_file="dcmqi-${latest_version}-mac-x86_64.tar.gz" |
| 87 | + echo "set(macos_arm64_filename \"$mac_arm64_file\")" |
| 88 | + echo "set(macos_arm64_sha256 \"${checksums[$mac_arm64_file]}\")" |
| 89 | + echo '' |
| 90 | + echo "set(macos_x86_64_filename \"$mac_x86_64_file\")" |
| 91 | + echo "set(macos_x86_64_sha256 \"${checksums[$mac_x86_64_file]}\")" |
| 92 | + else |
| 93 | + mac_file="dcmqi-${latest_version}-mac.tar.gz" |
| 94 | + echo "set(macos_filename \"$mac_file\")" |
| 95 | + echo "set(macos_sha256 \"${checksums[$mac_file]}\")" |
| 96 | + fi |
| 97 | + echo '' |
| 98 | +
|
| 99 | + # Windows |
| 100 | + win_file="dcmqi-${latest_version}-win64.zip" |
| 101 | + echo "set(win64_filename \"$win_file\")" |
| 102 | + echo "set(win64_sha256 \"${checksums[$win_file]}\")" |
| 103 | + echo '' |
| 104 | + echo '' |
| 105 | +
|
| 106 | + # Platform detection |
| 107 | + echo 'cmake_host_system_information(RESULT is_64bit QUERY IS_64BIT)' |
| 108 | + echo '' |
| 109 | + echo 'set(archive "linux")' |
| 110 | + echo '' |
| 111 | + echo 'if(APPLE)' |
| 112 | + if [ "$has_mac_split" = true ]; then |
| 113 | + echo ' if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")' |
| 114 | + echo ' set(archive "macos_arm64")' |
| 115 | + echo ' else()' |
| 116 | + echo ' set(archive "macos_x86_64")' |
| 117 | + echo ' endif()' |
| 118 | + else |
| 119 | + echo ' set(archive "macos")' |
| 120 | + fi |
| 121 | + echo 'endif()' |
| 122 | + echo '' |
| 123 | + echo 'if(WIN32)' |
| 124 | + echo ' if(is_64bit AND NOT (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ARM64"))' |
| 125 | + echo ' set(archive "win64")' |
| 126 | + echo ' endif()' |
| 127 | + echo 'endif()' |
| 128 | + echo '' |
| 129 | + echo 'if(NOT DEFINED "${archive}_filename")' |
| 130 | + echo ' message(FATAL_ERROR "Failed to determine which archive to download: '"'"'${archive}_filename'"'"' variable is not defined")' |
| 131 | + echo 'endif()' |
| 132 | + echo '' |
| 133 | + echo 'if(NOT DEFINED "${archive}_sha256")' |
| 134 | + echo ' message(FATAL_ERROR "Could you make sure variable '"'"'${archive}_sha256'"'"' is defined ?")' |
| 135 | + echo 'endif()' |
| 136 | + echo '' |
| 137 | + echo 'set(dcmqi_archive_filename "${${archive}_filename}")' |
| 138 | + echo 'set(dcmqi_archive_sha256 "${${archive}_sha256}")' |
| 139 | + echo '' |
| 140 | + echo 'set(dcmqi_archive_url "https://github.com/QIICR/dcmqi/releases/download/v${version}/${dcmqi_archive_filename}")' |
| 141 | + } > dcmqiUrls.cmake |
| 142 | +
|
| 143 | + # Configure git and create branch |
| 144 | + git config user.name "github-actions[bot]" |
| 145 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 146 | +
|
| 147 | + branch="dcmqi-v${latest_version}" |
| 148 | + git checkout -b "$branch" |
| 149 | + git add dcmqiUrls.cmake |
| 150 | + git commit -m "feat: update dcmqi from version v$current_version to v$latest_version" |
| 151 | + git push origin "$branch" |
| 152 | +
|
| 153 | + gh pr create \ |
| 154 | + --title "feat: update dcmqi from v$current_version to v$latest_version" \ |
| 155 | + --body "## Summary |
| 156 | + - Updates packaged dcmqi binaries from v$current_version to v$latest_version |
| 157 | + - SHA256 checksums computed from downloaded release assets |
| 158 | +
|
| 159 | + **Upstream release:** https://github.com/QIICR/dcmqi/releases/tag/$latest_tag |
| 160 | +
|
| 161 | + --- |
| 162 | + *This PR was automatically created by the update-dcmqi workflow.*" |
0 commit comments