Files

292 lines
12 KiB
YAML

# Ébauche du pipeline CI/CD de FWS-Kitty.
#
# Ce fichier n'est PAS actif : il vit dans docCours/ pour être relu avant mise
# en service. Pour l'activer, le déplacer vers .gitea/workflows/ci.yml (Gitea
# act_runner accepte la syntaxe GitHub Actions utilisée ici).
#
# Hypothèses :
# - runner act_runner avec accès à Docker, étiquettes [self-hosted, linux, x64]
# - image de build préconstruite : fws/kitty-build:latest (Arch + deps système)
# - caches persistants montés : /cache/kitty (ccache, Go, bundle deps)
name: CI
on:
pull_request:
push:
branches: [main]
tags: ['v*']
schedule:
- cron: '0 3 * * *' # nightly : sanitizers + réaudit
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
BUILD_IMAGE: fws/kitty-build:latest
CACHE_ROOT: /cache/kitty
CCACHE_DIR: /cache/kitty/ccache
GOCACHE: /cache/kitty/go-build
GOMODCACHE: /cache/kitty/go-mod
KITTY_DISABLE_WAYLAND: '1'
CI: 'true'
jobs:
# ---------------------------------------------------------------------------
# 0. Hygiène : convention de commits et fichiers interdits
# ---------------------------------------------------------------------------
hygiene:
runs-on: [self-hosted, linux, x64]
container: { image: 'fws/kitty-lint:latest' }
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- name: Check whitespace and conflict markers
run: git diff --check "${{ github.event.pull_request.base.sha || 'HEAD~1' }}" HEAD
- name: Validate commit messages (Conventional Commits)
run: |
base="${{ github.event.pull_request.base.sha || 'HEAD~1' }}"
git log --format=%s "$base"..HEAD | while read -r subject; do
echo "$subject" | grep -Eq \
'^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9./-]+\))?!?: .{1,72}$' \
|| { echo "::error::Invalid commit subject: $subject"; exit 1; }
done
- name: Reject build artifacts and secrets
run: |
tracked="$(git ls-files)"
bad="$(echo "$tracked" | grep -E '\.pkg\.tar\.zst$|(^|/)(dependencies|build|\.venv)/|_generated\.go$|^\.env')" || true
if [ -n "$bad" ]; then echo "::error::Artifacts must not be tracked:"; echo "$bad"; exit 1; fi
# ---------------------------------------------------------------------------
# 1. Qualité : lint, format, typage
# ---------------------------------------------------------------------------
lint:
runs-on: [self-hosted, linux, x64]
container: { image: 'fws/kitty-lint:latest' }
steps:
- uses: actions/checkout@v4
- run: ruff check --output-format=github .
- run: ruff format --check .
- run: gofmt -s -l tools kittens bypy gen | tee /tmp/fmt.txt && test ! -s /tmp/fmt.txt
# go vet exige le code généré : on limite aux paquets autonomes en PR rapide
- run: go vet ./kittens/file_manager/ ./tools/... ./bypy/...
- run: staticcheck ./kittens/file_manager/ ./tools/... ./bypy/...
- name: Type check Python
run: ./dev.sh build && ./test.py type-check
# ---------------------------------------------------------------------------
# 2. Audit : vulnérabilités, dépendances, secrets, SBOM
# ---------------------------------------------------------------------------
audit:
runs-on: [self-hosted, linux, x64]
container: { image: 'fws/kitty-lint:latest' }
steps:
- uses: actions/checkout@v4
- name: Go vulnerabilities
run: govulncheck ./... | tee /tmp/govuln.txt
- name: Python doc dependencies
run: pip-audit -r docs/requirements.txt
- name: Secret scan
run: gitleaks detect --no-git --redact -v
- name: SBOM
run: syft dir:. -o spdx-json=sbom.spdx.json
- uses: actions/upload-artifact@v4
with: { name: sbom, path: sbom.spdx.json, retention-days: 90 }
# ---------------------------------------------------------------------------
# 3. Build : C + code généré + kittens + docs
# ---------------------------------------------------------------------------
build:
needs: [lint]
runs-on: [self-hosted, linux, x64]
container:
image: 'fws/kitty-build:latest'
options: --user builder
steps:
- uses: actions/checkout@v4
- name: Restore dependency bundle
run: |
test -x dependencies/linux-amd64/bin/python || ./dev.sh deps
- name: Build
run: |
start=$(date +%s)
./dev.sh build
echo "BUILD_SECONDS=$(( $(date +%s) - start ))" >> "$GITHUB_ENV"
- name: Smoke test binaries
run: |
./kitty/launcher/kitty --version
./kitty/launcher/kitten --version
- name: Build documentation
run: |
python -m venv .docs-venv
.docs-venv/bin/pip install --disable-pip-version-check -q -r docs/requirements.txt
PATH="$PWD/.docs-venv/bin:$PATH" make -C docs html FAIL_WARN=1
- uses: actions/upload-artifact@v4
with:
name: kitty-build
path: |
kitty/launcher/kitty
kitty/launcher/kitten
docs/_build/html
retention-days: 7
- name: Report build duration
run: echo "Build completed in ${BUILD_SECONDS}s"
# ---------------------------------------------------------------------------
# 4. Tests : suite Python + Go sous serveur X virtuel
# ---------------------------------------------------------------------------
test:
needs: [build]
runs-on: [self-hosted, linux, x64]
container:
image: 'fws/kitty-build:latest'
options: --user builder
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with: { name: kitty-build, path: . }
- name: Go tests (file manager kitten)
run: go test --tags testing ./kittens/file_manager/
- name: Full suite
run: xvfb-run -a ./test.py
- name: Leak/UB check
if: github.event_name == 'schedule'
run: make asan && xvfb-run -a ./test.py --module kittens/file_manager
# ---------------------------------------------------------------------------
# 5. Paquet Arch : build, signature, test d'installation
# ---------------------------------------------------------------------------
package:
needs: [test]
runs-on: [self-hosted, linux, x64]
container:
image: 'fws/kitty-build:latest'
options: --user builder
outputs:
pkgver: ${{ steps.version.outputs.pkgver }}
pkgrel: ${{ steps.version.outputs.pkgrel }}
steps:
- uses: actions/checkout@v4
- name: Derive version from tag
id: version
run: |
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
echo "pkgver=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
else
echo "pkgver=$(sed -n 's/^pkgver=//p' packaging/PKGBUILD)" >> "$GITHUB_OUTPUT"
fi
echo "pkgrel=$(sed -n 's/^pkgrel=//p' packaging/PKGBUILD)" >> "$GITHUB_OUTPUT"
- name: Build package
run: |
cd packaging
sed -i "s/^pkgver=.*/pkgver=${{ steps.version.outputs.pkgver }}/;s/^pkgrel=.*/pkgrel=${{ steps.version.outputs.pkgrel }}/" PKGBUILD
makepkg -f --nodeps
repo-add fws-kitty.db.tar.gz fws-kitty-*.pkg.tar.zst
namcap fws-kitty-*.pkg.tar.zst || true
- name: Sign (production only)
if: startsWith(github.ref, 'refs/tags/v')
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
printf '%s' "$GPG_PRIVATE_KEY" | base64 -d | gpg --batch --import
cd packaging
for f in fws-kitty-*.pkg.tar.zst; do
gpg --batch --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
--detach-sign --no-armor "$f"
done
repo-add --sign --key <FWS_KEY_ID> fws-kitty.db.tar.gz fws-kitty-*.pkg.tar.zst
- name: Install test in a clean container
run: |
docker run --rm -v "$PWD/packaging:/pkgs:ro" archlinux:base-devel \
sh -c 'pacman -U --noconfirm /pkgs/fws-kitty-*.pkg.tar.zst && kitty --version && kitten file-manager --help'
- uses: actions/upload-artifact@v4
with:
name: arch-package
path: |
packaging/fws-kitty-*.pkg.tar.zst*
packaging/fws-kitty.db.tar.gz*
retention-days: 30
# ---------------------------------------------------------------------------
# 6a. Staging : automatique sur main
# ---------------------------------------------------------------------------
deploy-staging:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [package]
runs-on: [self-hosted, linux, x64]
environment: staging
steps:
- uses: actions/download-artifact@v4
with: { name: arch-package, path: pkgs }
- name: Publish to fws-testing repository
env:
SSH_KEY: ${{ secrets.REPO_DEPLOY_SSH_KEY }}
HOST: ${{ secrets.REPO_DEPLOY_HOST }}
USER: ${{ secrets.REPO_DEPLOY_USER }}
run: |
install -m 600 /dev/null ~/.ssh/deploy && printf '%s' "$SSH_KEY" > ~/.ssh/deploy
rsync -av -e "ssh -i ~/.ssh/deploy -o StrictHostKeyChecking=yes" \
pkgs/ "$USER@$HOST:/srv/pacman/fws/testing/x86_64/"
- name: Verify published package
run: |
docker run --rm archlinux:base-devel sh -c \
'printf "[fws-testing]\nServer = %s\nSigLevel = Optional\n" "${{ vars.TESTING_REPO_URL }}" >> /etc/pacman.conf && \
pacman -Syu --noconfirm fws-kitty && kitty --version'
# ---------------------------------------------------------------------------
# 6b. Production : tag vX.Y.Z + approbation manuelle
# ---------------------------------------------------------------------------
release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [package]
runs-on: [self-hosted, linux, x64]
environment: production # required_reviewers : 1 mainteneur
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with: { name: arch-package, path: pkgs }
- name: Publish to stable repository
env:
SSH_KEY: ${{ secrets.REPO_DEPLOY_SSH_KEY_PROD }}
HOST: ${{ secrets.REPO_DEPLOY_HOST }}
USER: ${{ secrets.REPO_DEPLOY_USER }}
run: |
install -m 600 /dev/null ~/.ssh/deploy && printf '%s' "$SSH_KEY" > ~/.ssh/deploy
rsync -av -e "ssh -i ~/.ssh/deploy -o StrictHostKeyChecking=yes" \
pkgs/ "$USER@$HOST:/srv/pacman/fws/x86_64/"
- name: Publish Gitea release
env:
TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
curl -sS -X POST "$GITEA_API/repos/$GITHUB_REPOSITORY/releases" \
-H "Authorization: token $TOKEN" \
-F tag_name="$GITHUB_REF_NAME" \
-F name="$GITHUB_REF_NAME" \
-F body="$(sed -n "/^## \\[$GITHUB_REF_NAME\\]/,/^## \\[/p" CHANGELOG.rst | head -n -1)" \
-F attachment=@pkgs/fws-kitty-*.pkg.tar.zst
- name: Verify production install
run: |
docker run --rm archlinux:base-devel sh -c \
'printf "[fws]\nServer = %s\nSigLevel = Required DatabaseOptional\n" "${{ vars.PROD_REPO_URL }}" >> /etc/pacman.conf && \
pacman -Syu --noconfirm fws-kitty && kitty --version'
# ---------------------------------------------------------------------------
# 7. Notification : un échec doit toujours dire quoi faire
# ---------------------------------------------------------------------------
notify:
if: always()
needs: [lint, audit, build, test, package]
runs-on: [self-hosted, linux, x64]
steps:
- name: Send status to team webhook
run: |
curl -sS -X POST "${{ secrets.NOTIFY_WEBHOOK_URL }}" \
-H 'Content-Type: application/json' \
-d "{\"content\":\"CI ${{ job.status }} on ${{ github.repository }}@${{ github.sha }} (${{ github.ref_name }})\"}"