Skip to content

Commit 53c6767

Browse files
committed
ci: allow security scan workflow to target a single branch
Add a 'branch' input to workflow_dispatch that allows scanning a specific branch (e.g. fix/override-shell-quote-1.0) without auto-discovering all version branches. This enables verifying fix branches pass the security scan before creating PRs. Usage: gh workflow run "Security Scan" --ref main -f branch=fix/my-branch -f standalone-run=true
1 parent 5769285 commit 53c6767

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

.github/workflows/security-scan.yaml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ on:
2222
required: false
2323
type: boolean
2424
default: false
25+
branch:
26+
description: 'Single branch to scan (e.g. fix/override-shell-quote-1.0). If empty, scans all version branches.'
27+
required: false
28+
type: string
29+
default: ''
2530

2631
env:
2732
CODE_EDITOR_TARGETS: '["code-editor-sagemaker-server"]'
@@ -31,12 +36,21 @@ jobs:
3136
get-branches-to-scan:
3237
runs-on: ubuntu-latest
3338
outputs:
34-
security-scan-branches: ${{ steps.determine-pr-branches.outputs.branches || steps.determine-scheduled-security-scan-branches.outputs.branches }}
35-
global-dependencies-branches: ${{ steps.determine-pr-branches.outputs.branches || steps.determine-scheduled-global-dependencies-branches.outputs.branches }}
36-
output-branch-name: ${{ steps.determine-pr-branches.outputs.output-branch-name || steps.get-upstream-branches.outputs.output-branch-name }}
39+
security-scan-branches: ${{ steps.manual-branch.outputs.branches || steps.determine-pr-branches.outputs.branches || steps.determine-scheduled-security-scan-branches.outputs.branches }}
40+
global-dependencies-branches: ${{ steps.manual-branch.outputs.branches || steps.determine-pr-branches.outputs.branches || steps.determine-scheduled-global-dependencies-branches.outputs.branches }}
41+
output-branch-name: ${{ steps.manual-branch.outputs.output-branch-name || steps.determine-pr-branches.outputs.output-branch-name || steps.get-upstream-branches.outputs.output-branch-name }}
3742
steps:
43+
- name: Use manually specified branch
44+
id: manual-branch
45+
if: github.event_name == 'workflow_dispatch' && inputs.branch != ''
46+
run: |
47+
echo "Manual branch specified: ${{ inputs.branch }}"
48+
echo 'branches=["${{ inputs.branch }}"]' >> "$GITHUB_OUTPUT"
49+
echo "output-branch-name=${{ inputs.branch }}" >> "$GITHUB_OUTPUT"
50+
3851
- name: Checkout repository
3952
uses: actions/checkout@v6
53+
if: steps.manual-branch.outputs.branches == ''
4054
with:
4155
fetch-depth: 0
4256

@@ -63,7 +77,7 @@ jobs:
6377
6478
- name: Get all upstream branches
6579
id: get-upstream-branches
66-
if: github.event_name != 'push'
80+
if: github.event_name != 'push' && steps.manual-branch.outputs.branches == ''
6781
run: |
6882
# Get main branch and all version branches (*.*)
6983
branches=$(git branch -r | grep -E 'origin/(main|[0-9]+\.[0-9]+)$' | sed 's/origin\///' | tr '\n' ' ')
@@ -73,7 +87,7 @@ jobs:
7387
7488
- name: Get completed workflows from previous day
7589
id: get-completed-workflows
76-
if: github.event_name != 'push'
90+
if: github.event_name != 'push' && steps.manual-branch.outputs.branches == ''
7791
env:
7892
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7993
run: |
@@ -97,7 +111,7 @@ jobs:
97111
98112
- name: Check for successful scan artifacts from previous day
99113
id: check-scan-artifacts
100-
if: github.event_name != 'push'
114+
if: github.event_name != 'push' && steps.manual-branch.outputs.branches == ''
101115
env:
102116
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103117
REPOSITORY: ${{ github.repository }}
@@ -148,7 +162,7 @@ jobs:
148162
149163
- name: Determine security scan branches for scheduled runs
150164
id: determine-scheduled-security-scan-branches
151-
if: github.event_name != 'push'
165+
if: github.event_name != 'push' && steps.manual-branch.outputs.branches == ''
152166
run: |
153167
upstream_branches="${{ steps.get-upstream-branches.outputs.upstream-branches }}"
154168
successful_branches="${{ steps.check-scan-artifacts.outputs.successful-security-scan-branches }}"
@@ -185,7 +199,7 @@ jobs:
185199
186200
- name: Determine global dependencies branches for scheduled runs
187201
id: determine-scheduled-global-dependencies-branches
188-
if: github.event_name != 'push'
202+
if: github.event_name != 'push' && steps.manual-branch.outputs.branches == ''
189203
run: |
190204
upstream_branches="${{ steps.get-upstream-branches.outputs.upstream-branches }}"
191205
successful_branches="${{ steps.check-scan-artifacts.outputs.successful-global-dependencies-branches }}"

0 commit comments

Comments
 (0)