Skip to content

Commit c4ca677

Browse files
committed
Add workflow to check for unsafeFlags in Swift packages
1 parent fd30d85 commit c4ca677

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Check for unsafeFlags
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
fast-scan:
11+
name: Fast Python scanner (text-based)
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Run quick Python scanner (ignores comments)
18+
run: |
19+
set -euo pipefail
20+
python3 - <<'PY'
21+
import sys,os,re
22+
found=False
23+
for root,_,files in os.walk('.'):
24+
for f in files:
25+
if f == 'Package.swift':
26+
path=os.path.join(root,f)
27+
try:
28+
with open(path, 'r', encoding='utf-8') as fh:
29+
in_block_comment=False
30+
for i,line in enumerate(fh, start=1):
31+
s=line.rstrip('\n')
32+
if '/*' in s:
33+
in_block_comment=True
34+
if '*/' in s:
35+
in_block_comment=False
36+
continue
37+
if in_block_comment:
38+
continue
39+
if re.match(r'^\s*//', s):
40+
continue
41+
if 'unsafeFlags' in s:
42+
print(f"{path}:{i}: {s}")
43+
found=True
44+
except Exception as e:
45+
print(f"Error reading {path}: {e}", file=sys.stderr)
46+
if found:
47+
sys.exit(1)
48+
else:
49+
print('No unsafeFlags found in tracked Package.swift files.')
50+
PY
51+
52+
dump-package-check:
53+
name: Dump Swift package (authoritative) and scan JSON
54+
runs-on: ubuntu-latest
55+
container:
56+
image: swift:5.10
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v4
60+
61+
- name: Dump package JSON and check for unsafeFlags
62+
run: |
63+
set -euo pipefail
64+
# Ensure we have a clean workspace
65+
swift --version || true
66+
swift package dump-package > package.json
67+
if grep -q '"unsafeFlags"' package.json; then
68+
echo "ERROR: unsafeFlags found in resolved package JSON:"
69+
grep -n '"unsafeFlags"' package.json || true
70+
echo "--- package.json ---"
71+
sed -n '1,200p' package.json || true
72+
exit 1
73+
else
74+
echo "No unsafeFlags in resolved package JSON."
75+
fi

0 commit comments

Comments
 (0)