As thukthuk and lampbench-web: once the checks pass on a push to main, the CI job `release` reserves the next CalVer version (YYYY.M.MICRO, Bangkok time) with a draft release, builds the server on Ubuntu 22.04 (glibc 2.35) with that version and the commit (`VISA_COMMIT`), packs bin/visa, VERSION and COMMIT as visa-linux-x86_64.tar.gz, signs it with the repository secret RELEASE_SIGNING_KEY (ssh-keygen, namespace visa-release, principal visa-ci; checked against release/allowed-signers before it is published) and publishes the release. cnx01 will install a release only with that signature (cnx-network-clan modules/visa, in a PR of its own). - .gitea/scripts/release.py and test_release.py from lamp-testbench (the same reserve/publish/discard and version order), with visa's one archive; sign-release.sh; build-release.sh. The release scripts' tests run in the check job. - `visa --version` (and `visa version`): "visa <version> (<commit>)", which CI and cnx01's fetch check. - The key was made locally, put into the secret through the API and deleted; only its public half is in the repo. - README, AGENTS (main is live: push only whole steps), PLAN's decisions. Checks: fmt, clippy; test_release.py 14 tests OK in WSL; `visa --version`.
163 lines
5.4 KiB
YAML
163 lines
5.4 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, within 15 minutes, and restarts the app
|
|
# on it (cnx-network-clan modules/visa): a push to main is a deploy.
|
|
# 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 }}"
|