Skip to content

Commit 1d3e915

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 1d3e915

1 file changed

Lines changed: 96 additions & 1 deletion

File tree

.github/workflows/main.yml

Lines changed: 96 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,103 @@ 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+
- 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

Comments
 (0)