mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
165 lines
7.4 KiB
YAML
165 lines
7.4 KiB
YAML
name: Block spec trace
|
|
|
|
# Every PR description carries the spec trace (see the PR template); this
|
|
# check fails a PR whose description does not.
|
|
#
|
|
# pull_request_target: the workflow and the script come from the base branch,
|
|
# so a PR cannot change its own check. The PR's code is never checked out or
|
|
# run: only its commit is fetched, for the file list. The description is read
|
|
# from the event through an environment variable, never interpolated.
|
|
on:
|
|
pull_request_target:
|
|
paths:
|
|
- "seaweed-block/**"
|
|
- ".github/workflows/block-*.yml"
|
|
- ".github/block/**"
|
|
- ".github/dockerfiles/block-*.Dockerfile"
|
|
# edited: the check reads the description and the base.
|
|
types: [opened, synchronize, reopened, edited]
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: seaweed-block
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: block-spec-trace-${{ github.event.pull_request.number }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
trace:
|
|
name: spec trace
|
|
# The base-owned check defaults to a disposable hosted runner. Only a
|
|
# same-repository PR may opt into the registered BLOCK_RUNNER_LABEL.
|
|
runs-on: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository) && vars.BLOCK_RUNNER_LABEL || 'ubuntu-latest' }}
|
|
timeout-minutes: 5
|
|
steps:
|
|
- name: Runner free space
|
|
working-directory: ${{ runner.temp }}
|
|
run: |
|
|
python3 -I - <<'PY'
|
|
import os
|
|
import shutil
|
|
import sys
|
|
required = 10_000_000_000
|
|
for path in dict.fromkeys((os.environ["GITHUB_WORKSPACE"], os.environ["RUNNER_TEMP"])):
|
|
try:
|
|
free = shutil.disk_usage(path).free
|
|
except OSError as err:
|
|
print(f"runner_disk_check_failed path={path!r} error={err}")
|
|
sys.exit(75)
|
|
if free < required:
|
|
print(f"runner_disk_low path={path!r} free_bytes={free} required_bytes={required}")
|
|
sys.exit(75)
|
|
print(f"runner_disk_ok path={path!r} free_bytes={free} required_bytes={required}")
|
|
PY
|
|
|
|
- name: Checkout base
|
|
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
|
|
with:
|
|
# github.sha is the tip of the base branch when the event fires; the
|
|
# PR's base.sha can predate this workflow's own scripts.
|
|
ref: ${{ github.sha }}
|
|
fetch-depth: 0
|
|
persist-credentials: false
|
|
|
|
# spec-trace-check.sh builds the trusted sametokens.go; a self-hosted
|
|
# runner has no Go on its PATH unless the job sets it up.
|
|
- name: Set up Go
|
|
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
|
|
with:
|
|
go-version-file: seaweed-block/go.mod
|
|
cache: false
|
|
|
|
- name: Check spec trace
|
|
env:
|
|
BASE: ${{ github.event.pull_request.base.sha }}
|
|
HEAD: ${{ github.event.pull_request.head.sha }}
|
|
PR: ${{ github.event.pull_request.number }}
|
|
BODY: ${{ github.event.pull_request.body }}
|
|
TITLE: ${{ github.event.pull_request.title }}
|
|
run: |
|
|
set -euo pipefail
|
|
bash .github/scripts/spec-trace-check-test.sh
|
|
python3 -B .github/scripts/model-trace-check-test.py
|
|
bash .github/scripts/changed-go-blobs-test.sh
|
|
# fsckObjects: a PR's objects are checked as they arrive, so a tree
|
|
# with a '..' or '.git' entry is refused here.
|
|
git -c fetch.fsckObjects=true fetch --no-tags origin "+refs/pull/${PR}/head:refs/remotes/pr/head"
|
|
printf '%s' "$BODY" >body.txt
|
|
bash ../.github/block/scripts/post-merge-review-changed.sh "$BASE" "$HEAD" >changed.bin
|
|
# Old and new blobs of each changed non-test Go file, for kind DOCS
|
|
# (objects only; a path that would leave blobs/ is refused).
|
|
mb=$(git merge-base "$BASE" "$HEAD")
|
|
bash ../.github/block/scripts/changed-go-blobs.sh "$mb" "$HEAD" blobs
|
|
# Mapping and validator come from the trusted base checkout above.
|
|
bash .github/scripts/spec-trace-check.sh body.txt blobs .github/model-code-trace.tsv <changed.bin
|
|
# Internal names stay out of this public repository: added lines,
|
|
# commit messages, title and description (no PR code is run).
|
|
bash .github/scripts/public-text-check-test.sh
|
|
printf '%s' "$TITLE" >title.txt
|
|
bash ../.github/block/scripts/public-text-check.sh "$mb" "$HEAD" title.txt body.txt
|
|
|
|
- name: Invariants ledger anchors (report only)
|
|
# Every code and test anchor of docs/design/invariants.md must exist at
|
|
# the PR's commit (git objects only; nothing from the PR is run). It
|
|
# reports and does not fail the check while the known imprecise
|
|
# anchors are being corrected; then this step becomes gating.
|
|
continue-on-error: true
|
|
env:
|
|
HEAD: ${{ github.event.pull_request.head.sha }}
|
|
run: python3 -I ../.github/block/scripts/ledger_check.py "$GITHUB_WORKSPACE" "$HEAD" seaweed-block/docs/design/invariants.md seaweed-block/ || true
|
|
|
|
- name: Clean job workspace
|
|
# Hosted runners are disposable; their setup-go cache upload runs in
|
|
# a post action and still needs the checkout. Persistent runners do not
|
|
# upload that cache, and must release their checkout/build files here.
|
|
if: always() && runner.environment == 'self-hosted'
|
|
working-directory: ${{ runner.temp }}
|
|
run: |
|
|
python3 -I - <<'PY'
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import sys
|
|
root = Path(os.environ["GITHUB_WORKSPACE"])
|
|
# Refuse aliases rather than resolving them. Open EVERY component without
|
|
# following symlinks, then keep cleanup anchored to the verified directory fd.
|
|
if not root.is_absolute() or ".." in root.parts or root == Path(root.anchor) or root.name != root.parent.name or root == Path(os.environ["RUNNER_TEMP"]):
|
|
print(f"runner_workspace_cleanup_refused path={str(root)!r}")
|
|
sys.exit(1)
|
|
flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW
|
|
fd = os.open(root.anchor, flags)
|
|
previous = os.open(".", flags)
|
|
errors = []
|
|
try:
|
|
for part in root.parts[1:]:
|
|
child = os.open(part, flags, dir_fd=fd)
|
|
os.close(fd)
|
|
fd = child
|
|
if not shutil.rmtree.avoids_symlink_attacks:
|
|
raise OSError("descriptor-safe directory removal is unavailable")
|
|
os.fchdir(fd)
|
|
for entry in os.scandir("."):
|
|
try:
|
|
if entry.is_dir(follow_symlinks=False):
|
|
shutil.rmtree(entry.name)
|
|
else:
|
|
os.unlink(entry.name)
|
|
except OSError as err:
|
|
errors.append(f"{entry.name}: {err}")
|
|
except OSError as err:
|
|
print(f"runner_workspace_cleanup_refused path={str(root)!r} error={err}")
|
|
sys.exit(1)
|
|
finally:
|
|
os.fchdir(previous)
|
|
os.close(previous)
|
|
os.close(fd)
|
|
if errors:
|
|
print("runner_workspace_cleanup_failed " + "; ".join(errors))
|
|
sys.exit(1)
|
|
print(f"runner_workspace_clean path={str(root)!r}")
|
|
PY
|