Skip to content

Commit cc5585f

Browse files
committed
Security improvements to workflow.
Refer to actions using the hash and not the tag that can be moved. Also limit permissions to read-only.
1 parent 1d3e915 commit cc5585f

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

.github/workflows/main.yml

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ on:
1313
# run testing on the first of each month 5am ET / 9am UTC
1414
- cron: '0 9 1 * *'
1515

16+
# Set minimal permissions for all jobs (read-only)
17+
permissions:
18+
contents: read
19+
actions: read
20+
1621
jobs:
1722
R-build:
1823
strategy:
@@ -22,17 +27,15 @@ jobs:
2227
os: [ 'macos-15-intel', 'ubuntu-latest', 'windows-latest']
2328
runs-on: ${{ matrix.os }}
2429
name: ${{ matrix.R }} ${{ matrix.os }} build
25-
env:
26-
R_LIBS: ${{ github.workspace }}/Rlibs
2730

2831
steps:
29-
- uses: actions/checkout@v6
32+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3033
with:
3134
fetch-depth: 0
3235
ref: ${{ github.event.pull_request.head.sha }}
3336

34-
- name: Setup R
35-
uses: r-lib/actions/setup-r@v2
37+
- name: Setup R (also sets the R_LIBS_USER environment variable)
38+
uses: r-lib/actions/setup-r@a51a8012b0aab7c32ef9d19bf54da93f3254335e # v2.12.0
3639
with:
3740
r-version: ${{ matrix.R }}
3841
- name: System Dependencies
@@ -44,7 +47,6 @@ jobs:
4447
- name: Configuration Information
4548
shell: bash
4649
run: |
47-
mkdir -p "$R_LIBS"
4850
cmake --version
4951
if [[ "$RUNNER_OS" == "Windows" ]]; then
5052
ls -d /c/rtools* 2>/dev/null || echo "No rtools found in /c/"
@@ -58,42 +60,45 @@ jobs:
5860
- name: Install R packages
5961
shell: bash
6062
run: |
61-
R -e "install.packages(c('remotes', 'pkgbuild'), lib=Sys.getenv('R_LIBS'), repos='https://cloud.r-project.org/')"
63+
R -e "install.packages(c('remotes'), lib=Sys.getenv('R_LIBS_USER'), repos='https://cloud.r-project.org/')"
6264
- name: Build and test
6365
shell: bash
6466
env:
6567
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS: 2
6668
run: |
67-
R -e "Sys.setenv(MAKEJ=2); remotes::install_git(c('.'), lib=Sys.getenv('R_LIBS'))"
69+
R -e "Sys.setenv(MAKEJ=2); remotes::install_git(c('.'), lib=Sys.getenv('R_LIBS_USER'))"
6870
R -e "library(SimpleITK); Version()"
6971
- name: Create binary package from installed package
7072
id: create_package
7173
shell: bash
7274
run: |
7375
# Get the R version for naming
74-
R_VERSION="${{ matrix.R }}"
75-
R_VERSION_SHORT=$(echo $R_VERSION | cut -d'.' -f1,2)
76+
R_VERSION_SHORT=$(echo "${{ matrix.R }}" | cut -d'.' -f1,2)
77+
78+
# Get package version from DESCRIPTION
79+
PKG_VERSION=$(Rscript -e "cat(read.dcf(file.path(Sys.getenv('R_LIBS_USER'), 'SimpleITK', 'DESCRIPTION'), 'Version')[1])")
80+
7681
# Create output directory for artifacts
7782
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
83+
84+
# Create binary package archive from installed package (no recompilation)
85+
cd "${R_LIBS_USER}"
8286
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"
87+
PKG_NAME="SimpleITK_${PKG_VERSION}_R${R_VERSION_SHORT}_macos-x86_64.tgz"
88+
tar czf "${GITHUB_WORKSPACE}/artifacts/${PKG_NAME}" SimpleITK
8589
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"
90+
PKG_NAME="SimpleITK_${PKG_VERSION}_R${R_VERSION_SHORT}_linux-x86_64.tar.gz"
91+
tar czf "${GITHUB_WORKSPACE}/artifacts/${PKG_NAME}" SimpleITK
8892
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"
93+
PKG_NAME="SimpleITK_${PKG_VERSION}_R${R_VERSION_SHORT}_windows-x86_64.zip"
94+
7z a -tzip "${GITHUB_WORKSPACE}/artifacts/${PKG_NAME}" SimpleITK
9195
fi
92-
mv "$PKG_FILE" "$NEW_NAME"
96+
97+
cd "${GITHUB_WORKSPACE}"
9398
ls -lh artifacts/
9499
- name: Upload binary package
95100
if: steps.create_package.outcome == 'success'
96-
uses: actions/upload-artifact@v4
101+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
97102
with:
98103
name: SimpleITK-${{ matrix.R }}-${{ matrix.os }}
99104
path: artifacts/*
@@ -111,7 +116,7 @@ jobs:
111116

112117
steps:
113118
- name: Checkout repository
114-
uses: actions/checkout@v6
119+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
115120
with:
116121
fetch-depth: 1
117122

@@ -130,7 +135,7 @@ jobs:
130135
131136
- name: Download all artifacts
132137
if: steps.verify_tag.outputs.draft_release == 'true'
133-
uses: actions/download-artifact@v4
138+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
134139
with:
135140
path: release-artifacts
136141
pattern: SimpleITK-*
@@ -146,7 +151,7 @@ jobs:
146151
# or updates it if it does.
147152
- name: Create or Update Draft Release
148153
if: steps.verify_tag.outputs.draft_release == 'true'
149-
uses: softprops/action-gh-release@v2
154+
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
150155
env:
151156
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152157
with:

0 commit comments

Comments
 (0)