From 0e150382e138400e6524736b1770c119dc4f3b70 Mon Sep 17 00:00:00 2001 From: Ben Grande Date: Mon, 8 Jul 2024 15:21:49 +0200 Subject: [PATCH] ci: check if RPM Specs are up to date --- .pre-commit-config.yaml | 25 +++++++++++++------------ scripts/spec-gen.sh | 37 +++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 095ad1e..9b9c15e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,25 +69,26 @@ repos: pass_filenames: false description: Check if .qubesbuilder is up to date - # TODO: generate temporary spec and compare against staged one. - # - id: spec-gen - # name: spec-gen - # language: script - # entry: scripts/spec-gen.sh test - # args: [test] - # # pass_filenames: true - # description: Check if RPM SPEC files are up to date + - id: spec-gen + name: spec-gen + language: script + entry: scripts/spec-gen.sh + args: [test] + pass_filenames: true + # yamllint disable rule:line-length + files: ^(rpm_spec/template/template.spec|salt/.*|scripts/spec-(get|gen)\.sh)$ + description: Check if RPM SPEC files are up to date - - id: reuse-lint - name: reuse-lint + - id: license-lint + name: license-lint entry: reuse args: [lint] language: python pass_filenames: false description: Lint files to comply with the REUSE Specification - - id: git-lint - name: git-lint + - id: commit-lint + name: commit-lint language: python entry: gitlint args: [--staged, --msg-filename] diff --git a/scripts/spec-gen.sh b/scripts/spec-gen.sh index 24fdafc..00dda53 100755 --- a/scripts/spec-gen.sh +++ b/scripts/spec-gen.sh @@ -42,7 +42,11 @@ get_spec(){ } gen_spec(){ - project="${1}" + project="$(echo "${1}" | sed "s|salt/||;s|/.*||")" + if echo "${projects_seen}" | grep -qF " ${project} "; then + return + fi + projects_seen="${projects_seen} ${project} " if echo "${unwanted}" | grep -q "^${project}$"; then echo "warn: skipping spec generation of untracked formula: ${project}" >&2 @@ -66,8 +70,9 @@ gen_spec(){ project_name="$(get_spec project)" version="$(get_spec version)" - license="$(get_spec license)" license_csv="$(get_spec license_csv)" + ## Ideally we would query the license, but it is a heavy call. + license="$(echo "${license_csv}" | sed "s/,/ AND /g")" vendor="$(get_spec vendor)" packager="$(get_spec packager)" url="$(get_spec url)" @@ -121,9 +126,12 @@ gen_spec(){ if test "${2-}" = "test"; then if ! cmp -s "${target}" "${intended_target}"; then - echo "${0##*/}: error: File ${intended_target} is not up to date" >&2 - echo "${0##*/}: error: Update the spec with: ${0##/*} ${project}" >&2 - exit 1 + echo "error: ${intended_target} is not up to date" >&2 + fail=1 + else + if test -n "$(git diff --name-only "${intended_target}")"; then + echo "warn: ${intended_target} is up to date but it is not staged" >&2 + fi fi fi } @@ -142,16 +150,25 @@ untracked="$(git ls-files --exclude-standard --others salt/)" unwanted="$(printf %s"${ignored}\n${untracked}\n" \ | grep "^salt/\S\+/README.md" | cut -d "/" -f2 | sort -u)" -if test "${2-}" = "test"; then - gen_spec "${1}" test - exit +fail="" +gen_mode="" + +if test "${1-}" = "test"; then + gen_mode="test" + shift fi -if test -z "${1-}"; then +if echo "${@}" | grep -qE "(^scripts/| scripts/|/template.spec)" || test -z "${1-}"; then # shellcheck disable=SC2046 set -- $(find salt/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \ | sort -d | tr "\n" " ") fi + +projects_seen="" for p in "$@"; do - gen_spec "${p}" + gen_spec "${p}" ${gen_mode} done + +if test "${fail}" = "1" && test "${gen_mode}" = "test"; then + exit 1 +fi