|
2 | 2 | push: |
3 | 3 | branches: |
4 | 4 | - main |
| 5 | + tags: |
| 6 | + - 'v*' # Trigger on version tags |
5 | 7 | pull_request: |
6 | 8 | branches: |
7 | 9 | - main |
|
28 | 30 | with: |
29 | 31 | fetch-depth: 0 |
30 | 32 | ref: ${{ github.event.pull_request.head.sha }} |
| 33 | + |
31 | 34 | - name: Setup R |
32 | 35 | uses: r-lib/actions/setup-r@v2 |
33 | 36 | with: |
@@ -55,11 +58,103 @@ jobs: |
55 | 58 | - name: Install R packages |
56 | 59 | shell: bash |
57 | 60 | run: | |
58 | | - R -e "install.packages(c('remotes'), lib=Sys.getenv('R_LIBS'), repos='https://cloud.r-project.org/')" |
| 61 | + R -e "install.packages(c('remotes', 'pkgbuild'), lib=Sys.getenv('R_LIBS'), repos='https://cloud.r-project.org/')" |
59 | 62 | - name: Build and test |
60 | 63 | shell: bash |
61 | 64 | env: |
62 | 65 | ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS: 2 |
63 | 66 | run: | |
64 | 67 | R -e "Sys.setenv(MAKEJ=2); remotes::install_git(c('.'), lib=Sys.getenv('R_LIBS'))" |
65 | 68 | R -e "library(SimpleITK); Version()" |
| 69 | + - name: Create binary package from installed package |
| 70 | + id: create_package |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + # Get the R version for naming |
| 74 | + R_VERSION="${{ matrix.R }}" |
| 75 | + R_VERSION_SHORT=$(echo $R_VERSION | cut -d'.' -f1,2) |
| 76 | + # Create output directory for artifacts |
| 77 | + mkdir -p artifacts |
| 78 | + # Build binary package from the installed package (no recompilation needed) |
| 79 | + # The configure script already built everything and remotes::install_git installed it |
| 80 | + R -e "pkg <- file.path(Sys.getenv('R_LIBS'), 'SimpleITK'); pkgbuild::build(pkg, dest_path='artifacts', binary=TRUE)" |
| 81 | + # Rename with descriptive platform info |
| 82 | + if [[ "$RUNNER_OS" == "macOS" ]]; then |
| 83 | + PKG_FILE=$(ls artifacts/SimpleITK_*.tgz) |
| 84 | + NEW_NAME="${PKG_FILE%.tgz}_R${R_VERSION_SHORT}_macos-x86_64.tgz" |
| 85 | + elif [[ "$RUNNER_OS" == "Linux" ]]; then |
| 86 | + PKG_FILE=$(ls artifacts/SimpleITK_*.tar.gz) |
| 87 | + NEW_NAME="${PKG_FILE%.tar.gz}_R${R_VERSION_SHORT}_linux-x86_64.tar.gz" |
| 88 | + elif [[ "$RUNNER_OS" == "Windows" ]]; then |
| 89 | + PKG_FILE=$(ls artifacts/SimpleITK_*.zip) |
| 90 | + NEW_NAME="${PKG_FILE%.zip}_R${R_VERSION_SHORT}_windows-x86_64.zip" |
| 91 | + fi |
| 92 | + mv "$PKG_FILE" "$NEW_NAME" |
| 93 | + ls -lh artifacts/ |
| 94 | + - name: Upload binary package |
| 95 | + if: steps.create_package.outcome == 'success' |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: SimpleITK-${{ matrix.R }}-${{ matrix.os }} |
| 99 | + path: artifacts/* |
| 100 | + retention-days: 30 |
| 101 | + |
| 102 | + create-release: |
| 103 | + name: Create GitHub Draft Release |
| 104 | + # Only run this job for tag pushes after the R-build job completes |
| 105 | + # successfully. |
| 106 | + if: startsWith(github.ref, 'refs/tags/v') |
| 107 | + needs: R-build |
| 108 | + runs-on: ubuntu-latest |
| 109 | + permissions: |
| 110 | + contents: write |
| 111 | + |
| 112 | + steps: |
| 113 | + - name: Checkout repository |
| 114 | + uses: actions/checkout@v6 |
| 115 | + with: |
| 116 | + fetch-depth: 1 |
| 117 | + |
| 118 | + - name: Verify tag matches SITK_TARGET |
| 119 | + id: verify_tag |
| 120 | + run: | |
| 121 | + SITK_TARGET=$(grep '^SITK_TARGET:' DESCRIPTION | awk '{print $2}') |
| 122 | + TAG_NAME="${{ github.ref_name }}" |
| 123 | + if [ "${TAG_NAME}" != "${SITK_TARGET}" ]; then |
| 124 | + echo "Tag ${TAG_NAME} does not match SITK_TARGET ${SITK_TARGET}" |
| 125 | + echo "Skipping draft release creation." |
| 126 | + echo "draft_release=false" >> $GITHUB_OUTPUT |
| 127 | + else |
| 128 | + echo "draft_release=true" >> $GITHUB_OUTPUT |
| 129 | + fi |
| 130 | +
|
| 131 | + - name: Download all artifacts |
| 132 | + if: steps.verify_tag.outputs.draft_release == 'true' |
| 133 | + uses: actions/download-artifact@v4 |
| 134 | + with: |
| 135 | + path: release-artifacts |
| 136 | + pattern: SimpleITK-* |
| 137 | + merge-multiple: true |
| 138 | + |
| 139 | + - name: Display downloaded artifacts |
| 140 | + if: steps.verify_tag.outputs.draft_release == 'true' |
| 141 | + run: | |
| 142 | + echo "Downloaded artifacts:" |
| 143 | + ls -lhR release-artifacts/ |
| 144 | +
|
| 145 | + # This action automatically creates the release if it doesn't exist, |
| 146 | + # or updates it if it does. |
| 147 | + - name: Create or Update Draft Release |
| 148 | + if: steps.verify_tag.outputs.draft_release == 'true' |
| 149 | + uses: softprops/action-gh-release@v2 |
| 150 | + env: |
| 151 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 152 | + with: |
| 153 | + draft: true |
| 154 | + name: SimpleITK ${{ github.ref_name }} R Package Release |
| 155 | + body: | |
| 156 | + Please review and test the packages before publishing this release. |
| 157 | + Then remove the "Draft" status to make it public and delete this message. |
| 158 | + files: | |
| 159 | + release-artifacts/* |
| 160 | + fail_on_unmatched_files: true |
0 commit comments