Skip to content

Commit c29ac80

Browse files
Merge branch 'main' into catch-a-logging-exception
2 parents 45bb258 + 3665e76 commit c29ac80

9 files changed

+202
-15
lines changed

.github/workflows/codeflash-optimize.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: CodeFlash
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
paths:
66
- "**"
77
workflow_dispatch:
@@ -13,6 +13,7 @@ concurrency:
1313
jobs:
1414
optimize:
1515
name: Optimize new Python code
16+
environment: external-trusted-contributors
1617
if: ${{ github.actor != 'codeflash-ai[bot]' }}
1718
runs-on: ubuntu-latest
1819
env:
@@ -26,6 +27,21 @@ jobs:
2627
uses: actions/checkout@v4
2728
with:
2829
fetch-depth: 0
30+
- name: Validate PR
31+
run: |
32+
# Checking for any workflow changes for security risks
33+
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^.github/workflows/"; then
34+
echo "Workflow changes detected."
35+
36+
# Check if the PR author is allowed
37+
AUTHOR="${{ github.event.pull_request.user.login }}"
38+
if [[ "$AUTHOR" != "misrasaurabh1" && "$AUTHOR" != "KRRT7" ]]; then
39+
echo "Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
40+
exit 1
41+
else
42+
echo "Authorized user ($AUTHOR). Proceeding."
43+
fi
44+
fi
2945
3046
- name: 🐍 Set up Python 3.11 for CLI
3147
uses: astral-sh/setup-uv@v5
@@ -43,4 +59,4 @@ jobs:
4359
id: optimize_code
4460
run: |
4561
source .venv/bin/activate
46-
poetry run codeflash
62+
poetry run codeflash

.github/workflows/end-to-end-test-bubblesort-pytest-no-git.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: end-to-end-test
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
workflow_dispatch:
66

77
jobs:
88
bubble-sort-optimization-pytest-no-git:
9+
environment: external-trusted-contributors
910
runs-on: ubuntu-latest
1011
env:
1112
CODEFLASH_AIS_SERVER: prod
@@ -21,6 +22,21 @@ jobs:
2122
with:
2223
fetch-depth: 0
2324
token: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Validate PR
26+
run: |
27+
# Checking for any workflow changes for security risks
28+
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^.github/workflows/"; then
29+
echo "Workflow changes detected."
30+
31+
# Check if the PR author is allowed
32+
AUTHOR="${{ github.event.pull_request.user.login }}"
33+
if [[ "$AUTHOR" != "misrasaurabh1" && "$AUTHOR" != "KRRT7" ]]; then
34+
echo "Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
35+
exit 1
36+
else
37+
echo "Authorized user ($AUTHOR). Proceeding."
38+
fi
39+
fi
2440
2541
- name: Set up Python 3.11 for CLI
2642
uses: astral-sh/setup-uv@v5

.github/workflows/end-to-end-test-bubblesort-unittest.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: end-to-end-test
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
workflow_dispatch:
66

77
jobs:
88
bubble-sort-optimization-unittest:
9+
environment: external-trusted-contributors
910
runs-on: ubuntu-latest
1011
env:
1112
CODEFLASH_AIS_SERVER: prod
@@ -21,6 +22,21 @@ jobs:
2122
with:
2223
fetch-depth: 0
2324
token: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Validate PR
26+
run: |
27+
# Checking for any workflow changes for security risks
28+
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^.github/workflows/"; then
29+
echo "Workflow changes detected."
30+
31+
# Check if the PR author is allowed
32+
AUTHOR="${{ github.event.pull_request.user.login }}"
33+
if [[ "$AUTHOR" != "misrasaurabh1" && "$AUTHOR" != "KRRT7" ]]; then
34+
echo "Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
35+
exit 1
36+
else
37+
echo "Authorized user ($AUTHOR). Proceeding."
38+
fi
39+
fi
2440
2541
- name: Set up Python 3.11 for CLI
2642
uses: astral-sh/setup-uv@v5
@@ -38,4 +54,4 @@ jobs:
3854
id: optimize_code
3955
run: |
4056
source .venv/bin/activate
41-
poetry run python tests/scripts/end_to_end_test_bubblesort_unittest.py
57+
poetry run python tests/scripts/end_to_end_test_bubblesort_unittest.py

.github/workflows/end-to-end-test-coverage.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: Coverage E2E
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
workflow_dispatch:
66

77
jobs:
88
end-to-end-test-coverage:
9+
environment: external-trusted-contributors
910
runs-on: ubuntu-latest
1011
env:
1112
CODEFLASH_AIS_SERVER: prod
@@ -19,6 +20,21 @@ jobs:
1920
with:
2021
fetch-depth: 0
2122
token: ${{ secrets.GITHUB_TOKEN }}
23+
- name: Validate PR
24+
run: |
25+
# Checking for any workflow changes for security risks
26+
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^.github/workflows/"; then
27+
echo "Workflow changes detected."
28+
29+
# Check if the PR author is allowed
30+
AUTHOR="${{ github.event.pull_request.user.login }}"
31+
if [[ "$AUTHOR" != "misrasaurabh1" && "$AUTHOR" != "KRRT7" ]]; then
32+
echo "Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
33+
exit 1
34+
else
35+
echo "Authorized user ($AUTHOR). Proceeding."
36+
fi
37+
fi
2238
2339
- name: Set up Python 3.11 for CLI
2440
uses: astral-sh/setup-uv@v5
@@ -37,4 +53,4 @@ jobs:
3753
id: optimize_code
3854
run: |
3955
source .venv/bin/activate
40-
poetry run python tests/scripts/end_to_end_test_coverage.py
56+
poetry run python tests/scripts/end_to_end_test_coverage.py

.github/workflows/end-to-end-test-futurehouse.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: end-to-end-test
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
workflow_dispatch:
66

77
jobs:
88
futurehouse-structure:
9+
environment: external-trusted-contributors
910
runs-on: ubuntu-latest
1011
env:
1112
CODEFLASH_AIS_SERVER: prod
@@ -21,6 +22,21 @@ jobs:
2122
with:
2223
fetch-depth: 0
2324
token: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Validate PR
26+
run: |
27+
# Checking for any workflow changes for security risks
28+
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^.github/workflows/"; then
29+
echo "Workflow changes detected."
30+
31+
# Check if the PR author is allowed
32+
AUTHOR="${{ github.event.pull_request.user.login }}"
33+
if [[ "$AUTHOR" != "misrasaurabh1" && "$AUTHOR" != "KRRT7" ]]; then
34+
echo "Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
35+
exit 1
36+
else
37+
echo "Authorized user ($AUTHOR). Proceeding."
38+
fi
39+
fi
2440
2541
- name: Set up Python 3.11 for CLI
2642
uses: astral-sh/setup-uv@v5
@@ -38,4 +54,4 @@ jobs:
3854
id: optimize_code
3955
run: |
4056
source .venv/bin/activate
41-
poetry run python tests/scripts/end_to_end_test_futurehouse.py
57+
poetry run python tests/scripts/end_to_end_test_futurehouse.py

.github/workflows/end-to-end-test-init-optim.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: end-to-end-test
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
workflow_dispatch:
66

77
jobs:
88
init-optimization:
9+
environment: external-trusted-contributors
910
runs-on: ubuntu-latest
1011
env:
1112
CODEFLASH_AIS_SERVER: prod
@@ -21,6 +22,21 @@ jobs:
2122
with:
2223
fetch-depth: 0
2324
token: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Validate PR
26+
run: |
27+
# Checking for any workflow changes for security risks
28+
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^.github/workflows/"; then
29+
echo "Workflow changes detected."
30+
31+
# Check if the PR author is allowed
32+
AUTHOR="${{ github.event.pull_request.user.login }}"
33+
if [[ "$AUTHOR" != "misrasaurabh1" && "$AUTHOR" != "KRRT7" ]]; then
34+
echo "Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
35+
exit 1
36+
else
37+
echo "Authorized user ($AUTHOR). Proceeding."
38+
fi
39+
fi
2440
2541
- name: Set up Python 3.11 for CLI
2642
uses: astral-sh/setup-uv@v5
@@ -38,4 +54,4 @@ jobs:
3854
id: optimize_code
3955
run: |
4056
source .venv/bin/activate
41-
poetry run python tests/scripts/end_to_end_test_init_optimization.py
57+
poetry run python tests/scripts/end_to_end_test_init_optimization.py

.github/workflows/end-to-end-test-tracer-replay.yaml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: end-to-end-test
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
workflow_dispatch:
66

77
jobs:
88
tracer-replay:
9+
environment: external-trusted-contributors
910
runs-on: ubuntu-latest
1011
env:
1112
CODEFLASH_AIS_SERVER: prod
@@ -21,6 +22,22 @@ jobs:
2122
with:
2223
fetch-depth: 0
2324
token: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Validate PR
26+
run: |
27+
# Checking for any workflow changes for security risks
28+
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^.github/workflows/"; then
29+
echo "Workflow changes detected."
30+
31+
# Check if the PR author is allowed
32+
AUTHOR="${{ github.event.pull_request.user.login }}"
33+
if [[ "$AUTHOR" != "misrasaurabh1" && "$AUTHOR" != "KRRT7" ]]; then
34+
echo "Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
35+
exit 1
36+
else
37+
echo "Authorized user ($AUTHOR). Proceeding."
38+
fi
39+
fi
40+
2441
2542
- name: Set up Python 3.11 for CLI
2643
uses: astral-sh/setup-uv@v5
@@ -38,4 +55,4 @@ jobs:
3855
id: optimize_code
3956
run: |
4057
source .venv/bin/activate
41-
poetry run python tests/scripts/end_to_end_test_tracer_replay.py
58+
poetry run python tests/scripts/end_to_end_test_tracer_replay.py

.github/workflows/end-to-end-topological-sort-test.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: end-to-end-test
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
workflow_dispatch:
66

77
jobs:
88
topological-sort-optimization:
9+
environment: external-trusted-contributors
910
runs-on: ubuntu-latest
1011
env:
1112
CODEFLASH_AIS_SERVER: prod
@@ -21,6 +22,24 @@ jobs:
2122
with:
2223
fetch-depth: 0
2324
token: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Validate PR
26+
run: |
27+
# Checking for any workflow changes for security risks
28+
if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^.github/workflows/"; then
29+
echo "Workflow changes detected."
30+
31+
# Check if the PR author is allowed
32+
AUTHOR="${{ github.event.pull_request.user.login }}"
33+
if [[ "$AUTHOR" != "misrasaurabh1" && "$AUTHOR" != "KRRT7" ]]; then
34+
echo "Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
35+
exit 1
36+
else
37+
echo "Authorized user ($AUTHOR). Proceeding."
38+
fi
39+
fiif git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "end-to-end-topological-sort-test.yaml"; then
40+
echo "This workflow file has been modified. Exiting for security."
41+
exit 1
42+
fi
2443
2544
- name: Set up Python 3.11 for CLI
2645
uses: astral-sh/setup-uv@v5
@@ -38,4 +57,4 @@ jobs:
3857
id: optimize_code
3958
run: |
4059
source .venv/bin/activate
41-
poetry run python tests/scripts/end_to_end_test_topological_sort.py
60+
poetry run python tests/scripts/end_to_end_test_topological_sort.py
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: PR Labeler
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/**"
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
label-workflow-changes:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: write
14+
steps:
15+
- name: Label PR with workflow changes
16+
uses: actions/github-script@v6
17+
with:
18+
script: |
19+
const labelName = 'workflow-modified';
20+
21+
// Check if the label exists
22+
try {
23+
const labels = await github.rest.issues.listLabelsForRepo({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo
26+
});
27+
28+
const labelExists = labels.data.some(label => label.name === labelName);
29+
30+
if (!labelExists) {
31+
// Create the label if it doesn't exist
32+
await github.rest.issues.createLabel({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
name: labelName,
36+
color: 'f9d0c4',
37+
description: 'This PR modifies GitHub Actions workflows'
38+
});
39+
console.log(`Label "${labelName}" created`);
40+
} else {
41+
console.log(`Label "${labelName}" already exists`);
42+
}
43+
} catch (error) {
44+
console.error(`Failed to check or create label: ${error.message}`);
45+
throw error;
46+
}
47+
48+
// Add the label to the PR
49+
await github.rest.issues.addLabels({
50+
issue_number: context.issue.number,
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
labels: [labelName]
54+
});
55+
console.log(`Label "${labelName}" added to the PR.`);

0 commit comments

Comments
 (0)