Skip to content

Commit 68b3835

Browse files
google-labs-jules[bot]greenc-FNAL
authored andcommitted
maintenance: Modernize Python GitHub Actions workflows
Modernized the `python-check.yaml` and `python-fix.yaml` workflows to align with repository best practices. - Pinned all external actions to specific commit hashes for improved security and reproducibility. - Scoped permissions at the job level, applying the principle of least privilege. - Added a security check to the `python-fix.yaml` workflow to ensure it can only be triggered by trusted users. - Standardized the reference to the `detect-relevant-changes` reusable action to use the full repository path and a specific commit hash. Pin in-repository actions to `@main`, not `@<commit>`
1 parent 3b8d032 commit 68b3835

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

.github/workflows/python-check.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@ jobs:
1111
runs-on: ubuntu-latest
1212
permissions:
1313
contents: read
14-
packages: read
1514

1615
outputs:
1716
has_changes: ${{ steps.filter.outputs.matched }}
1817
changed_files: ${{ steps.filter.outputs.matched_files }}
1918

2019
steps:
2120
- name: Checkout code
22-
uses: actions/checkout@v4
21+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2322
with:
2423
fetch-depth: 0
2524
path: phlex-src
2625

2726
- name: Detect Python changes
2827
id: filter
29-
uses: ./phlex-src/.github/actions/detect-relevant-changes
28+
uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main
3029
with:
3130
repo-path: phlex-src
3231
base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
@@ -49,13 +48,12 @@ jobs:
4948
runs-on: ubuntu-latest
5049
permissions:
5150
contents: read
52-
packages: read
5351
container:
5452
image: ghcr.io/framework-r-d/phlex-ci:latest
5553

5654
steps:
5755
- name: Checkout code
58-
uses: actions/checkout@v4
56+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
5957
with:
6058
path: phlex-src
6159

.github/workflows/python-fix.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ on:
66
types:
77
- created
88

9-
permissions:
10-
pull-requests: write
11-
contents: write
12-
139
jobs:
1410
check:
1511
runs-on: ubuntu-latest
1612
name: Check for phlexbot token
17-
if: ${{ github.event.issue.pull_request }}
13+
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'OWNER') }}
14+
permissions:
15+
contents: read
16+
pull-requests: read
1817

1918
outputs:
2019
match_result: ${{ steps.check_comment.outputs.match_result }}
@@ -42,10 +41,13 @@ jobs:
4241
name: Apply fixes
4342
needs: check
4443
if: ${{ needs.check.outputs.match_result == 'match' }}
44+
permissions:
45+
contents: write
46+
pull-requests: write
4547
container:
4648
image: ghcr.io/framework-r-d/phlex-ci:latest
4749
steps:
48-
- uses: actions/checkout@v4
50+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4951
with:
5052
path: phlex-src
5153
ref: ${{ needs.check.outputs.ref_name }}
@@ -59,7 +61,7 @@ jobs:
5961
ruff format .
6062
ruff --fix .
6163
62-
- uses: EndBug/add-and-commit@v9
64+
- uses: EndBug/add-and-commit@777a761e0f8293b7b051170404976d7cf10611cb # v9.1.4
6365
id: add_and_commit
6466
with:
6567
token: ${{ secrets.WORKFLOW_PAT }}
@@ -70,14 +72,14 @@ jobs:
7072

7173
- name: Formatting changes committed and pushed
7274
if: ${{ steps.add_and_commit.outputs.committed == 'true' && steps.add_and_commit.outputs.pushed == 'true'}}
73-
uses: thollander/actions-comment-pull-request@v3
75+
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
7476
with:
7577
message: |
7678
Python linting fixes pushed (commit ${{ steps.add_and_commit.outputs.commit_sha }})
7779
7880
- name: No formatting changes to make
7981
if: ${{ steps.add_and_commit.outputs.committed == 'false' }}
80-
uses: thollander/actions-comment-pull-request@v3
82+
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
8183
with:
8284
message: |
8385
No Python linting fixes to make

0 commit comments

Comments
 (0)