Skip to content

Commit 95a05ca

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 95a05ca

1 file changed

Lines changed: 29 additions & 25 deletions

File tree

.github/workflows/main.yml

Lines changed: 29 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,44 @@ 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+
# Get package version from DESCRIPTION
78+
PKG_VERSION=$(R -e "cat(read.dcf(file.path(Sys.getenv('R_LIBS_USER'), 'SimpleITK', 'DESCRIPTION'), 'Version')[1])" | tail -1)
79+
7680
# Create output directory for artifacts
7781
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+
# Create binary package archive from installed package (no recompilation)
83+
cd "$(R -e "cat(Sys.getenv('R_LIBS_USER'))" | tail -1)"
84+
8285
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"
86+
PKG_NAME="SimpleITK_${PKG_VERSION}_R${R_VERSION_SHORT}_macos-x86_64.tgz"
87+
tar czf "${GITHUB_WORKSPACE}/artifacts/${PKG_NAME}" SimpleITK
8588
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"
89+
PKG_NAME="SimpleITK_${PKG_VERSION}_R${R_VERSION_SHORT}_linux-x86_64.tar.gz"
90+
tar czf "${GITHUB_WORKSPACE}/artifacts/${PKG_NAME}" SimpleITK
8891
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"
92+
PKG_NAME="SimpleITK_${PKG_VERSION}_R${R_VERSION_SHORT}_windows-x86_64.zip"
93+
7z a -tzip "${GITHUB_WORKSPACE}/artifacts/${PKG_NAME}" SimpleITK
9194
fi
92-
mv "$PKG_FILE" "$NEW_NAME"
95+
96+
cd "${GITHUB_WORKSPACE}"
9397
ls -lh artifacts/
9498
- name: Upload binary package
9599
if: steps.create_package.outcome == 'success'
96-
uses: actions/upload-artifact@v4
100+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
97101
with:
98102
name: SimpleITK-${{ matrix.R }}-${{ matrix.os }}
99103
path: artifacts/*
@@ -111,7 +115,7 @@ jobs:
111115

112116
steps:
113117
- name: Checkout repository
114-
uses: actions/checkout@v6
118+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
115119
with:
116120
fetch-depth: 1
117121

@@ -130,7 +134,7 @@ jobs:
130134
131135
- name: Download all artifacts
132136
if: steps.verify_tag.outputs.draft_release == 'true'
133-
uses: actions/download-artifact@v4
137+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
134138
with:
135139
path: release-artifacts
136140
pattern: SimpleITK-*
@@ -146,7 +150,7 @@ jobs:
146150
# or updates it if it does.
147151
- name: Create or Update Draft Release
148152
if: steps.verify_tag.outputs.draft_release == 'true'
149-
uses: softprops/action-gh-release@v2
153+
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
150154
env:
151155
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152156
with:

0 commit comments

Comments
 (0)