Skip to content

Commit 7061061

Browse files
committed
Harden CI build: use env for untrusted inputs, pin actions to SHA
Signed-off-by: Gary Oberbrunner <garyo@darkstarsystems.com>
1 parent 257add4 commit 7061061

1 file changed

Lines changed: 62 additions & 39 deletions

File tree

.github/workflows/build.yml

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
name: Build OpenFX libs and examples
22

3-
permissions:
4-
id-token: write
5-
contents: write
6-
actions: write
7-
83
on:
94
push:
105
pull_request:
@@ -21,6 +16,9 @@ jobs:
2116
github.event_name == 'push' ||
2217
github.event.pull_request.head.repo.full_name != github.repository
2318
runs-on: ${{ matrix.os }}
19+
permissions:
20+
contents: write # needed for release upload
21+
id-token: write # needed for sigstore
2422
container:
2523
image: ${{ matrix.container }}
2624
volumes: ${{ matrix.need_node20_vol && fromJSON('["/node20217:/node20217:rw,rshared", "/node20217:/__e/node20:ro,rshared"]') || fromJSON('[]') }}
@@ -162,30 +160,37 @@ jobs:
162160
tar -xJ --strip-components 1 -C /node20217 -f -
163161
164162
- name: Checkout code
165-
uses: actions/checkout@v4
163+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
166164
with:
167165
clean: true
168166
fetch-depth: 0
169167

170168
- name: setup env vars
169+
env:
170+
MATRIX_BUILDTYPE: ${{ matrix.buildtype }}
171+
MATRIX_OS: ${{ matrix.os }}
171172
run: |
172173
git config --global --add safe.directory $PWD # needed for checkout v3, doesn't hurt anyway
173-
BUILDTYPE_LC=$(echo '${{ matrix.buildtype }}'|tr [:upper:] [:lower:])
174+
BUILDTYPE_LC=$(echo "$MATRIX_BUILDTYPE"|tr [:upper:] [:lower:])
174175
echo "BUILDTYPE_LC=$BUILDTYPE_LC" >> $GITHUB_ENV
175-
echo "OSNAME=$(echo '${{ matrix.os }}'|sed 's/-.*//')" >> $GITHUB_ENV
176+
echo "OSNAME=$(echo "$MATRIX_OS"|sed 's/-.*//')" >> $GITHUB_ENV
176177
echo "GIT_COMMIT_ID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
177178
echo "CONAN_PRESET=conan-$BUILDTYPE_LC" >> $GITHUB_ENV
178-
echo "BUILD_DIR=build/${{ matrix.buildtype }}" >> $GITHUB_ENV
179+
echo "BUILD_DIR=build/$MATRIX_BUILDTYPE" >> $GITHUB_ENV
179180
180181
- name: Set RELEASE_NAME
181182
# this looks like "linux-vfx2022-1.5[-no-opengl]"; used in filenames
183+
env:
184+
RELEASE_PREFIX: ${{ matrix.release_prefix }}
185+
OPENGL_BUILD: ${{ env.OPENGL_BUILD }}
186+
REF_TYPE: ${{ github.ref_type }}
187+
REF_NAME: ${{ github.ref_name }}
188+
GIT_SHA: ${{ github.sha }}
182189
run: |
183-
RELEASE_PREFIX=${{ matrix.release_prefix }}
184-
OPENGL_BUILD=${{ env.OPENGL_BUILD }}
185-
if [ "${{ github.ref_type }}" == "tag" ]; then
186-
REF_SUFFIX=$(echo "${{ github.ref_name }}" | sed 's/OFX_Release_//')
190+
if [ "$REF_TYPE" == "tag" ]; then
191+
REF_SUFFIX=$(echo "$REF_NAME" | sed 's/OFX_Release_//')
187192
else
188-
REF_SUFFIX=$(echo ${{ github.sha }} | cut -c1-8)
193+
REF_SUFFIX=$(echo "$GIT_SHA" | cut -c1-8)
189194
fi
190195
echo "RELEASE_NAME=${RELEASE_PREFIX}-${REF_SUFFIX}${OPENGL_BUILD}" >> $GITHUB_ENV
191196
@@ -196,7 +201,7 @@ jobs:
196201
echo "$HOME/.local/bin" >> $GITHUB_PATH
197202
198203
- name: Set up python 3.11
199-
uses: actions/setup-python@v5
204+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
200205
if: matrix.ostype == 'mac'
201206
with:
202207
python-version: '3.11'
@@ -226,14 +231,16 @@ jobs:
226231
# The get-conan action doesn't know about uv Python and would use system Python
227232
- name: Install Conan manually (CentOS 7)
228233
if: matrix.vfx-cy == 2021 || matrix.vfx-cy == 2022
234+
env:
235+
CONAN_VERSION: ${{ matrix.conan_version }}
229236
run: |
230-
python3.11 -m pip install --user conan==${{ matrix.conan_version }}
237+
python3.11 -m pip install --user conan==$CONAN_VERSION
231238
232239
# Use get-conan action for other platforms
233240
- name: Install Conan
234241
id: conan
235242
if: matrix.vfx-cy != 2021 && matrix.vfx-cy != 2022
236-
uses: turtlebrowser/get-conan@main
243+
uses: turtlebrowser/get-conan@e41c1e039be765c0ed9d9d38cc2a287566e1d8b3 # main 2025-03-04
237244
with:
238245
version: ${{ matrix.conan_version }}
239246

@@ -244,7 +251,7 @@ jobs:
244251
conan profile detect
245252
246253
- name: Install system dependencies if needed
247-
uses: ConorMacBride/install-package@v1
254+
uses: ConorMacBride/install-package@3e7ad059e07782ee54fa35f827df52aae0626f30 # v1
248255
if: ${{ matrix.aswfdockerbuild == false }}
249256
with:
250257
apt: libgl-dev libgl1-mesa-dev
@@ -266,16 +273,16 @@ jobs:
266273
267274
- name: Setup MSVC
268275
if: startsWith(matrix.os, 'windows')
269-
uses: ilammy/msvc-dev-cmd@v1.13.0 # use cl, not msbuild
276+
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
270277
# We use cl.exe because it can find CUDA without the CUDA visual studio integration,
271278
# which is extremely slow to install (see Jimver/cuda-toolkit below)
272279
# See comments at https://github.com/Jimver/cuda-toolkit/issues/253
273280

274281
- name: Setup Ninja
275-
uses: seanmiddleditch/gha-setup-ninja@v4
282+
uses: seanmiddleditch/gha-setup-ninja@8b297075da4cd2a5f1fd21fe011b499edf06e9d2 # v4
276283

277284
- name: Install CUDA Toolkit
278-
uses: Jimver/cuda-toolkit@v0.2.19
285+
uses: Jimver/cuda-toolkit@4bd727d5619dc6fa323b1e76c3aa5dca94f5ec6d # v0.2.19
279286
id: cuda-toolkit-linux
280287
if: matrix.ostype == 'linux' && matrix.cuda == true
281288
with:
@@ -285,7 +292,7 @@ jobs:
285292
linux-local-args: '["--toolkit"]'
286293

287294
- name: Install CUDA Toolkit
288-
uses: Jimver/cuda-toolkit@v0.2.16
295+
uses: Jimver/cuda-toolkit@9b295696791d75d658d8de64c4a85097ad8abeaf # v0.2.16
289296
id: cuda-toolkit-win
290297
if: matrix.ostype == 'windows' && matrix.cuda == true
291298
with:
@@ -299,24 +306,34 @@ jobs:
299306
# rpm install libglvnd-devel
300307

301308
- name: Install dependencies
309+
env:
310+
MATRIX_OPENGL: ${{ matrix.opengl }}
311+
MATRIX_OPENCL: ${{ matrix.opencl }}
312+
MATRIX_BUILDTYPE: ${{ matrix.buildtype }}
302313
run: |
303-
[[ "${{ matrix.opengl }}" != false && "${{ matrix.opencl }}" = true ]] && USE_OPENCL="-o use_opencl=True"
304-
conan install -s build_type=${{ matrix.buildtype }} -pr:b=default --build=missing . -c tools.cmake.cmaketoolchain:generator=Ninja $USE_OPENCL
314+
[[ "$MATRIX_OPENGL" != false && "$MATRIX_OPENCL" = true ]] && USE_OPENCL="-o use_opencl=True"
315+
conan install -s build_type=$MATRIX_BUILDTYPE -pr:b=default --build=missing . -c tools.cmake.cmaketoolchain:generator=Ninja $USE_OPENCL
305316
306317
- name: Configure project with cmake
318+
env:
319+
MATRIX_OPENGL: ${{ matrix.opengl }}
320+
MATRIX_OPENCL: ${{ matrix.opencl }}
321+
MATRIX_CUDA: ${{ matrix.cuda }}
322+
MATRIX_HAS_PRESETS: ${{ matrix.has_cmake_presets }}
323+
MATRIX_OSTYPE: ${{ matrix.ostype }}
307324
run: |
308325
CMAKE_DEFINES=(-DBUILD_EXAMPLE_PLUGINS=TRUE \
309326
-DPLUGIN_INSTALLDIR=$(pwd)/build/Install)
310-
if [[ "${{ matrix.opengl }}" != false ]] ; then
327+
if [[ "$MATRIX_OPENGL" != false ]] ; then
311328
echo "OPENGL_BUILD=" >> $GITHUB_ENV
312329
CMAKE_DEFINES+=(-DOFX_SUPPORTS_OPENGLRENDER=TRUE)
313-
[[ "${{ matrix.opencl }}" = true ]] && CMAKE_DEFINES+=(-DOFX_SUPPORTS_OPENCLRENDER=TRUE)
314-
[[ "${{ matrix.cuda }}" = true ]] && CMAKE_DEFINES+=(-DOFX_SUPPORTS_CUDARENDER=TRUE)
330+
[[ "$MATRIX_OPENCL" = true ]] && CMAKE_DEFINES+=(-DOFX_SUPPORTS_OPENCLRENDER=TRUE)
331+
[[ "$MATRIX_CUDA" = true ]] && CMAKE_DEFINES+=(-DOFX_SUPPORTS_CUDARENDER=TRUE)
315332
else
316333
echo "OPENGL_BUILD=-no-ogl" >> $GITHUB_ENV
317334
fi
318335
CMAKE_GENERATOR=(-G Ninja)
319-
if [[ ${{ matrix.has_cmake_presets }} = true ]]; then
336+
if [[ $MATRIX_HAS_PRESETS = true ]]; then
320337
# Sets up to build in e.g. build/Release
321338
cmake --preset $CONAN_PRESET ${CMAKE_GENERATOR[@]} ${CMAKE_DEFINES[@]} .
322339
else
@@ -330,29 +347,35 @@ jobs:
330347
fi
331348
332349
- name: Build with cmake
350+
env:
351+
MATRIX_OSTYPE: ${{ matrix.ostype }}
333352
run: |
334-
if [[ ${{ matrix.ostype }} = windows ]]; then
353+
if [[ $MATRIX_OSTYPE = windows ]]; then
335354
cmake --build $BUILD_DIR --target install --config Release --parallel
336355
else
337356
cmake --build $BUILD_DIR --target install --parallel
338357
fi
339358
340359
- name: Install with cmake
360+
env:
361+
MATRIX_OSTYPE: ${{ matrix.ostype }}
341362
run: |
342-
if [[ ${{ matrix.ostype }} = windows ]]; then
363+
if [[ $MATRIX_OSTYPE = windows ]]; then
343364
cmake --install $BUILD_DIR --config Release
344365
else
345366
cmake --install $BUILD_DIR
346367
fi
347368
348369
# This isn't used for release; just checks that makefiles still work.
349370
- name: Build old stuff with make
371+
env:
372+
MATRIX_OSTYPE: ${{ matrix.ostype }}
350373
run: |
351-
if [[ ${{ matrix.ostype }} = windows ]]; then
374+
if [[ $MATRIX_OSTYPE = windows ]]; then
352375
echo No Windows nmake build yet
353376
else
354377
(cd Examples; make -j)
355-
# should build Support/Plugins too, but those need work
378+
# should build Support/Plugins too, but those need work
356379
fi
357380
358381
############################################################
@@ -409,7 +432,7 @@ jobs:
409432
# Conan installed urllib3 1.26.x, but tuf (required by sigstore) needs urllib3 2.x for BaseHTTPResponse
410433
# Explicitly upgrade urllib3 first, then install sigstore
411434
python3.11 -m pip install --user --upgrade 'urllib3>=2.0'
412-
python3.11 -m pip install --user sigstore
435+
python3.11 -m pip install --user 'sigstore>=3,<4'
413436
414437
- name: Sign header/libs tarball with Sigstore manually (CentOS 7)
415438
if: github.event_name == 'release' && (matrix.vfx-cy == 2021 || matrix.vfx-cy == 2022)
@@ -428,7 +451,7 @@ jobs:
428451

429452
- name: Upload header/libs tarball and signatures
430453
if: github.event_name == 'release'
431-
uses: actions/upload-artifact@v4
454+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
432455
with:
433456
name: "openfx-${{ env.RELEASE_NAME }}"
434457
path: |
@@ -437,14 +460,14 @@ jobs:
437460
438461
- name: Upload header/libs tarball (no signatures)
439462
if: github.event_name != 'release'
440-
uses: actions/upload-artifact@v4
463+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
441464
with:
442465
name: "openfx-${{ env.RELEASE_NAME }}"
443466
path: |
444467
openfx-${{ env.RELEASE_NAME }}.tar.gz
445468
446469
# Now the same, for the plugins
447-
470+
448471
- name: Create built/installed plugins tarball
449472
run: |
450473
tar -czf openfx_plugins-$RELEASE_NAME.tar.gz -C build/Install .
@@ -467,7 +490,7 @@ jobs:
467490

468491
- name: Upload plugins tarball and signatures
469492
if: github.event_name == 'release'
470-
uses: actions/upload-artifact@v4
493+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
471494
with:
472495
name: "openfx_plugins-${{ env.RELEASE_NAME }}"
473496
path: |
@@ -476,13 +499,13 @@ jobs:
476499
477500
- name: Upload plugins tarball (no signatures)
478501
if: github.event_name != 'release'
479-
uses: actions/upload-artifact@v4
502+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
480503
with:
481504
name: "openfx_plugins-${{ env.RELEASE_NAME }}"
482505
path: |
483506
openfx_plugins-${{ env.RELEASE_NAME }}.tar.gz
484507
485-
- name: Upload artifacts to release
508+
- name: Upload artifacts to release
486509
if: github.event_name == 'release'
487510
env:
488511
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)