Update dcmqi #7
This file contains hidden or 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: Update dcmqi | |
| on: | |
| schedule: | |
| - cron: "0 9 * * 1" # Every Monday at 9am UTC | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| check-update: | |
| name: Check for new dcmqi release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Check for update and open PR | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| # Get current version from dcmqiUrls.cmake | |
| current_version=$(grep 'set(version' dcmqiUrls.cmake | sed 's/set(version "\(.*\)")/\1/') | |
| echo "Current version: $current_version" | |
| # Get latest upstream release (skip drafts and prereleases) | |
| latest_tag=$(gh api repos/QIICR/dcmqi/releases/latest --jq '.tag_name') | |
| latest_version="${latest_tag#v}" | |
| echo "Latest upstream version: $latest_version" | |
| if [ "$current_version" = "$latest_version" ]; then | |
| echo "Already up-to-date at v$current_version" | |
| exit 0 | |
| fi | |
| echo "Update available: v$current_version -> v$latest_version" | |
| # Check if a PR already exists for this version | |
| existing_pr=$(gh pr list --search "dcmqi v$latest_version" --json number --jq '.[0].number // empty') | |
| if [ -n "$existing_pr" ]; then | |
| echo "PR #$existing_pr already exists for v$latest_version" | |
| exit 0 | |
| fi | |
| # Get asset list | |
| assets=$(gh api "repos/QIICR/dcmqi/releases/tags/$latest_tag" --jq '.assets[].name') | |
| echo "Assets: $assets" | |
| # Download assets and compute checksums | |
| # Also extract binary names from one archive (Linux) | |
| declare -A checksums | |
| binaries="" | |
| for asset in $assets; do | |
| echo "Downloading $asset..." | |
| url="https://github.com/QIICR/dcmqi/releases/download/$latest_tag/$asset" | |
| tmpfile=$(mktemp) | |
| curl -sL "$url" -o "$tmpfile" | |
| sha256=$(sha256sum "$tmpfile" | awk '{print $1}') | |
| checksums["$asset"]="$sha256" | |
| echo " SHA256: $sha256" | |
| # Discover binaries from the Linux archive | |
| if [[ "$asset" == *-linux.tar.gz ]] && [ -z "$binaries" ]; then | |
| echo "Discovering binaries from $asset..." | |
| binaries=$(tar -tzf "$tmpfile" | grep '^[^/]*/bin/[^/]*$' | grep -v '/$' | sed 's|.*/bin/||' | sort) | |
| echo " Discovered binaries: $(echo $binaries | tr '\n' ' ')" | |
| fi | |
| rm -f "$tmpfile" | |
| done | |
| if [ -z "$binaries" ]; then | |
| echo "ERROR: Could not discover binaries from Linux archive" | |
| exit 1 | |
| fi | |
| # Determine macOS asset pattern | |
| has_mac_split=false | |
| for asset in $assets; do | |
| case "$asset" in | |
| *-mac-arm64*) has_mac_split=true ;; | |
| esac | |
| done | |
| # Generate dcmqiUrls.cmake | |
| { | |
| echo '# Checksums computed from assets associated with the dcmqi GitHub release' | |
| echo '' | |
| echo "set(version \"$latest_version\")" | |
| echo '' | |
| # Linux | |
| linux_file="dcmqi-${latest_version}-linux.tar.gz" | |
| echo "set(linux_filename \"$linux_file\")" | |
| echo "set(linux_sha256 \"${checksums[$linux_file]}\")" | |
| echo '' | |
| # macOS | |
| if [ "$has_mac_split" = true ]; then | |
| mac_arm64_file="dcmqi-${latest_version}-mac-arm64.tar.gz" | |
| mac_x86_64_file="dcmqi-${latest_version}-mac-x86_64.tar.gz" | |
| echo "set(macos_arm64_filename \"$mac_arm64_file\")" | |
| echo "set(macos_arm64_sha256 \"${checksums[$mac_arm64_file]}\")" | |
| echo '' | |
| echo "set(macos_x86_64_filename \"$mac_x86_64_file\")" | |
| echo "set(macos_x86_64_sha256 \"${checksums[$mac_x86_64_file]}\")" | |
| else | |
| mac_file="dcmqi-${latest_version}-mac.tar.gz" | |
| echo "set(macos_filename \"$mac_file\")" | |
| echo "set(macos_sha256 \"${checksums[$mac_file]}\")" | |
| fi | |
| echo '' | |
| # Windows | |
| win_file="dcmqi-${latest_version}-win64.zip" | |
| echo "set(win64_filename \"$win_file\")" | |
| echo "set(win64_sha256 \"${checksums[$win_file]}\")" | |
| echo '' | |
| echo '' | |
| # Platform detection | |
| echo 'cmake_host_system_information(RESULT is_64bit QUERY IS_64BIT)' | |
| echo '' | |
| echo 'set(archive "linux")' | |
| echo '' | |
| echo 'if(APPLE)' | |
| if [ "$has_mac_split" = true ]; then | |
| echo ' if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")' | |
| echo ' set(archive "macos_arm64")' | |
| echo ' else()' | |
| echo ' set(archive "macos_x86_64")' | |
| echo ' endif()' | |
| else | |
| echo ' set(archive "macos")' | |
| fi | |
| echo 'endif()' | |
| echo '' | |
| echo 'if(WIN32)' | |
| echo ' if(is_64bit AND NOT (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ARM64"))' | |
| echo ' set(archive "win64")' | |
| echo ' endif()' | |
| echo 'endif()' | |
| echo '' | |
| echo 'if(NOT DEFINED "${archive}_filename")' | |
| echo ' message(FATAL_ERROR "Failed to determine which archive to download: '"'"'${archive}_filename'"'"' variable is not defined")' | |
| echo 'endif()' | |
| echo '' | |
| echo 'if(NOT DEFINED "${archive}_sha256")' | |
| echo ' message(FATAL_ERROR "Could you make sure variable '"'"'${archive}_sha256'"'"' is defined ?")' | |
| echo 'endif()' | |
| echo '' | |
| echo 'set(dcmqi_archive_filename "${${archive}_filename}")' | |
| echo 'set(dcmqi_archive_sha256 "${${archive}_sha256}")' | |
| echo '' | |
| echo 'set(dcmqi_archive_url "https://github.com/QIICR/dcmqi/releases/download/v${version}/${dcmqi_archive_filename}")' | |
| } > dcmqiUrls.cmake | |
| # Update binaries.txt with discovered binary list | |
| echo "$binaries" > binaries.txt | |
| # Update pyproject.toml [project.scripts] to match binaries.txt | |
| python3 -c 'import re; b=open("binaries.txt").read().split(); blk="[project.scripts]\n"+"".join(f"{x} = \"dcmqi:{x}\"\n" for x in b)+"\n"; c=open("pyproject.toml").read(); open("pyproject.toml","w").write(re.sub(r"\[project\.scripts\]\n[^\[]*\n",blk,c))' | |
| # Update README.md to reference the new dcmqi release version | |
| sed -i "s|dcmqi v${current_version}](https://github.com/QIICR/dcmqi/releases/tag/v${current_version})|dcmqi v${latest_version}](https://github.com/QIICR/dcmqi/releases/tag/v${latest_version})|" README.md | |
| # Configure git and create branch | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| branch="dcmqi-v${latest_version}" | |
| git checkout -b "$branch" | |
| git add dcmqiUrls.cmake binaries.txt pyproject.toml README.md | |
| git commit -m "feat: update dcmqi from version v$current_version to v$latest_version" | |
| git push origin "$branch" | |
| gh pr create \ | |
| --title "feat: update dcmqi from v$current_version to v$latest_version" \ | |
| --body "## Summary | |
| - Updates packaged dcmqi binaries from v$current_version to v$latest_version | |
| - SHA256 checksums computed from downloaded release assets | |
| **Upstream release:** https://github.com/QIICR/dcmqi/releases/tag/$latest_tag | |
| --- | |
| *This PR was automatically created by the update-dcmqi workflow.*" |