.gitea/workflows/fuzz.yml runs cargo-fuzz (libFuzzer, nightly Rust) at 03:00 Chiang Mai time on runner02 on cnx01 (runs-on: cnx01; the label comes with cnx-network-clan PR #170), 10 minutes a target, under nice -n 19 (.gitea/scripts/fuzz.sh). Targets, bodies in src/fuzzing.rs: - text: passport zones and OCR output (whatever from_ocr returns must parse), positions, names, dates, Thai numbers, agreement texts and the contract diff. - upload: a file as files::sniff types it, through the pack's image and PDF code to a finished A4 page (pack::pdf::sides), EXIF orientation. - signed_copy: the drawn signature's PNG, or any text as the agreement, in the signed copy's PDF. fuzz/seeds/ holds small real files to start from (JPEG with JFIF and EXIF, PNG with pHYs, palette PNG, WebP lossy and lossless, A4 and landscape PDF, a drawn signature, zone, OCR, map links, Thai names). The grown corpus stays in the runner's cache; a crash fails the job and leaves its input as the artifact fuzz-findings, which goes into tests/fuzz_cases/<target>/ with the fix. tests/fuzz_cases.rs replays those and the seeds on every push, on stable. No sanitizer (safe Rust, about three times the inputs), debug assertions on, 10 s and 2 GB per input count as findings. DRAWING_LIMIT moved to agreements so the target uses the client page's limit. A local run of 60 s each in a Linux container: 635,522 / 9,763 / 4,089 inputs, peak 62 MB, nothing found.
166 lines
5.6 KiB
YAML
166 lines
5.6 KiB
YAML
# visa CI on git.b4l.co.th (Gitea Actions).
|
|
#
|
|
# leaks: gitleaks over the whole history on every push and pull request
|
|
# (.gitea/scripts/gitleaks.sh, rules in .gitleaks.toml). The pull
|
|
# request trigger covers AGit pull requests, whose commits arrive
|
|
# without a branch push. The pre-commit hook in .githooks/ scans the
|
|
# staged changes before they leave a computer.
|
|
# check: cargo fmt, clippy and the tests against a throwaway PostgreSQL 18,
|
|
# the version on cnx01 (each #[sqlx::test] creates its own
|
|
# database), and the release scripts' own tests.
|
|
# release: once both pass on a push to main (or a manual run on main), the
|
|
# commit becomes the next CalVer release, YYYY.M.MICRO in Bangkok
|
|
# time (.gitea/scripts/release.py). The server is built for Linux
|
|
# x86_64 on Ubuntu 22.04 (glibc 2.35; .gitea/scripts/build-release.sh)
|
|
# and signed with the repository secret RELEASE_SIGNING_KEY
|
|
# (.gitea/scripts/sign-release.sh). cnx01 installs each release
|
|
# with that signature only, seconds after the release webhook tells
|
|
# it (every 15 minutes it also looks), and restarts the app on it
|
|
# (cnx-network-clan modules/visa): a push to main is a deploy.
|
|
# Fuzzing runs every night in fuzz.yml; its findings are replayed here
|
|
# by tests/fuzz_cases.rs.
|
|
# A commit message with [skip ci] skips the whole workflow.
|
|
name: CI
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: ci-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
CARGO_INCREMENTAL: "0"
|
|
RUST_TOOLCHAIN: "1.98.1"
|
|
|
|
jobs:
|
|
leaks:
|
|
name: secret scan
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: gitleaks
|
|
run: bash .gitea/scripts/gitleaks.sh
|
|
|
|
check:
|
|
name: fmt, clippy, tests
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 60
|
|
services:
|
|
postgres:
|
|
image: postgres:18
|
|
env:
|
|
POSTGRES_USER: visa
|
|
POSTGRES_PASSWORD: visa-ci
|
|
POSTGRES_DB: visa
|
|
options: >-
|
|
--health-cmd "pg_isready -U visa"
|
|
--health-interval 5s
|
|
--health-timeout 5s
|
|
--health-retries 20
|
|
env:
|
|
DATABASE_URL: postgres://visa:visa-ci@postgres:5432/visa
|
|
# the tests wait on the database more than on the CPU
|
|
RUST_TEST_THREADS: "16"
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Release script tests
|
|
run: |
|
|
if ! command -v python3 >/dev/null || ! command -v ssh-keygen >/dev/null; then
|
|
SUDO=$(command -v sudo || true)
|
|
$SUDO apt-get update -qq
|
|
$SUDO apt-get install -y -qq python3 openssh-client
|
|
fi
|
|
python3 .gitea/scripts/test_release.py
|
|
|
|
- name: Rust toolchain
|
|
run: bash .gitea/scripts/rust-toolchain.sh "$RUST_TOOLCHAIN"
|
|
|
|
- uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
target
|
|
key: check-${{ runner.os }}-${{ env.RUST_TOOLCHAIN }}-${{ hashFiles('Cargo.lock') }}
|
|
restore-keys: check-${{ runner.os }}-${{ env.RUST_TOOLCHAIN }}-
|
|
|
|
- name: Format
|
|
run: cargo fmt --all --check
|
|
|
|
- name: Clippy
|
|
run: cargo clippy --all-targets --locked -- -D warnings
|
|
|
|
- name: Tests
|
|
run: cargo test --locked
|
|
|
|
release:
|
|
name: release
|
|
needs: [leaks, check]
|
|
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
|
|
runs-on: ubuntu-22.04
|
|
timeout-minutes: 60
|
|
permissions:
|
|
contents: write
|
|
actions: read
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: System packages
|
|
run: |
|
|
SUDO=$(command -v sudo || true)
|
|
$SUDO apt-get update -qq
|
|
$SUDO apt-get install -y -qq python3 openssh-client
|
|
|
|
# Holds the next version with a draft release on this commit; empty when
|
|
# a newer release already contains the commit.
|
|
- name: Version
|
|
id: version
|
|
run: python3 .gitea/scripts/release.py reserve
|
|
|
|
- name: Rust toolchain
|
|
if: steps.version.outputs.version != ''
|
|
run: bash .gitea/scripts/rust-toolchain.sh "$RUST_TOOLCHAIN"
|
|
|
|
- uses: actions/cache@v4
|
|
if: steps.version.outputs.version != ''
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
target
|
|
key: release-${{ runner.os }}-${{ env.RUST_TOOLCHAIN }}-${{ hashFiles('Cargo.lock') }}
|
|
restore-keys: release-${{ runner.os }}-${{ env.RUST_TOOLCHAIN }}-
|
|
|
|
- name: Build
|
|
if: steps.version.outputs.version != ''
|
|
run: bash .gitea/scripts/build-release.sh "${{ steps.version.outputs.version }}"
|
|
|
|
# cnx01 installs the server only with this signature
|
|
- name: Sign
|
|
if: steps.version.outputs.version != ''
|
|
env:
|
|
RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }}
|
|
run: bash .gitea/scripts/sign-release.sh dist/visa-linux-x86_64.tar.gz
|
|
|
|
- name: Publish
|
|
if: steps.version.outputs.version != ''
|
|
run: python3 .gitea/scripts/release.py publish "${{ steps.version.outputs.release_id }}" dist/*
|
|
|
|
- name: Discard the draft
|
|
if: (failure() || cancelled()) && steps.version.outputs.release_id != ''
|
|
run: python3 .gitea/scripts/release.py discard "${{ steps.version.outputs.release_id }}"
|