Skip to content

Commit 7daf984

Browse files
authored
Fix actions vulnerabilites (#3)
* Fix checkout of untrusted code in a privileged context * Fix ci permissions * Remove search for upstream pr and create an output message step
1 parent ac52320 commit 7daf984

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

.github/workflows/calculate-size-delta.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77

88
permissions:
99
contents: read
10-
pull-requests: write
1110

1211
jobs:
1312
build:
@@ -38,6 +37,10 @@ jobs:
3837
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
3938
echo "Searching for PR from branch '${{ github.ref_name }}'..."
4039
PR_NUMBER=$(gh pr list --state open --head "${{ github.ref_name }}" --json number --jq '.[0].number // empty')
40+
if [ -z "$PR_NUMBER" ]; then
41+
echo "Not found in current repo, searching across forks..."
42+
PR_NUMBER=$(gh pr list --state open --json number,headRefName,headRepositoryOwner --jq ".[] | select(.headRefName == \"${{ github.ref_name }}\") | .number" | head -n1)
43+
fi
4144
else
4245
# For issue_comment, the PR number is in the event context
4346
PR_NUMBER=${{ github.event.issue.number }}
@@ -109,27 +112,57 @@ jobs:
109112
docker image pull --platform linux/arm64 localhost:5000/app-bricks/python-base:latest
110113
docker image pull --platform linux/arm64 localhost:5000/app-bricks/python-apps-base:latest
111114
115+
- name: Calculate image sizes
116+
id: sizes
117+
run: |
118+
SIZE1=$(docker images 'localhost:5000/app-bricks/python-base:latest' --format '{{.Size}}')
119+
SIZE2=$(docker images 'localhost:5000/app-bricks/python-apps-base:latest' --format '{{.Size}}')
120+
echo "python_base_size=$SIZE1" >> $GITHUB_OUTPUT
121+
echo "python_apps_base_size=$SIZE2" >> $GITHUB_OUTPUT
122+
112123
- name: Add image sizes to Job Summary
113124
run: |
114125
echo "## Docker Image Sizes" >> $GITHUB_STEP_SUMMARY
115126
echo "" >> $GITHUB_STEP_SUMMARY
116127
echo "| Image | Size |" >> $GITHUB_STEP_SUMMARY
117128
echo "|-------|------|" >> $GITHUB_STEP_SUMMARY
118-
echo "| app-bricks/python-base | $(docker images 'localhost:5000/app-bricks/python-base:latest' --format '{{.Size}}') |" >> $GITHUB_STEP_SUMMARY
119-
echo "| app-bricks/python-apps-base | $(docker images 'localhost:5000/app-bricks/python-apps-base:latest' --format '{{.Size}}') |" >> $GITHUB_STEP_SUMMARY
120-
129+
echo "| app-bricks/python-base | ${{ steps.sizes.outputs.python_base_size }} |" >> $GITHUB_STEP_SUMMARY
130+
echo "| app-bricks/python-apps-base | ${{ steps.sizes.outputs.python_apps_base_size }} |" >> $GITHUB_STEP_SUMMARY
131+
outputs:
132+
python_base_size: ${{ steps.sizes.outputs.python_base_size }}
133+
python_apps_base_size: ${{ steps.sizes.outputs.python_apps_base_size }}
134+
pr_number: ${{ steps.pr_info.outputs.pr_number }}
135+
comment-results:
136+
runs-on: ubuntu-latest
137+
needs: build
138+
if: needs.build.outputs.pr_number != ''
139+
permissions:
140+
pull-requests: write
141+
steps:
121142
- name: Comment on PR with image sizes
122-
if: steps.pr_info.outputs.pr_number != ''
123143
env:
124144
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125145
run: |
126-
SIZE1=$(docker images 'localhost:5000/app-bricks/python-base:latest' --format '{{.Size}}')
127-
SIZE2=$(docker images 'localhost:5000/app-bricks/python-apps-base:latest' --format '{{.Size}}')
128-
gh pr comment ${{ steps.pr_info.outputs.pr_number }} --body-file - <<EOF
146+
gh pr comment ${{ needs.build.outputs.pr_number }} --repo ${{ github.repository }} --body-file - <<EOF
129147
## Docker Image Sizes
130148
131149
| Image | Size |
132150
|-------|------|
133-
| app-bricks/python-base | $SIZE1 |
134-
| app-bricks/python-apps-base | $SIZE2 |
151+
| app-bricks/python-base | ${{ needs.build.outputs.python_base_size }} |
152+
| app-bricks/python-apps-base | ${{ needs.build.outputs.python_apps_base_size }} |
135153
EOF
154+
notify-no-pr:
155+
runs-on: ubuntu-latest
156+
needs: build
157+
if: needs.build.outputs.pr_number == ''
158+
permissions: {}
159+
160+
steps:
161+
- name: Notify to check Job Summary
162+
run: |
163+
echo "ℹ️ No PR found for this workflow run."
164+
echo "📊 Image sizes are available in the Job Summary of the 'build' job."
165+
echo ""
166+
echo "To view:"
167+
echo "1. Go to the 'build' job above"
168+
echo "2. Scroll to the bottom to see the Job Summary"

.github/workflows/ci_checks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: Run Tests and Check Documentation
33
on:
44
pull_request:
55

6+
permissions:
7+
contents: read
8+
69
jobs:
710
ci-checks:
811
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)