Skip to content

Commit e3a6fff

Browse files
authored
Add hab path (#38)
Signed-off-by: sandhi <sagarwal@progress.com>
1 parent 944c7bd commit e3a6fff

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

.github/workflows/ci-main-pull-request.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ on:
196196
required: false
197197
type: string
198198
default: 'stable'
199+
grype-hab-path:
200+
description: "Path to built Habitat package (used if build_package is true, overrides hab_origin/hab_package inputs)"
201+
required: false
202+
type: string
199203
grype-hab-scan-linux:
200204
description: 'Scan Linux (x86_64-linux) Habitat package'
201205
required: false
@@ -895,20 +899,31 @@ jobs:
895899
echo "level=none" >> $GITHUB_OUTPUT
896900
fi
897901
902+
- name: Install Grype and update database
903+
run: |
904+
curl -sSfL https://get.anchore.io/grype | sh -s -- -b /usr/local/bin
905+
grype db update
906+
grype version
907+
908+
- name: Generate Artifact Name
909+
run: |
910+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
911+
ARTIFACT_NAME=$(echo "grype-scan-${{ github.event.repository.name }}-${TIMESTAMP}" | sed 's|/|-|g')
912+
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
913+
898914
- name: Run Grype scan on repo
899915
id: scan
900-
uses: anchore/scan-action@v3
901-
with:
902-
path: .
903-
fail-build: true
904-
severity-cutoff: ${{ steps.severity.outputs.level }}
905-
output-format: json
916+
run: |
917+
# Run grype with only-fixed flag and output to JSON for analysis
918+
grype dir:. --only-fixed -o json > grype-scan.json
919+
grype dir:. --only-fixed --only-fixed --output table >> grype-scan.log || true
920+
echo "✅ Grype scan completed successfully"
906921
907922

908923
- name: Check Grype results and fail if vulnerabilities found
909924
if: always()
910925
run: |
911-
JSON_FILE="./results.json"
926+
JSON_FILE="./grype-scan.json"
912927
913928
if [ ! -f "$JSON_FILE" ] || [ -z "$JSON_FILE" ]; then
914929
echo "⚠️ Grype JSON output not found"
@@ -949,9 +964,10 @@ jobs:
949964
if: always()
950965
uses: actions/upload-artifact@v4
951966
with:
952-
name: grype-results
953-
path: ./results.json
954-
retention-days: 30
967+
name: ${{ env.ARTIFACT_NAME }}
968+
path: |
969+
grype-scan.json
970+
grype-scan.log
955971
956972
# - name: Run Grype scan on repo
957973
# uses: anchore/scan-action@v3
@@ -984,6 +1000,7 @@ jobs:
9841000
hab_version: ${{ inputs.grype-hab-version }}
9851001
hab_release: ${{ inputs.grype-hab-release }}
9861002
hab_channel: ${{ inputs.grype-hab-channel }}
1003+
hab_path: ${{ inputs.grype-hab-path }}
9871004
scan-linux: ${{ inputs.grype-hab-scan-linux }}
9881005
scan-windows: ${{ inputs.grype-hab-scan-windows }}
9891006
scan-macos: ${{ inputs.grype-hab-scan-macos }}

.github/workflows/grype-hab-package-scan.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ on:
8888
required: false
8989
type: boolean
9090
default: false
91+
hab_path:
92+
description: "Path to built Habitat package (used if build_package is true, overrides hab_origin/hab_package inputs)"
93+
required: false
94+
type: string
9195

9296
jobs:
9397
habitat-grype-scan-linux:
@@ -139,7 +143,12 @@ jobs:
139143
hab origin key download --auth $HAB_AUTH_TOKEN --secret $HAB_ORIGIN
140144
echo "--- running linux hab build"
141145
export BUILD_ARGS="-X 'main.version=${{ inputs.hab_version }}' -X 'main.build_date_time=$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
142-
hab pkg build .
146+
if [ -z "${{ inputs.hab_path }}" ]; then
147+
hab pkg build .
148+
else
149+
hab pkg build ${{ inputs.hab_path }}
150+
fi
151+
143152
hartifacts=$(ls results/*.hart)
144153
if [ -f "$hartifacts" ]; then
145154
echo "Built package artifact: $hartifacts"
@@ -322,7 +331,12 @@ jobs:
322331
hab origin key download $env:HAB_ORIGIN
323332
hab origin key download --auth $env:HAB_AUTH_TOKEN --secret $env:HAB_ORIGIN
324333
write-output "--- running windows hab build"
325-
hab pkg build .
334+
if ([string]::IsNullOrEmpty("${{ inputs.hab_path }}")) {
335+
hab pkg build .
336+
} else {
337+
hab pkg build ${{ inputs.hab_path }}
338+
}
339+
# hab pkg build .
326340
327341
- name: Extract built package info
328342
if: ${{ inputs.build_package == true }}
@@ -521,7 +535,12 @@ jobs:
521535
elif [ -n "${{ secrets.HAB_AUTH_TOKEN }}" ]; then
522536
export HAB_AUTH_TOKEN="${{ secrets.HAB_AUTH_TOKEN }}"
523537
fi
524-
hab pkg build .
538+
if [ -z "${{ inputs.hab_path }}" ]; then
539+
hab pkg build .
540+
else
541+
hab pkg build ${{ inputs.hab_path }}
542+
fi
543+
# hab pkg build .
525544
526545
- name: Extract built package info
527546
if: ${{ inputs.build_package == true }}

0 commit comments

Comments
 (0)