ci: validate accepted stories with targeted ATDD and gate feature checks
CI / UI Checks (pull_request) Successful in 10s
CI / Rust Checks (pull_request) Failing after 25m35s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Failing after 1s
CI / Deploy (pull_request) Skipped
CI / UI Checks (pull_request) Successful in 10s
CI / Rust Checks (pull_request) Failing after 25m35s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Failing after 1s
CI / Deploy (pull_request) Skipped
This commit is contained in:
1 parent
9567bbf3aa
commit
1baeefe889
6 files changed
+808
-145
No files matched your search
+133
-90
@@ -2,6 +2,15 @@ name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, labeled, unlabeled]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
validation_level:
|
||||
description: Validation depth for this run
|
||||
type: choice
|
||||
options: [story, feature]
|
||||
default: story
|
||||
required: true
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
@@ -9,6 +18,8 @@ on:
|
||||
env:
|
||||
CARGO_BUILD_JOBS: "2"
|
||||
CARGO_INCREMENTAL: "0"
|
||||
CARGO_PROFILE_DEV_DEBUG: "0"
|
||||
CARGO_PROFILE_TEST_DEBUG: "0"
|
||||
RUST_TEST_THREADS: "2"
|
||||
TESTCONTAINERS_RYUK_DISABLED: "true"
|
||||
|
||||
@@ -19,7 +30,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -56,12 +67,6 @@ jobs:
|
||||
docker --version
|
||||
docker info
|
||||
|
||||
- name: Install dependency policy tool
|
||||
run: cargo install cargo-deny --version 0.20.2 --locked
|
||||
|
||||
- name: Run tooling unit tests
|
||||
run: python3 -m unittest discover -s tests/unit
|
||||
|
||||
- name: Check typed runtime configuration contract
|
||||
run: |
|
||||
cargo run -p crank-config --bin crank-config-contract -- --check
|
||||
@@ -104,14 +109,10 @@ jobs:
|
||||
- name: Check Rust code health
|
||||
run: scripts/check-rust-code-health.sh
|
||||
|
||||
- name: Check dependency licenses and advisories
|
||||
run: cargo deny --locked check advisories bans licenses sources
|
||||
|
||||
- name: Check Rust boundaries
|
||||
run: scripts/check-rust-boundaries.sh
|
||||
|
||||
- name: Run offline OpenAPI support corpus gate
|
||||
run: cargo test -p crank-import --test corpus -- --test-threads=1
|
||||
|
||||
- name: Check OpenAPI matrix and corpus compatibility versions
|
||||
env:
|
||||
@@ -127,80 +128,15 @@ jobs:
|
||||
fi
|
||||
python3 scripts/check-openapi-matrix-compatibility.py --base "$base_ref"
|
||||
|
||||
- name: Save OpenAPI corpus evidence
|
||||
if: always()
|
||||
uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7 # v4
|
||||
with:
|
||||
name: openapi-corpus-evidence
|
||||
path: crates/crank-import/target/openapi-corpus/evidence-*.json
|
||||
if-no-files-found: warn
|
||||
|
||||
- name: Run clippy
|
||||
run: cargo clippy --workspace --all-targets --all-features --jobs "$CARGO_BUILD_JOBS" -- -D warnings
|
||||
|
||||
# One event per change: a feature branch is gated by its pull request, so the push event runs
|
||||
# only on `main` (see `on:` above). No cache and no parallel test shards are configured on
|
||||
# purpose: both need a measured runner/isolation check first (team validation policy), and the
|
||||
# workspace suites already isolate shared databases per test process.
|
||||
#
|
||||
# Story events (`pull_request`) run only the packages the diff touches; the full workspace
|
||||
# suite stays the feature/release gate and runs on `main`.
|
||||
- name: Run story tests (affected packages)
|
||||
if: ${{ gitea.event_name == 'pull_request' }}
|
||||
run: |
|
||||
set -eu
|
||||
base="$(git merge-base HEAD origin/main 2>/dev/null || true)"
|
||||
if [ -z "$base" ]; then
|
||||
git fetch --no-tags origin main
|
||||
base="$(git merge-base HEAD FETCH_HEAD)"
|
||||
fi
|
||||
changed="$(git diff --name-only "$base" HEAD)"
|
||||
packages=""
|
||||
workspace=""
|
||||
for path in $changed; do
|
||||
case "$path" in
|
||||
Cargo.toml|Cargo.lock|rust-toolchain.toml|justfile|vendor/*|crates/Cargo.toml|apps/Cargo.toml)
|
||||
workspace="yes"
|
||||
;;
|
||||
crates/*/*)
|
||||
packages="$packages $(printf '%s' "$path" | cut -d/ -f2)"
|
||||
;;
|
||||
apps/admin-api/*)
|
||||
packages="$packages admin-api"
|
||||
;;
|
||||
apps/mcp-server/*)
|
||||
packages="$packages mcp-server"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ -n "$workspace" ]; then
|
||||
echo "shared build input changed: running the whole workspace"
|
||||
cargo test --workspace --all-targets --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
|
||||
exit 0
|
||||
fi
|
||||
selected=""
|
||||
for package in $(printf '%s\n' $packages | sort -u); do
|
||||
selected="$selected -p $package"
|
||||
done
|
||||
if [ -z "$selected" ]; then
|
||||
echo "no Rust package changed in this diff; the static checks above are the story gate"
|
||||
exit 0
|
||||
fi
|
||||
echo "story packages:$selected"
|
||||
cargo test $selected --all-targets --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
|
||||
|
||||
- name: Run full workspace tests (feature/release gate)
|
||||
if: ${{ gitea.event_name != 'pull_request' }}
|
||||
run: cargo test --workspace --all-targets --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
|
||||
|
||||
- name: Run Crank story ATDD
|
||||
run: scripts/ci-story-checks.sh
|
||||
ui:
|
||||
name: UI Checks
|
||||
runs-on: ubuntu-latest
|
||||
needs: rust
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
|
||||
- name: Verify runner toolchain
|
||||
run: |
|
||||
@@ -208,6 +144,7 @@ jobs:
|
||||
npm --version
|
||||
docker --version
|
||||
|
||||
|
||||
- name: Install UI dependencies
|
||||
working-directory: apps/ui
|
||||
run: npm ci
|
||||
@@ -220,10 +157,76 @@ jobs:
|
||||
working-directory: apps/ui
|
||||
run: npm run build
|
||||
|
||||
rust-feature:
|
||||
needs: rust
|
||||
name: Rust Feature Validation
|
||||
if: >-
|
||||
inputs.validation_level == 'feature' ||
|
||||
contains(gitea.event.pull_request.labels.*.name, 'feature-ready')
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Install Rust toolchain
|
||||
run: |
|
||||
set -eu
|
||||
toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n1)"
|
||||
if [ -z "$toolchain" ]; then
|
||||
echo "Unable to read Rust toolchain channel from rust-toolchain.toml" >&2
|
||||
exit 1
|
||||
fi
|
||||
rustup toolchain install "$toolchain" --profile minimal --component clippy --component rustfmt
|
||||
rustup default "$toolchain"
|
||||
host="$(rustc -vV | sed -n 's/^host: //p')"
|
||||
toolchain_dir="${RUSTUP_HOME:-$HOME/.rustup}/toolchains/${toolchain}-${host}"
|
||||
toolchain_bin="$toolchain_dir/bin"
|
||||
if [ ! -x "$toolchain_bin/rustc" ] || [ ! -x "$toolchain_bin/cargo" ]; then
|
||||
echo "Rust $toolchain was not installed at $toolchain_dir." >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s\n' "$toolchain_bin" >> "$GITHUB_PATH"
|
||||
"$toolchain_bin/rustc" --version
|
||||
"$toolchain_bin/cargo" --version
|
||||
"$toolchain_bin/rustfmt" --version
|
||||
"$toolchain_bin/cargo-clippy" --version
|
||||
- name: Verify runner toolchain
|
||||
run: |
|
||||
python3 --version
|
||||
rustc --version
|
||||
cargo --version
|
||||
rustfmt --version
|
||||
cargo clippy --version
|
||||
docker --version
|
||||
docker info
|
||||
- name: Install dependency policy tool
|
||||
run: cargo install cargo-deny --version 0.20.2 --locked
|
||||
- name: Run tooling unit tests
|
||||
run: python3 -m unittest discover -s tests/unit
|
||||
- name: Check dependency licenses and advisories
|
||||
run: cargo deny --locked check advisories bans licenses sources
|
||||
- name: Run offline OpenAPI support corpus gate
|
||||
run: cargo test -p crank-import --test corpus -- --test-threads=1
|
||||
- name: Save OpenAPI corpus evidence
|
||||
if: always()
|
||||
uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7 # v4
|
||||
with:
|
||||
name: openapi-corpus-evidence
|
||||
path: crates/crank-import/target/openapi-corpus/evidence-*.json
|
||||
if-no-files-found: warn
|
||||
- name: Run clippy
|
||||
run: cargo clippy --workspace --all-targets --all-features --jobs "$CARGO_BUILD_JOBS" -- -D warnings
|
||||
- name: Run tests
|
||||
run: cargo test --workspace --all-targets --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
|
||||
frontend-e2e:
|
||||
needs: [rust, ui]
|
||||
if: >-
|
||||
inputs.validation_level == 'feature' ||
|
||||
contains(gitea.event.pull_request.labels.*.name, 'feature-ready')
|
||||
name: Frontend E2E
|
||||
runs-on: ubuntu-latest
|
||||
needs: ui
|
||||
services:
|
||||
crank-e2e-postgres:
|
||||
image: postgres:16-alpine
|
||||
@@ -246,7 +249,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
|
||||
- name: Install Rust toolchain
|
||||
run: |
|
||||
@@ -324,15 +327,16 @@ jobs:
|
||||
find .tmp/ui-e2e/logs -maxdepth 1 -type f -print -exec sed -n '1,220p' {} \; || true
|
||||
|
||||
deployment:
|
||||
needs: [rust, ui]
|
||||
if: >-
|
||||
inputs.validation_level == 'feature' ||
|
||||
contains(gitea.event.pull_request.labels.*.name, 'feature-ready')
|
||||
name: Community Image Smoke
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- rust
|
||||
- ui
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
|
||||
- name: Validate Community deployment manifests
|
||||
run: |
|
||||
@@ -447,14 +451,53 @@ jobs:
|
||||
docker compose -f deploy/community/docker-compose.images.yml \
|
||||
--env-file .tmp/community-smoke.env --profile local-db down -v --remove-orphans || true
|
||||
|
||||
required-checks:
|
||||
name: Required Checks
|
||||
runs-on: ubuntu-latest
|
||||
if: always()
|
||||
needs:
|
||||
- rust
|
||||
- ui
|
||||
- deployment
|
||||
- rust-feature
|
||||
- frontend-e2e
|
||||
steps:
|
||||
- name: Require story gates and mode-appropriate feature gates
|
||||
env:
|
||||
FEATURE_VALIDATION: ${{ inputs.validation_level == 'feature' || contains(gitea.event.pull_request.labels.*.name, 'feature-ready') }}
|
||||
RUST_RESULT: ${{ needs.rust.result }}
|
||||
UI_RESULT: ${{ needs.ui.result }}
|
||||
RUST_FEATURE_RESULT: ${{ needs.rust-feature.result }}
|
||||
E2E_RESULT: ${{ needs.frontend-e2e.result }}
|
||||
IMAGE_RESULT: ${{ needs.deployment.result }}
|
||||
run: |
|
||||
set -eu
|
||||
if [ "$RUST_RESULT" != "success" ] || \
|
||||
[ "$UI_RESULT" != "success" ]; then
|
||||
echo "A required story gate did not succeed." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$FEATURE_VALIDATION" = "true" ]; then
|
||||
if [ "$RUST_FEATURE_RESULT" != "success" ] || \
|
||||
[ "$E2E_RESULT" != "success" ] || \
|
||||
[ "$IMAGE_RESULT" != "success" ]; then
|
||||
echo "A required feature gate did not succeed." >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$RUST_FEATURE_RESULT" != "skipped" ] || \
|
||||
[ "$E2E_RESULT" != "skipped" ] || \
|
||||
[ "$IMAGE_RESULT" != "skipped" ]; then
|
||||
echo "A feature-only gate did not skip in story mode." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
deploy:
|
||||
name: Deploy
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- rust
|
||||
- ui
|
||||
- frontend-e2e
|
||||
- deployment
|
||||
- required-checks
|
||||
if: ${{ gitea.event_name == 'push' && gitea.ref == 'refs/heads/main' }}
|
||||
env:
|
||||
REGISTRY: git.itexp.me
|
||||
@@ -466,7 +509,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
|
||||
- name: Verify runner toolchain
|
||||
run: |
|
||||
|
||||
@@ -5,6 +5,13 @@ on:
|
||||
tags:
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
validation_level:
|
||||
description: Validation depth for this run
|
||||
type: choice
|
||||
options: [story, feature]
|
||||
default: story
|
||||
required: true
|
||||
|
||||
env:
|
||||
REGISTRY: git.itexp.me
|
||||
@@ -17,10 +24,17 @@ env:
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
code: read
|
||||
releases: write
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Clear optional release evidence
|
||||
run: rm -f .tmp/openapi-playwright.json .tmp/openapi-ui-evidence.json
|
||||
|
||||
|
||||
|
||||
- name: Use preinstalled Rust toolchain
|
||||
run: |
|
||||
@@ -53,7 +67,14 @@ jobs:
|
||||
- name: Install dependency policy tool
|
||||
run: cargo install cargo-deny --version 0.20.2 --locked
|
||||
|
||||
- name: Check formatting
|
||||
run: cargo fmt --all --check
|
||||
|
||||
- name: Audit Rust dependencies
|
||||
run: cargo deny --locked check advisories bans licenses sources
|
||||
|
||||
- name: Run tooling unit tests
|
||||
if: inputs.validation_level == 'feature'
|
||||
run: python3 -m unittest discover -s tests/unit
|
||||
|
||||
- name: Check typed runtime configuration contract
|
||||
@@ -93,16 +114,19 @@ jobs:
|
||||
- name: Check Community scope
|
||||
run: scripts/check-community-scope.sh
|
||||
|
||||
- name: Run Crank story ATDD
|
||||
run: scripts/ci-story-checks.sh
|
||||
|
||||
- name: Run release quality gates
|
||||
if: inputs.validation_level == 'feature'
|
||||
run: |
|
||||
cargo fmt --all --check
|
||||
cargo clippy --workspace --all-targets --all-features -- -D warnings
|
||||
cargo test --workspace --all-targets -- --test-threads=1
|
||||
cargo deny --locked check advisories bans licenses sources
|
||||
|
||||
- name: Build release binaries
|
||||
run: cargo build --release -p admin-api -p mcp-server
|
||||
|
||||
|
||||
- name: Install UI dependencies
|
||||
working-directory: apps/ui
|
||||
run: npm ci
|
||||
@@ -116,10 +140,12 @@ jobs:
|
||||
run: npm run build
|
||||
|
||||
- name: Install Playwright browser
|
||||
if: inputs.validation_level == 'feature'
|
||||
working-directory: apps/ui
|
||||
run: npx playwright install --with-deps chromium
|
||||
|
||||
- name: Run release end-to-end tests
|
||||
if: inputs.validation_level == 'feature'
|
||||
working-directory: apps/ui
|
||||
run: |
|
||||
mkdir -p ../../.tmp
|
||||
@@ -127,6 +153,7 @@ jobs:
|
||||
PLAYWRIGHT_JSON_OUTPUT=../../.tmp/openapi-playwright.json npm run e2e
|
||||
|
||||
- name: Collect sanitized OpenAPI UI release evidence
|
||||
if: inputs.validation_level == 'feature'
|
||||
working-directory: apps/ui
|
||||
run: |
|
||||
trap 'rm -f ../../.tmp/openapi-playwright.json' EXIT
|
||||
@@ -155,22 +182,26 @@ jobs:
|
||||
|
||||
- name: Package release artifacts
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p dist/release
|
||||
source_revision="$(git rev-parse HEAD)"
|
||||
evidence_artifact="dist/crank-openapi-ui-evidence-${IMAGE_TAG}-${source_revision}.json"
|
||||
cp target/release/admin-api dist/release/admin-api
|
||||
cp target/release/crank-migrate dist/release/crank-migrate
|
||||
cp target/release/mcp-server dist/release/mcp-server
|
||||
cp .tmp/openapi-ui-evidence.json "$evidence_artifact"
|
||||
tar -C dist/release -czf dist/crank-community-admin-api-${IMAGE_TAG}.tar.gz admin-api crank-migrate
|
||||
tar -C dist/release -czf dist/crank-community-mcp-server-${IMAGE_TAG}.tar.gz mcp-server
|
||||
tar -C apps/ui/dist -czf dist/crank-community-ui-${IMAGE_TAG}.tar.gz .
|
||||
sha256sum \
|
||||
dist/crank-community-admin-api-${IMAGE_TAG}.tar.gz \
|
||||
dist/crank-community-mcp-server-${IMAGE_TAG}.tar.gz \
|
||||
dist/crank-community-ui-${IMAGE_TAG}.tar.gz \
|
||||
"$evidence_artifact" \
|
||||
> dist/crank-community-${IMAGE_TAG}-checksums.txt
|
||||
files=(
|
||||
"dist/crank-community-admin-api-${IMAGE_TAG}.tar.gz"
|
||||
"dist/crank-community-mcp-server-${IMAGE_TAG}.tar.gz"
|
||||
"dist/crank-community-ui-${IMAGE_TAG}.tar.gz"
|
||||
)
|
||||
if [ -f .tmp/openapi-ui-evidence.json ]; then
|
||||
cp .tmp/openapi-ui-evidence.json "$evidence_artifact"
|
||||
files+=("$evidence_artifact")
|
||||
fi
|
||||
sha256sum "${files[@]}" > "dist/crank-community-${IMAGE_TAG}-checksums.txt"
|
||||
|
||||
- name: Generate SBOM
|
||||
run: |
|
||||
@@ -178,54 +209,28 @@ jobs:
|
||||
dir:/workspace -o spdx-json \
|
||||
> dist/crank-community-${IMAGE_TAG}-sbom.spdx.json
|
||||
|
||||
- name: Write release notes
|
||||
run: |
|
||||
set -eu
|
||||
tag="${{ gitea.ref_name }}"
|
||||
{
|
||||
echo "## Crank Community ${tag}"
|
||||
echo
|
||||
echo "Source commit: \`$(git rev-parse HEAD)\`"
|
||||
echo
|
||||
echo "### Changes"
|
||||
echo
|
||||
git log --oneline -25 | sed 's/^/- /'
|
||||
echo
|
||||
echo "### Artifacts and checksums"
|
||||
echo
|
||||
echo '```'
|
||||
cat "dist/crank-community-${tag}-checksums.txt"
|
||||
echo '```'
|
||||
} > dist/RELEASE-NOTES.md
|
||||
cat dist/RELEASE-NOTES.md
|
||||
|
||||
# The archives, the checksums and the SBOM only exist inside the runner workspace until they are
|
||||
# attached to the release entry: publish them so a released version keeps its artifacts, and do
|
||||
# it before the registry steps so an image-credential problem cannot lose them.
|
||||
- name: Publish artifacts to the Gitea release
|
||||
- name: Publish release bundles, checksums, evidence, and SBOM to Gitea
|
||||
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||
env:
|
||||
RELEASE_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
FALLBACK_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
RELEASE_TAG: ${{ gitea.ref_name }}
|
||||
SOURCE_REVISION: ${{ gitea.sha }}
|
||||
run: |
|
||||
set -eu
|
||||
tag="${{ gitea.ref_name }}"
|
||||
token="${RELEASE_TOKEN:-${FALLBACK_TOKEN:-}}"
|
||||
if [ -z "$token" ]; then
|
||||
echo "No Gitea token is available to the workflow: the release artifacts stay in the runner workspace" >&2
|
||||
exit 1
|
||||
set -euo pipefail
|
||||
assets=(
|
||||
"dist/crank-community-admin-api-${RELEASE_TAG}.tar.gz"
|
||||
"dist/crank-community-mcp-server-${RELEASE_TAG}.tar.gz"
|
||||
"dist/crank-community-ui-${RELEASE_TAG}.tar.gz"
|
||||
"dist/crank-community-${RELEASE_TAG}-checksums.txt"
|
||||
"dist/crank-community-${RELEASE_TAG}-sbom.spdx.json"
|
||||
)
|
||||
evidence="dist/crank-openapi-ui-evidence-${RELEASE_TAG}-${SOURCE_REVISION}.json"
|
||||
if [ -f "$evidence" ]; then
|
||||
assets+=("$evidence")
|
||||
fi
|
||||
prerelease=""
|
||||
case "$tag" in
|
||||
*-*) prerelease="--prerelease" ;;
|
||||
esac
|
||||
GITEA_TOKEN="$token" python3 scripts/publish-gitea-release.py \
|
||||
--api "${{ gitea.server_url }}/api/v1" \
|
||||
--repo "${{ gitea.repository }}" \
|
||||
--tag "$tag" \
|
||||
--title "Crank Community ${tag}" \
|
||||
--notes-file dist/RELEASE-NOTES.md \
|
||||
--dist dist \
|
||||
$prerelease
|
||||
python3 scripts/ci-release-assets.py "${assets[@]}"
|
||||
|
||||
- name: Load deployment secrets from OpenBao
|
||||
env:
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# Проверки в CI
|
||||
|
||||
## Уровни
|
||||
|
||||
Обычная story запускает быстрые статические и контрактные проверки затронутого
|
||||
проекта плюс один явный ATDD-вход `scripts/ci-story-checks.sh`. Скрипт содержит
|
||||
короткие команды для принятого восстановительного scope и завершается ошибкой,
|
||||
если команда падает или не выбрала ни одного теста. Story CI не запускает полный
|
||||
Rust workspace, полный pytest, browser E2E, образный smoke или feature matrix.
|
||||
|
||||
Полная проверка фичи запускается при ручном `workflow_dispatch` с
|
||||
`validation_level: feature` или PR с меткой `feature-ready`. Снятие метки,
|
||||
обычный push и обычный PR возвращают CI к уровню story. Стабильный обязательный
|
||||
контекст слияния — `CI / Required Checks`; он всегда проверяет базовые jobs, а
|
||||
feature jobs должны быть `skipped` для story и `success` для feature. Пустой или
|
||||
неизвестный результат считается ошибкой.
|
||||
|
||||
У Crank и FreeHub полный Rust clippy/workspace test и тяжёлые feature/security
|
||||
проверки выполняются только на feature. UI build и быстрые UI unit tests остаются
|
||||
на story, Playwright E2E — на feature. Crank image build/scan/compose smoke — на
|
||||
feature; фактический Deploy остаётся отдельным push-main job со своими build,
|
||||
scan, health и требованием успешного SHA. Тег релиза по умолчанию запускает story
|
||||
ATDD, сборку бинарных/UI артефактов, security audit и image scan. Полный release
|
||||
clippy/workspace/E2E доступен через ручной dispatch с `validation_level: feature`;
|
||||
отчёт evidence прикладывается только если такой E2E был выполнен. FreeHub
|
||||
production CD сохраняет свой exact-SHA CI guard и собственные build/health
|
||||
проверки.
|
||||
|
||||
У Torranslate story запускает один Python 3.14 и принятый целевой pytest файл;
|
||||
feature запускает существующий Python 3.13/3.14 quality matrix и Docker Compose
|
||||
smoke. Никакие workflow этого проекта не меняют Seerr, VPN/DNS или production.
|
||||
|
||||
## Поддержка ATDD-команд
|
||||
|
||||
Перед поставкой Dev и QA обновляют `scripts/ci-story-checks.sh` под story,
|
||||
которая действительно поставляется. DevOps проверяет, что тот же проверяемый
|
||||
коммит содержит актуальную команду. Начальные команды в этих скриптах относятся
|
||||
к принятому recovery scope Crank 3.17, FreeHub 2.13 и Torranslate Phase0 sidecar;
|
||||
они **не подтверждают**, что текущие 3.18, 2.14 или 1.19 уже проверены. Если
|
||||
story требует security или contract regression, добавьте её точечно в тот же
|
||||
вход и зафиксируйте основание в AC/handoff. Не добавляйте динамический selector,
|
||||
список фильтров или общий тестовый framework.
|
||||
|
||||
## Стоимость и доказательства
|
||||
|
||||
Cargo registry/git и npm dependency caches уменьшают повторную загрузку
|
||||
зависимостей. `target` не кешируется: холодная компиляция остаётся затратой и
|
||||
не измерена этим изменением. Не заявляйте экономию времени до сравнения реальных
|
||||
логов. Полный workspace/pytest и feature smoke назначаются для готовой фичи или
|
||||
явного feature dispatch, а не каждой story.
|
||||
Executable
+285
@@ -0,0 +1,285 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Publish immutable Crank release assets to Gitea, safely supporting retries."""
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import quote, urlencode, urlsplit
|
||||
from urllib.request import HTTPRedirectHandler, Request, build_opener
|
||||
|
||||
_REPO = re.compile(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+\Z")
|
||||
_TAG = re.compile(r"v[A-Za-z0-9._+-]+\Z")
|
||||
|
||||
|
||||
|
||||
class PublishError(Exception):
|
||||
"""Sanitized release publication failure safe to show in CI logs."""
|
||||
|
||||
|
||||
class _NoRedirect(HTTPRedirectHandler):
|
||||
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
||||
raise PublishError(
|
||||
f"Gitea API redirected (HTTP {code}); refusing to forward credentials"
|
||||
)
|
||||
|
||||
|
||||
def _inputs(env):
|
||||
raw_base = env.get("GITEA_SERVER_URL", "")
|
||||
parts = urlsplit(raw_base)
|
||||
if (
|
||||
parts.scheme != "https"
|
||||
or not parts.hostname
|
||||
or parts.username
|
||||
or parts.password
|
||||
or parts.query
|
||||
or parts.fragment
|
||||
or parts.path not in ("", "/")
|
||||
):
|
||||
raise PublishError("GITEA_SERVER_URL must be the trusted HTTPS Gitea origin")
|
||||
repo = env.get("GITEA_REPOSITORY", "")
|
||||
if not _REPO.fullmatch(repo):
|
||||
raise PublishError("GITEA_REPOSITORY must be owner/repository")
|
||||
tag = env.get("RELEASE_TAG", "")
|
||||
if not _TAG.fullmatch(tag):
|
||||
raise PublishError("RELEASE_TAG is not a supported version tag")
|
||||
token = env.get("GITEA_TOKEN", "")
|
||||
if (
|
||||
not token
|
||||
or len(token) > 4096
|
||||
or any(ord(char) < 32 or ord(char) == 127 for char in token)
|
||||
):
|
||||
raise PublishError("GITEA_TOKEN is unavailable or has invalid format")
|
||||
origin = f"{parts.scheme}://{parts.netloc}"
|
||||
owner, name = repo.split("/", 1)
|
||||
api = f"{origin}/api/v1/repos/{quote(owner, safe='')}/{quote(name, safe='')}"
|
||||
return origin, api, tag, token
|
||||
|
||||
|
||||
def _json_request(opener, method, url, token, payload=None, allow_404=False):
|
||||
body = None if payload is None else json.dumps(payload).encode("utf-8")
|
||||
headers = {"Authorization": f"token {token}", "Accept": "application/json"}
|
||||
if body is not None:
|
||||
headers["Content-Type"] = "application/json"
|
||||
request = Request(url, data=body, headers=headers, method=method)
|
||||
try:
|
||||
with opener.open(request, timeout=20) as response:
|
||||
return json.loads(response.read()), response.status
|
||||
except PublishError:
|
||||
raise
|
||||
except HTTPError as exc:
|
||||
status = exc.code
|
||||
exc.close()
|
||||
if allow_404 and status == 404:
|
||||
return None, 404
|
||||
raise PublishError(f"Gitea release API request failed (HTTP {status})") from None
|
||||
except (URLError, TimeoutError, OSError):
|
||||
raise PublishError("Gitea release API request failed or timed out") from None
|
||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
||||
raise PublishError("Gitea returned invalid release API data") from None
|
||||
|
||||
|
||||
def _release_id(api, tag, token, opener):
|
||||
tag_path = f"{api}/releases/tags/{quote(tag, safe='')}"
|
||||
release, status = _json_request(opener, "GET", tag_path, token, allow_404=True)
|
||||
if status == 404:
|
||||
release, status = _json_request(
|
||||
opener,
|
||||
"POST",
|
||||
f"{api}/releases",
|
||||
token,
|
||||
payload={
|
||||
"tag_name": tag,
|
||||
"name": f"Crank Community {tag}",
|
||||
"body": "Checksums, evidence, and SBOM are attached to this release.",
|
||||
},
|
||||
)
|
||||
if status not in (200, 201) or not isinstance(release, dict):
|
||||
raise PublishError("Gitea did not return a release record")
|
||||
if release.get("tag_name") != tag:
|
||||
raise PublishError("Gitea returned a release for a different tag")
|
||||
release_id = release.get("id")
|
||||
if not isinstance(release_id, int) or release_id <= 0:
|
||||
raise PublishError("Gitea returned an invalid release identifier")
|
||||
return release_id
|
||||
|
||||
|
||||
def _assets(api, release_id, token, opener):
|
||||
collected = {}
|
||||
page_size = 50
|
||||
max_pages = 20
|
||||
for page_num in range(1, max_pages + 1):
|
||||
url = f"{api}/releases/{release_id}/assets?{urlencode({'page': page_num, 'limit': page_size})}"
|
||||
result, status = _json_request(opener, "GET", url, token)
|
||||
if status != 200 or not isinstance(result, list):
|
||||
raise PublishError("Gitea returned invalid release asset data")
|
||||
for item in result:
|
||||
if (
|
||||
not isinstance(item, dict)
|
||||
or not isinstance(item.get("name"), str)
|
||||
or not isinstance(item.get("id"), int)
|
||||
or not isinstance(item.get("size"), int)
|
||||
or not isinstance(item.get("browser_download_url"), str)
|
||||
):
|
||||
raise PublishError("Gitea returned a malformed release asset")
|
||||
if item["name"] in collected:
|
||||
raise PublishError(
|
||||
f"Gitea returned duplicate release asset name {item['name']}"
|
||||
)
|
||||
collected[item["name"]] = item
|
||||
if len(result) < page_size:
|
||||
return collected
|
||||
raise PublishError("Gitea release asset history exceeded the pagination limit")
|
||||
|
||||
|
||||
def _same_bytes(origin, attachment, local_path, token, opener):
|
||||
download = urlsplit(attachment["browser_download_url"])
|
||||
trusted = urlsplit(origin)
|
||||
if (
|
||||
download.scheme != "https"
|
||||
or download.netloc != trusted.netloc
|
||||
or download.username
|
||||
or download.password
|
||||
or download.fragment
|
||||
):
|
||||
raise PublishError(
|
||||
f"Existing asset {attachment['name']} has an untrusted download URL; refusing to replace it"
|
||||
)
|
||||
expected_size = local_path.stat().st_size
|
||||
if attachment["size"] != expected_size:
|
||||
return False
|
||||
request = Request(
|
||||
attachment["browser_download_url"],
|
||||
headers={"Authorization": f"token {token}"},
|
||||
)
|
||||
try:
|
||||
with opener.open(request, timeout=30) as response:
|
||||
digest = hashlib.sha256()
|
||||
total = 0
|
||||
while True:
|
||||
chunk = response.read(1024 * 1024)
|
||||
if not chunk:
|
||||
break
|
||||
total += len(chunk)
|
||||
if total > expected_size:
|
||||
return False
|
||||
digest.update(chunk)
|
||||
except PublishError:
|
||||
raise
|
||||
except HTTPError as exc:
|
||||
status = exc.code
|
||||
exc.close()
|
||||
if 300 <= status < 400:
|
||||
raise PublishError(
|
||||
f"Existing asset {attachment['name']} redirects; refusing to forward credentials"
|
||||
) from None
|
||||
raise PublishError(
|
||||
f"Could not compare existing release asset (HTTP {status})"
|
||||
) from None
|
||||
except (URLError, TimeoutError, OSError):
|
||||
raise PublishError("Could not download existing release asset for comparison") from None
|
||||
return total == expected_size and digest.digest() == _hash_file(local_path)
|
||||
|
||||
|
||||
def _hash_file(path):
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as source:
|
||||
for chunk in iter(lambda: source.read(1024 * 1024), b""):
|
||||
digest.update(chunk)
|
||||
return digest.digest()
|
||||
|
||||
|
||||
def _curl_config(token):
|
||||
escaped = token.replace("\\", "\\\\").replace('"', '\\"')
|
||||
config = tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", delete=False)
|
||||
try:
|
||||
config.write(f'header = "Authorization: token {escaped}"\n')
|
||||
config.flush()
|
||||
os.chmod(config.name, 0o600)
|
||||
return config.name
|
||||
finally:
|
||||
config.close()
|
||||
|
||||
|
||||
def _upload(api, release_id, path, token):
|
||||
name = path.name
|
||||
url = f"{api}/releases/{release_id}/assets?{urlencode({'name': name})}"
|
||||
auth_config = _curl_config(token)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[
|
||||
"curl",
|
||||
"--fail",
|
||||
"--silent",
|
||||
"--show-error",
|
||||
"--max-time",
|
||||
"180",
|
||||
"--config",
|
||||
auth_config,
|
||||
"-F",
|
||||
f"attachment=@{path}",
|
||||
url,
|
||||
],
|
||||
check=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
except OSError:
|
||||
raise PublishError("curl is unavailable for release asset upload") from None
|
||||
finally:
|
||||
Path(auth_config).unlink(missing_ok=True)
|
||||
if result.returncode != 0:
|
||||
raise PublishError(f"Gitea rejected release asset {name} (curl exit {result.returncode})")
|
||||
|
||||
|
||||
def publish(env=None, assets=None, opener=None, upload=_upload):
|
||||
env = os.environ if env is None else env
|
||||
origin, api, tag, token = _inputs(env)
|
||||
if not assets:
|
||||
raise PublishError("No release assets were provided")
|
||||
paths = [Path(item) for item in assets]
|
||||
if any(not path.is_file() for path in paths):
|
||||
raise PublishError("A requested release asset file is missing")
|
||||
names = [path.name for path in paths]
|
||||
if len(names) != len(set(names)):
|
||||
raise PublishError("Release asset names must be unique")
|
||||
opener = opener or build_opener(_NoRedirect())
|
||||
release_id = _release_id(api, tag, token, opener)
|
||||
existing = _assets(api, release_id, token, opener)
|
||||
published = []
|
||||
for path in paths:
|
||||
attachment = existing.get(path.name)
|
||||
if attachment is not None:
|
||||
if not _same_bytes(origin, attachment, path, token, opener):
|
||||
raise PublishError(
|
||||
f"Release asset {path.name} already exists with different bytes; immutable asset left unchanged"
|
||||
)
|
||||
published.append((path.name, "already present with matching bytes"))
|
||||
continue
|
||||
upload(api, release_id, path, token)
|
||||
published.append((path.name, "uploaded"))
|
||||
return {"tag": tag, "release_id": release_id, "assets": published}
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
argv = sys.argv[1:] if argv is None else argv
|
||||
try:
|
||||
result = publish(assets=argv)
|
||||
except PublishError as exc:
|
||||
print(f"Gitea release assets: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
print(f"Gitea release {result['tag']} (id {result['release_id']}):")
|
||||
for name, state in result["assets"]:
|
||||
print(f"{state}: {name}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
active_log=""
|
||||
cleanup() {
|
||||
if [[ -n "$active_log" ]]; then
|
||||
rm -f -- "$active_log"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
run_atdd() {
|
||||
local description="$1"
|
||||
shift
|
||||
active_log="$(mktemp)"
|
||||
if cargo test "$@" >"$active_log" 2>&1; then
|
||||
if ! grep -Eq '^test result: ok\. [1-9][0-9]* passed' "$active_log"; then
|
||||
cat "$active_log" >&2
|
||||
printf 'ATDD command selected zero passing tests: %s\n' "$description" >&2
|
||||
return 1
|
||||
fi
|
||||
grep '^test result:' "$active_log"
|
||||
rm -f -- "$active_log"
|
||||
active_log=""
|
||||
return 0
|
||||
fi
|
||||
cat "$active_log" >&2
|
||||
printf 'ATDD command failed: %s\n' "$description" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
# Initial accepted recovery scope for Crank Story 3.17. Update with the story
|
||||
# being published and add only AC-required affected security/contract cases.
|
||||
run_atdd "MCP completion" -p mcp-server --test integration mcp_completion -- --test-threads=1
|
||||
run_atdd "static resource list" -p mcp-server --test integration static_resources::list -- --test-threads=1
|
||||
@@ -0,0 +1,245 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
from pathlib import Path
|
||||
from urllib.error import HTTPError
|
||||
|
||||
_MODULE_SPEC = spec_from_file_location(
|
||||
"ci_release_assets",
|
||||
Path(__file__).parents[2] / "scripts" / "ci-release-assets.py",
|
||||
)
|
||||
release_assets = module_from_spec(_MODULE_SPEC)
|
||||
_MODULE_SPEC.loader.exec_module(release_assets)
|
||||
|
||||
BASE = {
|
||||
"GITEA_SERVER_URL": "https://git.example.test",
|
||||
"GITEA_REPOSITORY": "team/project",
|
||||
"RELEASE_TAG": "v1.2.3",
|
||||
"GITEA_TOKEN": "gta_test-token",
|
||||
}
|
||||
API = "https://git.example.test/api/v1/repos/team/project"
|
||||
|
||||
|
||||
class Response:
|
||||
def __init__(self, payload=None, body=b"", status=200):
|
||||
self.payload = payload
|
||||
self.body = body
|
||||
self.status = status
|
||||
self.offset = 0
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *_args):
|
||||
return False
|
||||
|
||||
def read(self, size=-1):
|
||||
if self.payload is not None:
|
||||
body = json.dumps(self.payload).encode()
|
||||
else:
|
||||
body = self.body
|
||||
if size < 0:
|
||||
chunk = body[self.offset :]
|
||||
self.offset = len(body)
|
||||
return chunk
|
||||
chunk = body[self.offset : self.offset + size]
|
||||
self.offset += len(chunk)
|
||||
return chunk
|
||||
|
||||
|
||||
class Opener:
|
||||
def __init__(self, results):
|
||||
self.results = list(results)
|
||||
self.requests = []
|
||||
|
||||
def open(self, request, timeout):
|
||||
self.requests.append((request, timeout))
|
||||
if not self.results:
|
||||
raise AssertionError(f"unexpected HTTP request: {request.full_url}")
|
||||
expected_method, expected_fragment, result = self.results.pop(0)
|
||||
self_method = request.get_method()
|
||||
if self_method != expected_method or expected_fragment not in request.full_url:
|
||||
raise AssertionError(
|
||||
f"unexpected request {self_method} {request.full_url}; "
|
||||
f"expected {expected_method} containing {expected_fragment}"
|
||||
)
|
||||
if isinstance(result, BaseException):
|
||||
raise result
|
||||
return result
|
||||
|
||||
|
||||
def api_error(status):
|
||||
return HTTPError("https://git.example.test/api", status, "error", {}, None)
|
||||
|
||||
|
||||
def release_record():
|
||||
return {"id": 17, "tag_name": "v1.2.3"}
|
||||
|
||||
|
||||
def asset_record(name, content, url="https://git.example.test/download/file"):
|
||||
return {"id": 8, "name": name, "size": len(content), "browser_download_url": url}
|
||||
|
||||
|
||||
class ReleaseAssetsTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.path = Path(self.temp.name) / "bundle.tar.gz"
|
||||
self.path.write_bytes(b"expected release bytes")
|
||||
self.uploads = []
|
||||
|
||||
def tearDown(self):
|
||||
self.temp.cleanup()
|
||||
|
||||
def upload(self, api, release_id, path, token):
|
||||
self.uploads.append((api, release_id, path.name, token))
|
||||
|
||||
def test_creates_release_and_uploads_missing_asset(self):
|
||||
opener = Opener(
|
||||
[
|
||||
("GET", "/releases/tags/v1.2.3", api_error(404)),
|
||||
("POST", "/releases", Response(payload=release_record(), status=201)),
|
||||
("GET", "/releases/17/assets", Response(payload=[])),
|
||||
]
|
||||
)
|
||||
result = release_assets.publish(BASE, [str(self.path)], opener, self.upload)
|
||||
self.assertEqual(result["release_id"], 17)
|
||||
self.assertEqual(result["assets"], [("bundle.tar.gz", "uploaded")])
|
||||
self.assertEqual(len(self.uploads), 1)
|
||||
self.assertEqual(opener.requests[1][0].get_method(), "POST")
|
||||
self.assertEqual(opener.requests[1][0].get_header("Authorization"), "token gta_test-token")
|
||||
|
||||
def test_rerun_reuses_tag_release_and_skips_matching_asset_bytes(self):
|
||||
expected = self.path.read_bytes()
|
||||
opener = Opener(
|
||||
[
|
||||
("GET", "/releases/tags/v1.2.3", Response(payload=release_record())),
|
||||
(
|
||||
"GET",
|
||||
"/releases/17/assets",
|
||||
Response(payload=[asset_record(self.path.name, expected)]),
|
||||
),
|
||||
("GET", "/download/file", Response(body=expected)),
|
||||
]
|
||||
)
|
||||
result = release_assets.publish(BASE, [str(self.path)], opener, self.upload)
|
||||
self.assertEqual(result["assets"], [("bundle.tar.gz", "already present with matching bytes")])
|
||||
self.assertEqual(self.uploads, [])
|
||||
self.assertEqual([request.get_method() for request, _ in opener.requests], ["GET", "GET", "GET"])
|
||||
|
||||
def test_partial_retry_skips_matching_asset_and_uploads_only_missing_asset(self):
|
||||
second = Path(self.temp.name) / "checksums.txt"
|
||||
second.write_bytes(b"checksums")
|
||||
opener = Opener(
|
||||
[
|
||||
("GET", "/releases/tags/v1.2.3", Response(payload=release_record())),
|
||||
(
|
||||
"GET",
|
||||
"/releases/17/assets",
|
||||
Response(payload=[asset_record(self.path.name, self.path.read_bytes())]),
|
||||
),
|
||||
("GET", "/download/file", Response(body=self.path.read_bytes())),
|
||||
]
|
||||
)
|
||||
result = release_assets.publish(
|
||||
BASE, [str(self.path), str(second)], opener, self.upload
|
||||
)
|
||||
self.assertEqual(
|
||||
result["assets"],
|
||||
[
|
||||
("bundle.tar.gz", "already present with matching bytes"),
|
||||
("checksums.txt", "uploaded"),
|
||||
],
|
||||
)
|
||||
self.assertEqual(len(self.uploads), 1)
|
||||
self.assertEqual(self.uploads[0][2], "checksums.txt")
|
||||
|
||||
def test_different_existing_asset_is_not_overwritten(self):
|
||||
opener = Opener(
|
||||
[
|
||||
("GET", "/releases/tags/v1.2.3", Response(payload=release_record())),
|
||||
(
|
||||
"GET",
|
||||
"/releases/17/assets",
|
||||
Response(payload=[asset_record(self.path.name, b"x" * self.path.stat().st_size)]),
|
||||
),
|
||||
("GET", "/download/file", Response(body=b"x" * self.path.stat().st_size)),
|
||||
]
|
||||
)
|
||||
with self.assertRaisesRegex(release_assets.PublishError, "different bytes"):
|
||||
release_assets.publish(BASE, [str(self.path)], opener, self.upload)
|
||||
self.assertEqual(self.uploads, [])
|
||||
|
||||
def test_untrusted_existing_asset_url_is_rejected(self):
|
||||
opener = Opener(
|
||||
[
|
||||
("GET", "/releases/tags/v1.2.3", Response(payload=release_record())),
|
||||
(
|
||||
"GET",
|
||||
"/releases/17/assets",
|
||||
Response(
|
||||
payload=[
|
||||
asset_record(
|
||||
self.path.name,
|
||||
self.path.read_bytes(),
|
||||
"https://evil.example/download",
|
||||
)
|
||||
]
|
||||
),
|
||||
),
|
||||
]
|
||||
)
|
||||
with self.assertRaisesRegex(release_assets.PublishError, "untrusted download URL"):
|
||||
release_assets.publish(BASE, [str(self.path)], opener, self.upload)
|
||||
self.assertEqual(self.uploads, [])
|
||||
self.assertEqual(len(opener.requests), 2)
|
||||
|
||||
def test_same_size_different_bytes_fail(self):
|
||||
opener = Opener(
|
||||
[
|
||||
("GET", "/releases/tags/v1.2.3", Response(payload=release_record())),
|
||||
(
|
||||
"GET",
|
||||
"/releases/17/assets",
|
||||
Response(payload=[asset_record(self.path.name, b"x" * self.path.stat().st_size)]),
|
||||
),
|
||||
("GET", "/download/file", Response(body=b"x" * self.path.stat().st_size)),
|
||||
]
|
||||
)
|
||||
with self.assertRaisesRegex(release_assets.PublishError, "different bytes"):
|
||||
release_assets.publish(BASE, [str(self.path)], opener, self.upload)
|
||||
|
||||
def test_redirected_asset_download_fails_without_forwarding_token(self):
|
||||
redirect = HTTPError(
|
||||
"https://git.example.test/download/file",
|
||||
302,
|
||||
"Found",
|
||||
{"Location": "https://evil.example/file"},
|
||||
None,
|
||||
)
|
||||
opener = Opener(
|
||||
[
|
||||
("GET", "/releases/tags/v1.2.3", Response(payload=release_record())),
|
||||
(
|
||||
"GET",
|
||||
"/releases/17/assets",
|
||||
Response(payload=[asset_record(self.path.name, self.path.read_bytes())]),
|
||||
),
|
||||
("GET", "/download/file", redirect),
|
||||
]
|
||||
)
|
||||
with self.assertRaisesRegex(release_assets.PublishError, "redirects"):
|
||||
release_assets.publish(BASE, [str(self.path)], opener, self.upload)
|
||||
download_request = opener.requests[-1][0]
|
||||
self.assertEqual(download_request.get_header("Authorization"), "token gta_test-token")
|
||||
self.assertEqual(self.uploads, [])
|
||||
|
||||
def test_invalid_token_header_characters_are_rejected(self):
|
||||
with self.assertRaisesRegex(release_assets.PublishError, "invalid format"):
|
||||
release_assets.publish({**BASE, "GITEA_TOKEN": "bad\ntoken"}, [str(self.path)], Opener([]), self.upload)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user