mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 20:26:05 -05:00
The package workflows' publish steps ran easingthemes/ssh-deploy@main with the zmrepo SSH key in its environment, and imported the package signing key with crazy-max/ghaction-import-gpg@v7. A branch or tag is resolved when the workflow runs, so whoever could move it upstream could run code with those keys on our next push to master or release-1.38, and publish packages to the apt and rpm repositories. Pin each `uses:` to the commit its ref names today, with the ref as a comment so dependabot keeps updating them. ssh-deploy is pinned to v6.0.1, which main differs from only in release metadata. GitHub's own actions are pinned too. utils/check-pinned-actions.py and the CI Pinned Actions workflow fail when a workflow uses an action by anything but a full commit SHA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.4 KiB
Python
Executable File
37 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Fail if a workflow uses an action by a branch or tag instead of a commit SHA.
|
|
|
|
A branch or tag can be moved by whoever controls the action's repository, and the
|
|
package workflows hand their steps the zmrepo SSH key and the package signing key,
|
|
so every `uses:` must name a full 40-character commit SHA. Keep the version as a
|
|
comment after it (`@<sha> # v7`) so dependabot can update it.
|
|
|
|
Run from the repository root: python3 utils/check-pinned-actions.py
|
|
"""
|
|
import glob
|
|
import re
|
|
import sys
|
|
|
|
USES = re.compile(r'^\s*-?\s*uses:\s*([^\s#]+)')
|
|
PINNED = re.compile(r'^[\w.-]+/[\w.-]+(/[\w./-]+)?@[0-9a-f]{40}$')
|
|
|
|
failures = []
|
|
for path in sorted(glob.glob('.github/workflows/*.yml') + glob.glob('.github/workflows/*.yaml')):
|
|
with open(path, encoding='utf-8') as f:
|
|
for number, line in enumerate(f, 1):
|
|
m = USES.match(line)
|
|
if not m:
|
|
continue
|
|
ref = m.group(1)
|
|
if ref.startswith('./') or ref.startswith('docker://'):
|
|
continue
|
|
if not PINNED.match(ref):
|
|
failures.append(f'{path}:{number}: {ref} is not pinned to a commit SHA')
|
|
|
|
for failure in failures:
|
|
print(failure)
|
|
if failures:
|
|
print(f'\n{len(failures)} action reference(s) not pinned to a full commit SHA.')
|
|
sys.exit(1)
|
|
print('All workflow actions are pinned to commit SHAs.')
|