2020# JavaScript, and others. The findings are reported in the repo's code-scanning
2121# results page, https://github.com/quantumlib/REPO/security/code-scanning/.
2222#
23- # The OSV project provides a GA workflow that you can reference as a step with
23+ # Note: the OSV project provides a workflow you can reference as a step with
2424# uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml.
2525# Unfortunately, that workflow hardcodes some behaviors (such as uploading the
26- # SARIF file to the workflow Actions tab, which we rarely need ). The workflow
27- # below is basically a heavily modified version of theirs.
26+ # SARIF file to the workflow Actions tab, which we have never needed ). The
27+ # workflow in this file is basically a heavily modified version of theirs.
2828#
2929# For more OSV scanner examples and options, including how to ignore specific
3030# vulnerabilities, see https://google.github.io/osv-scanner/github-action/.
3131# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3232
33- name : OSV code scan
34- run-name : Run OSV vulnerability scanner ${{inputs.reason}}
33+ name : OSV known vulnerabilities scanner
34+ run-name : Run OSV (open-source vulnerabilities) scanner ${{inputs.reason}}
3535
3636on :
3737 pull_request :
4545 types :
4646 - checks_requested
4747
48- # Allow manual invocation.
49- workflow_dispatch :
50-
51- # Allow calling from nightly.yaml.
48+ # Allow calling from other workflows.
5249 workflow_call :
5350 inputs :
5451 reason :
52+ description : ' Append text to workflow run name:'
5553 type : string
54+ debug :
55+ description : ' Run with debugging options'
56+ type : boolean
57+ default : false
58+
59+ # Allow manual invocation.
60+ workflow_dispatch :
61+ inputs :
62+ debug :
63+ description : ' Run with debugging options'
64+ type : boolean
65+ default : true
5666
57- # Declare default permissions as read only.
67+ # Declare default workflow permissions as read only.
5868permissions : read-all
5969
70+ concurrency :
71+ # Cancel any previously-started but still active runs on the same branch.
72+ cancel-in-progress : true
73+ group : ${{github.workflow}}-${{github.event.pull_request.number||github.ref}}
74+
6075jobs :
6176 osv-scan :
77+ if : github.repository_owner == 'quantumlib'
6278 name : Run OSV scanner
6379 runs-on : ubuntu-24.04
6480 timeout-minutes : 15
6985 security-events : write
7086 # Needed to upload SARIF file to CodeQL.
7187 contents : read
88+ env :
89+ # Setting Bash SHELLOPTS here takes effect for all shell commands below.
90+ SHELLOPTS : ${{inputs.debug && 'xtrace' || '' }}
7291 steps :
7392 - name : Check out a copy of the git repository
74- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
93+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
7594 with :
7695 fetch-depth : 0
7796
@@ -82,10 +101,11 @@ jobs:
82101
83102 - name : Run OSV scanner on existing code
84103 # yamllint disable rule:line-length
85- uses : google/osv-scanner-action/osv-scanner-action@456ceb78310755116e0a3738121351006286b797 # v2.2.1
104+ uses : google/osv-scanner-action/osv-scanner-action@b00f71e051ddddc6e46a193c31c8c0bf283bf9e6 # v2.1.0
86105 continue-on-error : true
87106 with :
88107 scan-args : |-
108+ --include-git-root
89109 --format=json
90110 --output=old-results.json
91111 --recursive
@@ -99,18 +119,19 @@ jobs:
99119
100120 - name : Run OSV scanner on new code
101121 # yamllint disable rule:line-length
102- uses : google/osv-scanner-action/osv-scanner-action@456ceb78310755116e0a3738121351006286b797 # v2.2.1
122+ uses : google/osv-scanner-action/osv-scanner-action@b00f71e051ddddc6e46a193c31c8c0bf283bf9e6 # v2.1.0
103123 continue-on-error : true
104124 with :
105125 scan-args : |-
126+ --include-git-root
106127 --format=json
107128 --output=new-results.json
108129 --recursive
109130 ./
110131
111132 - name : Run the OSV scanner reporter
112133 # yamllint disable rule:line-length
113- uses : google/osv-scanner-action/osv-reporter-action@456ceb78310755116e0a3738121351006286b797 # v2.2.1
134+ uses : google/osv-scanner-action/osv-reporter-action@b00f71e051ddddc6e46a193c31c8c0bf283bf9e6 # v2.1.0
114135 with :
115136 scan-args : |-
116137 --output=osv-results.sarif
@@ -122,10 +143,18 @@ jobs:
122143 - name : Upload results to the repository's code-scanning results dashboard
123144 id : upload_artifact
124145 # yamllint disable rule:line-length
125- uses : github/codeql-action/upload-sarif@96f518a34f7a870018057716cc4d7a5c014bd61c # v3.29.10
146+ uses : github/codeql-action/upload-sarif@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3.29.5
126147 with :
127148 sarif_file : osv-results.sarif
128149
150+ - if : github.event.inputs.debug == true
151+ name : Upload results as artifacts to the workflow Summary page
152+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
153+ with :
154+ name : SARIF file
155+ path : results.sarif
156+ retention-days : 5
157+
129158 - name : Error troubleshooter
130159 if : ${{always() && steps.upload_artifact.outcome == 'failure'}}
131160 run : echo '::error::Artifact upload failed. Check the workflow logs.'
0 commit comments