Skip to content

Commit e1d88c7

Browse files
committed
Binary distributions via GitHub Releases.
For all triggering events, the workflow builds SimpleITK using the installer, creates binary packages from the results and uploads the artifacts to GitHub. When the triggering event is a tag push that matches the SITK_TARGET (DESCRIPTION file) a draft release is created and the packages are uploaded to it.
1 parent 069e241 commit e1d88c7

1 file changed

Lines changed: 99 additions & 1 deletion

File tree

.github/workflows/main.yml

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ on:
22
push:
33
branches:
44
- main
5+
tags:
6+
- 'v*' # Trigger on version tags
57
pull_request:
68
branches:
79
- main
@@ -28,6 +30,7 @@ jobs:
2830
with:
2931
fetch-depth: 0
3032
ref: ${{ github.event.pull_request.head.sha }}
33+
3134
- name: Setup R
3235
uses: r-lib/actions/setup-r@v2
3336
with:
@@ -55,11 +58,106 @@ jobs:
5558
- name: Install R packages
5659
shell: bash
5760
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/')"
5962
- name: Build and test
6063
shell: bash
6164
env:
6265
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS: 2
6366
run: |
6467
R -e "Sys.setenv(MAKEJ=2); remotes::install_git(c('.'), lib=Sys.getenv('R_LIBS'))"
6568
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+
95+
# Export PKG_NAME as output for use in upload step
96+
echo "pkg_name=${PKG_NAME}" >> $GITHUB_OUTPUT
97+
- name: Upload binary package
98+
if: steps.create_package.outcome == 'success'
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: ${{ steps.create_package.outputs.pkg_name }}
102+
path: artifacts/*
103+
retention-days: 30
104+
105+
create-release:
106+
name: Create GitHub Draft Release
107+
# Only run this job for tag pushes after the R-build job completes
108+
# successfully.
109+
if: startsWith(github.ref, 'refs/tags/v')
110+
needs: R-build
111+
runs-on: ubuntu-latest
112+
permissions:
113+
contents: write
114+
115+
steps:
116+
- name: Checkout repository
117+
uses: actions/checkout@v6
118+
with:
119+
fetch-depth: 1
120+
121+
- name: Verify tag matches SITK_TARGET
122+
id: verify_tag
123+
run: |
124+
SITK_TARGET=$(grep '^SITK_TARGET:' DESCRIPTION | awk '{print $2}')
125+
TAG_NAME="${{ github.ref_name }}"
126+
if [ "${TAG_NAME}" != "${SITK_TARGET}" ]; then
127+
echo "Tag ${TAG_NAME} does not match SITK_TARGET ${SITK_TARGET}"
128+
echo "Skipping draft release creation."
129+
echo "draft_release=false" >> $GITHUB_OUTPUT
130+
else
131+
echo "draft_release=true" >> $GITHUB_OUTPUT
132+
fi
133+
134+
- name: Download all artifacts
135+
if: steps.verify_tag.outputs.draft_release == 'true'
136+
uses: actions/download-artifact@v4
137+
with:
138+
path: release-artifacts
139+
pattern: SimpleITK_*
140+
merge-multiple: true
141+
142+
- name: Display downloaded artifacts
143+
if: steps.verify_tag.outputs.draft_release == 'true'
144+
run: |
145+
echo "Downloaded artifacts:"
146+
ls -lhR release-artifacts/
147+
148+
# This action automatically creates the release if it doesn't exist,
149+
# or updates it if it does.
150+
- name: Create or Update Draft Release
151+
if: steps.verify_tag.outputs.draft_release == 'true'
152+
uses: softprops/action-gh-release@v2
153+
env:
154+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
with:
156+
draft: true
157+
name: SimpleITK ${{ github.ref_name }} R Package Release
158+
body: |
159+
Please review and test the packages before publishing this release.
160+
Then remove the "Draft" status to make it public and delete this message.
161+
files: |
162+
release-artifacts/*
163+
fail_on_unmatched_files: true

0 commit comments

Comments
 (0)