Skip to content

Commit

Permalink
feat: Simplify setup of Debricked scans on FoD
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Oct 30, 2024
1 parent 2b9075b commit 7c25788
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ runs:
steps:
- uses: fortify/github-action/fod-sast-scan@main
if: inputs['sast-scan']=='true' && env.FOD_URL
env:
DO_DEBRICKED_SCAN: ${{ inputs['debricked-sca-scan'] }}
- uses: fortify/github-action/sc-sast-scan@main
if: inputs['sast-scan']=='true' && env.SSC_URL
env:
Expand Down
16 changes: 10 additions & 6 deletions internal/run-script/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ function run {
for arg in "$@"; do
# Expand environment variables that potentially contain multiple arguments.
# This is commonly used for *_EXTRA_OPTS environment variables, needed to
# properly handle quoted arguments containing whitespace.
# properly handle quoted arguments containing whitespace. To allow composite
# actions to append extra arguments, we resolve both the given variable name
# and that same variable named prefixed with GHA_
if [[ "$arg" == "__expand:"* ]]; then
local varName=${arg#"__expand:"}
if [ ! -z "${!varName}" ]; then
readarray -d '' expandedArgs < <(xargs printf '%s\0' <<<"${!varName}")
cmd+=("${expandedArgs[@]}")
fi
local varBaseName=${arg#"__expand:"}
for varName in $varBaseName GHA_$varBaseName; do
if [ ! -z "${!varName}" ]; then
readarray -d '' expandedArgs < <(xargs printf '%s\0' <<<"${!varName}")
cmd+=("${expandedArgs[@]}")
fi
done
else
cmd+=("$arg")
fi
Expand Down
22 changes: 21 additions & 1 deletion internal/set-fod-var-defaults/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ author: 'Fortify'
runs:
using: composite
steps:
- if: ${{ !env.FOD_RELEASE }}
- name: Set default FoD release name
if: ${{ !env.FOD_RELEASE }}
run: |
export FOD_RELEASE="${APP}:${REL}"
echo FOD_RELEASE=$FOD_RELEASE >> $GITHUB_ENV
Expand All @@ -13,6 +14,25 @@ runs:
env:
APP: ${{ github.repository }}
REL: ${{ github.head_ref || github.ref_name }}
- name: Configure --oss setup / -oss package options if Debricked scan enabled
if: ${{ env.DO_DEBRICKED_SCAN=='true' }}
run: |
# Configure --oss setup / -oss package options if Debricked scan enabled. Note that
# composite actions can't override user-provided environment variables, so we use
# a GitHub Action specific environment variable that will be automatically expanded
# in internal/run-script/scripts/common.sh.
#
# Platform-independent regexes looking for -oss/--oss options with word boundaries
# See 'Optional reading' section at https://stackoverflow.com/a/12696899
PKG_REGEX="(^|[^[:alnum:]_])-oss([^[:alnum:]_]|$)"
SETUP_REGEX="(^|[^[:alnum:]_])--oss([^[:alnum:]_]|$)"
if [[ ! $EXTRA_PACKAGE_OPTS =~ $PKG_REGEX && ! $PACKAGE_EXTRA_OPTS =~ $PKG_REGEX ]]; then
echo "GHA_PACKAGE_EXTRA_OPTS=-oss" >> $GITHUB_ENV
fi
if [[ ! $SETUP_EXTRA_OPTS =~ $SETUP_REGEX ]]; then
echo "GHA_SETUP_EXTRA_OPTS=--oss" >> $GITHUB_ENV
fi
shell: bash

branding:
icon: 'shield'
Expand Down
1 change: 1 addition & 0 deletions package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author: 'Fortify'
runs:
using: composite
steps:
- uses: fortify/github-action/internal/set-fod-var-defaults@main
- uses: fortify/github-action/internal/setup-java-for-sc-client@main
- uses: fortify/github-action/setup@main
with:
Expand Down

0 comments on commit 7c25788

Please sign in to comment.