# 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 }}"