Skip to content

Commit e3c8267

Browse files
Harden GitHub Actions workflows (#547)
1 parent 75ec373 commit e3c8267

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
schedule:
11+
- cron: 0 0 * * 1
12+
workflow_dispatch: # allow on-demand manual scans
13+
14+
permissions: # least privilege
15+
contents: read
16+
17+
jobs:
18+
analyze:
19+
name: Analyze (${{ matrix.language }})
20+
runs-on: ubuntu-latest
21+
permissions:
22+
security-events: write # required to upload CodeQL results
23+
contents: read
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
language: ["actions", "python"]
28+
29+
steps:
30+
- uses: actions/checkout@v7
31+
32+
- name: Initialize CodeQL
33+
uses: github/codeql-action/init@v4
34+
with:
35+
languages: ${{ matrix.language }}
36+
37+
- name: Perform CodeQL Analysis
38+
uses: github/codeql-action/analyze@v4
39+
with:
40+
category: "/language:${{ matrix.language }}"

.github/workflows/pypiupload.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
types: [created]
99
workflow_dispatch: # Allow manual trigger for testing
1010

11+
permissions: # least privilege; the deploy job overrides this for OIDC
12+
contents: read
13+
1114
jobs:
1215
deploy:
1316
runs-on: ubuntu-latest

.github/workflows/spec_update.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,35 @@ jobs:
2828
git submodule update --remote --recursive
2929
- name: Generate Branch Name
3030
id: git-branch
31+
env:
32+
FORMATTED_TIME: ${{ steps.current-time.outputs.formattedTime }}
3133
run: |
32-
echo "::set-output name=branch::spec_update_${{ steps.current-time.outputs.formattedTime }}"
34+
echo "branch=spec_update_${FORMATTED_TIME}" >> "$GITHUB_OUTPUT"
3335
- name: Generate Num Diffs
3436
id: git-diff-num
3537
run: |
3638
diffs=$(git diff --submodule spec | grep ">" | wc -l)
3739
echo "Number of Spec diffs: $diffs"
38-
echo "::set-output name=num-diff::$diffs"
40+
echo "num-diff=$diffs" >> "$GITHUB_OUTPUT"
3941
- name: Generate Diff
4042
id: git-diff
43+
env:
44+
NUM_DIFF: ${{ steps.git-diff-num.outputs.num-diff }}
4145
run: |
4246
cd spec
43-
gitdiff=$(git log -n ${{ steps.git-diff-num.outputs.num-diff }} --pretty="format:%n %H %n%n %b")
47+
gitdiff=$(git log -n "$NUM_DIFF" --pretty="format:%n %H %n%n %b")
4448
commit="Automated Spec Update $gitdiff"
45-
commit="${commit//'%'/'%25'}"
46-
commit="${commit//$'\n'/'%0A'}"
47-
commit="${commit//$'\r'/'%0D'}"
48-
echo "Commit Message: $commit"
49-
echo "::set-output name=commit::$commit"
49+
while true; do
50+
delimiter="SPEC_UPDATE_EOF_$(python -c 'import uuid; print(uuid.uuid4())')"
51+
if ! grep -Fxq "$delimiter" <<< "$commit"; then
52+
break
53+
fi
54+
done
55+
{
56+
printf 'commit<<%s\n' "$delimiter"
57+
printf '%s\n' "$commit"
58+
printf '%s\n' "$delimiter"
59+
} >> "$GITHUB_OUTPUT"
5060
cd ..
5161
- name: Generate New Routes
5262
run: |

0 commit comments

Comments
 (0)