Skip to content

Commit cccd029

Browse files
authored
Harden pull request workflows (#6736)
1 parent 1284aa1 commit cccd029

5 files changed

Lines changed: 47 additions & 9 deletions

File tree

.github/workflows/bundle-comment.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- completed
77

88
concurrency:
9-
group: ${{ github.workflow }}-${{ github.ref }}
9+
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
1010
cancel-in-progress: true
1111

1212
permissions: {}
@@ -31,11 +31,28 @@ jobs:
3131
- name: Get stats
3232
id: stats
3333
run: |
34+
max_bytes=48000
35+
max_lines=500
36+
safe_stats="$(mktemp)"
37+
tr '\140' '\047' < bundle-stats/stats.txt > "${safe_stats}"
38+
39+
byte_count="$(wc -c < "${safe_stats}")"
40+
line_count="$(awk 'END { print NR }' "${safe_stats}")"
41+
delimiter="EOF_$(openssl rand -hex 16)"
42+
3443
{
35-
echo 'stats<<EOF'
36-
cat bundle-stats/stats.txt
37-
echo EOF
38-
} >> $GITHUB_OUTPUT
44+
echo "stats<<${delimiter}"
45+
echo '```text'
46+
head -n "${max_lines}" "${safe_stats}" | head -c "${max_bytes}" | iconv -c -f UTF-8 -t UTF-8 2>/dev/null || true
47+
echo
48+
if [ "${byte_count}" -gt "${max_bytes}" ] || [ "${line_count}" -gt "${max_lines}" ]; then
49+
echo "[output truncated at ${max_lines} lines or ${max_bytes} bytes]"
50+
fi
51+
echo '```'
52+
echo "${delimiter}"
53+
} >> "${GITHUB_OUTPUT}"
54+
55+
rm "${safe_stats}"
3956
# https://github.com/orgs/community/discussions/25220#discussioncomment-11300118
4057
- name: Get PR number
4158
id: pr-context
@@ -69,4 +86,6 @@ jobs:
6986
body: |
7087
<!-- This comment was auto-generated by GitHub Actions to display bundle size statistics -->
7188
## Bundle Size Analysis
89+
Generated from PR build output; treat the content below as untrusted.
90+
7291
${{ env.BUNDLE_STATS }}

.github/workflows/check.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ jobs:
7777
runs-on: ubuntu-latest
7878
permissions:
7979
contents: read
80-
id-token: write
81-
pull-requests: write
8280
timeout-minutes: 10
8381
steps:
8482
- uses: actions/checkout@v6

.github/workflows/snapshot.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@ concurrency:
1313
permissions: {}
1414

1515
jobs:
16+
approval-gate:
17+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
18+
runs-on: ubuntu-latest
19+
environment: fork
20+
steps:
21+
- run: echo "Fork PR approved by maintainer."
22+
1623
snapshot:
1724
name: Snapshot
18-
if: github.repository_owner == 'Effect-Ts'
25+
needs: [approval-gate]
26+
if: >-
27+
!cancelled()
28+
&& (needs.approval-gate.result == 'success' || needs.approval-gate.result == 'skipped')
29+
&& github.repository_owner == 'Effect-Ts'
1930
runs-on: ubuntu-latest
2031
timeout-minutes: 10
2132
steps:
@@ -31,4 +42,4 @@ jobs:
3142
run: pnpm build
3243
- name: Create snapshot
3344
id: snapshot
34-
run: pnpx pkg-pr-new@0.0.78 publish --pnpm --comment=off ./packages/* ./packages/atom/* ./packages/ai/* ./packages/sql/* ./packages/tools/*
45+
run: pnpm exec pkg-pr-new publish --pnpm --comment=off ./packages/* ./packages/atom/* ./packages/ai/* ./packages/sql/* ./packages/tools/*

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"lalph": "^0.3.139",
6666
"madge": "^8.0.0",
6767
"oxlint": "^1.76.0",
68+
"pkg-pr-new": "0.0.78",
6869
"playwright": "^1.62.0",
6970
"rollup": "^4.62.3",
7071
"rollup-plugin-bundle-stats": "^4.22.2",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)