Skip to content

Commit 5828734

Browse files
committed
better security-wise gh action
1 parent 06c4fba commit 5828734

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

.github/workflows/style-bot-action.yml

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ name: Style Bot Action
33
on:
44
workflow_call:
55
inputs:
6-
pre_commit_script:
6+
style_command_type:
77
required: false
88
type: string
9-
description: "Optional script to run before committing changes"
10-
pre_commit_script_name:
11-
required: false
12-
type: string
13-
description: "Custom name for the pre-commit script step"
14-
default: "Custom pre-commit script"
9+
description: "Which style command to run (options: 'default' (make style && make quality), 'quality_only', 'style_only')"
10+
default: "default"
1511
python_quality_dependencies:
1612
required: true
1713
type: string
@@ -21,11 +17,6 @@ on:
2117
type: string
2218
description: "Python version to run code formatter"
2319
default: "3.10"
24-
style_command:
25-
required: false
26-
type: string
27-
description: "Command to run for style checks or/and style fixes"
28-
default: "make style && make quality"
2920
secrets:
3021
bot_token:
3122
required: true
@@ -101,6 +92,31 @@ jobs:
10192
echo "Head Ref: $HEADREF"
10293
echo "Head Repo Full Name: $HEADREPOFULLNAME"
10394
95+
- name: Verify critical files haven't been modified
96+
uses: actions/github-script@v6
97+
with:
98+
script: |
99+
const prNumber = context.payload.issue.number;
100+
const { data: pr } = await github.rest.pulls.listFiles({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
pull_number: prNumber
104+
});
105+
106+
const modifiedFiles = pr.map(file => file.filename);
107+
console.log("Modified files:", modifiedFiles);
108+
109+
const protectedFiles = ["setup.py", "Makefile"];
110+
console.log("Protected files:", protectedFiles);
111+
112+
for (const file of protectedFiles) {
113+
if (modifiedFiles.includes(file)) {
114+
core.setFailed(`❌ Error: Protected file '${file}' has been modified in this PR. This is not allowed for security reasons.`);
115+
return;
116+
}
117+
}
118+
119+
console.log("✅ All protected files check passed!");
104120
- name: Set up Python
105121
uses: actions/setup-python@v4
106122
with:
@@ -113,18 +129,28 @@ jobs:
113129
python -m pip install --upgrade pip
114130
pip install .$python_quality_dependencies
115131
116-
- name: ${{ inputs.pre_commit_script_name }}
117-
env:
118-
pre_commit_script: ${{ inputs.pre_commit_script }}
119-
if: inputs.pre_commit_script != ''
120-
run: |
121-
bash -c "${pre_commit_script}"
122-
123132
- name: Run style command
124-
env:
125-
style_command: ${{ inputs.style_command }}
133+
id: run_style
126134
run: |
127-
bash -c "$style_command"
135+
case "${{ inputs.style_command_type }}" in
136+
"default")
137+
echo "Running default style and quality checks"
138+
make style && make quality
139+
;;
140+
"quality_only")
141+
echo "Running quality checks only"
142+
make quality
143+
;;
144+
"style_only")
145+
echo "Running style checks only"
146+
make style
147+
;;
148+
*)
149+
echo "Invalid style_command_type: ${{ inputs.style_command_type }}"
150+
echo "Valid options are: 'default', 'quality_only', 'style_only'"
151+
exit 1
152+
;;
153+
esac
128154
129155
- name: Commit and push changes
130156
id: commit_and_push

.github/workflows/style-bot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
uses: ./.github/workflows/style-bot-action.yml
1414
with:
1515
python_quality_dependencies: "[quality]"
16-
style_command: "make style"
16+
style_command_type: "style_only"
1717
secrets:
1818
bot_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)