155 lines
4.0 KiB
YAML
155 lines
4.0 KiB
YAML
name: ci
|
|
|
|
'on':
|
|
push:
|
|
branches:
|
|
- '**'
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY: gcr.forust.xyz
|
|
IMAGE_NAME: forust/telegram-scraper
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: [self-hosted, linux, arch, homelab]
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Check lint toolchain
|
|
shell: bash
|
|
run: |
|
|
for tool in prettier ruff yamllint hadolint; do
|
|
command -v "$tool" >/dev/null || {
|
|
echo "Missing required tool: $tool" >&2
|
|
exit 1
|
|
}
|
|
done
|
|
|
|
- name: Check formatting with Prettier
|
|
shell: bash
|
|
run: |
|
|
mapfile -t prettier_files < <(
|
|
git ls-files \
|
|
| grep -E '\.(md|json|ya?ml|html|css)$' \
|
|
| grep -Ev '^(\.docs/|\.zed/|errorpages/html/|homepages/(forust_files|xdfnx_files)/)'
|
|
)
|
|
|
|
if [ "${#prettier_files[@]}" -eq 0 ]; then
|
|
echo "No Prettier-managed files found."
|
|
exit 0
|
|
fi
|
|
|
|
prettier --check --ignore-unknown "${prettier_files[@]}"
|
|
|
|
- name: Lint Python with Ruff
|
|
shell: bash
|
|
run: ruff check .
|
|
|
|
- name: Lint YAML syntax
|
|
shell: bash
|
|
run: yamllint -c .yamllint .
|
|
|
|
- name: Lint Dockerfiles
|
|
shell: bash
|
|
run: |
|
|
mapfile -t dockerfiles < <(
|
|
git ls-files ':(glob)**/Dockerfile' ':(glob)**/Dockerfile.*'
|
|
)
|
|
|
|
if [ "${#dockerfiles[@]}" -eq 0 ]; then
|
|
echo "No Dockerfiles found."
|
|
exit 0
|
|
fi
|
|
|
|
hadolint -c .hadolint.yaml "${dockerfiles[@]}"
|
|
|
|
validate:
|
|
runs-on: [self-hosted, linux, arch, homelab]
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Check validation toolchain
|
|
shell: bash
|
|
run: |
|
|
for tool in yamllint kubeconform; do
|
|
command -v "$tool" >/dev/null || {
|
|
echo "Missing required tool: $tool" >&2
|
|
exit 1
|
|
}
|
|
done
|
|
|
|
- name: Lint YAML syntax
|
|
shell: bash
|
|
run: yamllint -c .yamllint .
|
|
|
|
- name: Validate Kubernetes manifests
|
|
shell: bash
|
|
run: |
|
|
mapfile -t manifests < <(
|
|
git ls-files ':(glob)**/k8s/**/*.yaml' ':(glob)**/k8s/**/*.yml' \
|
|
| grep -Ev '(^|/)(kustomization\.ya?ml|.*\.example\.ya?ml|.*values\.ya?ml|patch-.*\.ya?ml)$'
|
|
)
|
|
|
|
if [ "${#manifests[@]}" -eq 0 ]; then
|
|
echo "No Kubernetes manifests found."
|
|
exit 0
|
|
fi
|
|
|
|
kubeconform \
|
|
-strict \
|
|
-ignore-missing-schemas \
|
|
-summary \
|
|
"${manifests[@]}"
|
|
|
|
publish:
|
|
needs: [lint, validate]
|
|
if: github.event_name != 'pull_request'
|
|
runs-on: [self-hosted, linux, arch, homelab]
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Read project version
|
|
id: version
|
|
shell: bash
|
|
run: |
|
|
version="$(python3 -c 'from pathlib import Path; import tomllib; print(tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"])')"
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to registry
|
|
shell: bash
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "${REGISTRY}" \
|
|
-u "${{ secrets.REGISTRY_USERNAME }}" \
|
|
--password-stdin
|
|
|
|
- name: Build and push image
|
|
shell: bash
|
|
run: |
|
|
image="${REGISTRY}/${IMAGE_NAME}"
|
|
tags=("latest" "${{ steps.version.outputs.version }}")
|
|
|
|
case "${GITHUB_REF_NAME}" in
|
|
main)
|
|
tags+=("main" "prod")
|
|
;;
|
|
dev)
|
|
tags+=("dev")
|
|
;;
|
|
esac
|
|
|
|
build_args=()
|
|
for tag in "${tags[@]}"; do
|
|
build_args+=(-t "${image}:${tag}")
|
|
done
|
|
|
|
docker build "${build_args[@]}" .
|
|
|
|
for tag in "${tags[@]}"; do
|
|
docker push "${image}:${tag}"
|
|
done
|