Skip to content

Commit d7cd961

Browse files
Fix issues for the Security Scan Workflow (#51)
1 parent 2d16366 commit d7cd961

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

.github/workflows/security-scan.yaml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ env:
55

66
on:
77
# Trigger 1: PR created on main or version branches (*.*)
8-
pull_request:
8+
pull_request_target:
99
branches:
1010
- main
1111
- '*.*'
@@ -36,21 +36,21 @@ jobs:
3636

3737
- name: Determine branches for PR events
3838
id: determine-pr-branches
39-
if: github.event_name == 'pull_request'
39+
if: github.event_name == 'pull_request_target'
4040
env:
4141
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
HEAD_REF: ${{ github.head_ref }}
4243
run: |
4344
# For PR events, validate base branch and use head ref if valid
4445
base_ref="${{ github.base_ref }}"
45-
head_ref="${{ github.head_ref }}"
4646
echo "Base branch: $base_ref"
47-
echo "Head branch: $head_ref"
47+
echo "Head branch: $HEAD_REF"
4848
4949
if [[ "$base_ref" =~ ^[0-9]+\.[0-9]+$ ]] || [[ "$base_ref" == "main" ]]; then
5050
echo "Base branch matches allowed pattern (main or digit.digit)"
51-
echo "branches=[\"$head_ref\"]" >> $GITHUB_OUTPUT
51+
echo "branches=[\"$HEAD_REF\"]" >> $GITHUB_OUTPUT
5252
echo "output-branch-name=$base_ref" >> $GITHUB_OUTPUT
53-
echo "Branches to scan: [$head_ref]"
53+
echo "Branches to scan: [$HEAD_REF]"
5454
echo "Output files will use branch name: $base_ref"
5555
else
5656
echo "Base branch does not match allowed pattern - no branches to scan"
@@ -60,17 +60,17 @@ jobs:
6060
6161
- name: Get all upstream branches
6262
id: get-upstream-branches
63-
if: github.event_name != 'pull_request'
63+
if: github.event_name != 'pull_request_target'
6464
run: |
6565
# Get main branch and all version branches (*.*)
66-
branches=$(git branch -r | grep -E 'origin/(main|[0-9]+\.[0-9]+)' | sed 's/origin\///' | tr '\n' ' ')
66+
branches=$(git branch -r | grep -E 'origin/(main|[0-9]+\.[0-9]+)$' | sed 's/origin\///' | tr '\n' ' ')
6767
echo "Found upstream branches: $branches"
6868
echo "upstream-branches=$branches" >> $GITHUB_OUTPUT
6969
echo "output-branch-name=scheduled" >> $GITHUB_OUTPUT
7070
7171
- name: Get completed workflows from previous day
7272
id: get-completed-workflows
73-
if: github.event_name != 'pull_request'
73+
if: github.event_name != 'pull_request_target'
7474
env:
7575
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7676
run: |
@@ -94,7 +94,7 @@ jobs:
9494
9595
- name: Check for successful scan artifacts from previous day
9696
id: check-scan-artifacts
97-
if: github.event_name != 'pull_request'
97+
if: github.event_name != 'pull_request_target'
9898
env:
9999
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100100
run: |
@@ -144,7 +144,7 @@ jobs:
144144
145145
- name: Determine security scan branches for scheduled runs
146146
id: determine-scheduled-security-scan-branches
147-
if: github.event_name != 'pull_request'
147+
if: github.event_name != 'pull_request_target'
148148
run: |
149149
upstream_branches="${{ steps.get-upstream-branches.outputs.upstream-branches }}"
150150
successful_branches="${{ steps.check-scan-artifacts.outputs.successful-security-scan-branches }}"
@@ -181,7 +181,7 @@ jobs:
181181
182182
- name: Determine global dependencies branches for scheduled runs
183183
id: determine-scheduled-global-dependencies-branches
184-
if: github.event_name != 'pull_request'
184+
if: github.event_name != 'pull_request_target'
185185
run: |
186186
upstream_branches="${{ steps.get-upstream-branches.outputs.upstream-branches }}"
187187
successful_branches="${{ steps.check-scan-artifacts.outputs.successful-global-dependencies-branches }}"
@@ -257,6 +257,7 @@ jobs:
257257
# security scan scripts. So we download the latest one from main
258258
echo "Downloading latest security-scan.sh script from main branch"
259259
curl -sSL "https://raw.githubusercontent.com/${{ github.repository }}/main/scripts/security-scan.sh" -o scripts/security-scan.sh
260+
sudo chmod +x scripts/security-scan.sh
260261
echo "Updated security-scan.sh to latest version from main"
261262
262263
- name: Set up environment
@@ -323,7 +324,7 @@ jobs:
323324
- name: Create Success Indicator File
324325
run: |
325326
# For PR events, use base_ref as output branch name, otherwise use actual branch
326-
if [ "${{ github.event_name }}" = "pull_request" ]; then
327+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
327328
output_branch="${{ needs.get-branches-to-scan.outputs.output-branch-name }}"
328329
else
329330
output_branch="${{ matrix.branch }}"
@@ -333,8 +334,8 @@ jobs:
333334
- name: Upload Success Indicator File
334335
uses: actions/upload-artifact@v4
335336
with:
336-
name: scan-success-${{ matrix.target }}-${{ github.event_name == 'pull_request' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}
337-
path: scan-success-${{ matrix.target }}-${{ github.event_name == 'pull_request' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}.txt
337+
name: scan-success-${{ matrix.target }}-${{ github.event_name == 'pull_request_target' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}
338+
path: scan-success-${{ matrix.target }}-${{ github.event_name == 'pull_request_target' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}.txt
338339
retention-days: 90
339340

340341
- name: Publish Scan Successful Metric
@@ -379,7 +380,7 @@ jobs:
379380
targets=($(echo "$targets_json" | jq -r '.[]'))
380381
381382
# For PR events, use base_ref as output branch name, otherwise use actual branch
382-
if [ "${{ github.event_name }}" = "pull_request" ]; then
383+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
383384
check_branch="${{ needs.get-branches-to-scan.outputs.output-branch-name }}"
384385
else
385386
check_branch="${{ matrix.branch }}"
@@ -417,8 +418,8 @@ jobs:
417418
if: success()
418419
uses: actions/upload-artifact@v4
419420
with:
420-
name: scan-success-branch-${{ github.event_name == 'pull_request' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}
421-
path: scan-success-branch-${{ github.event_name == 'pull_request' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}.txt
421+
name: scan-success-branch-${{ github.event_name == 'pull_request_target' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}
422+
path: scan-success-branch-${{ github.event_name == 'pull_request_target' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}.txt
422423
retention-days: 90
423424

424425
security-scan-global-dependencies:
@@ -461,6 +462,7 @@ jobs:
461462
# security scan scripts. So we download the latest one from main
462463
echo "Downloading latest security-scan.sh script from main branch"
463464
curl -sSL "https://raw.githubusercontent.com/${{ github.repository }}/main/scripts/security-scan.sh" -o scripts/security-scan.sh
465+
sudo chmod +x scripts/security-scan.sh
464466
echo "Updated security-scan.sh to latest version from main"
465467
466468
- name: Install Security Scan Dependencies
@@ -513,7 +515,7 @@ jobs:
513515
- name: Create Global Success Indicator File
514516
run: |
515517
# For PR events, use base_ref as output branch name, otherwise use actual branch
516-
if [ "${{ github.event_name }}" = "pull_request" ]; then
518+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
517519
output_branch="${{ needs.get-branches-to-scan.outputs.output-branch-name }}"
518520
else
519521
output_branch="${{ matrix.branch }}"
@@ -523,8 +525,8 @@ jobs:
523525
- name: Upload Global Success Indicator File
524526
uses: actions/upload-artifact@v4
525527
with:
526-
name: global-scan-success-${{ github.event_name == 'pull_request' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}
527-
path: global-scan-success-${{ github.event_name == 'pull_request' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}.txt
528+
name: global-scan-success-${{ github.event_name == 'pull_request_target' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}
529+
path: global-scan-success-${{ github.event_name == 'pull_request_target' && needs.get-branches-to-scan.outputs.output-branch-name || matrix.branch }}.txt
528530
retention-days: 90
529531

530532
- name: Publish Failure Metrics

0 commit comments

Comments
 (0)