Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ jobs:
[[ "$DESTINATION" == "s3://centreon-download/public/smoke-test/smoke-test-1.0.0.tar.gz" ]]
tar tzf "$SOURCE_FILE" | grep -q "^smoke-test-1.0.0/sources-delivery/action.yml$"

# checks the one package definition of this repository, the smoke test of packaging/nfpm
- name: Smoke test the wiring of packaging/check-descriptions
uses: $/packaging/check-descriptions

# most callers of the packaging actions run in a container, where paths differ
smoke-container:
name: smoke (${{ matrix.name }})
Expand All @@ -127,11 +131,23 @@ jobs:
include:
- name: debian
image: debian:12@sha256:1d04200c2ece1d4d75a2a6f8e11ebce7d86a2ae28b34bb2c9cbb3ee9f4953e75
distrib: bookworm
package: smoke-test_1.0.0-7+deb12u1_all.deb
- name: almalinux
image: almalinux:9@sha256:02df05719ef287ebd0df0a1eedb9172a00bd70703aed7b25660e426b8e0d6047
distrib: el9
package: smoke-test-1.0.0-7.el9.noarch.rpm
container:
image: ${{ matrix.image }}
env:
NFPM_VERSION: "2.43.4"
NFPM_SHA256: cafb544650cb0305d1b164fc0ab261eb77a81af324e18011282d326b326d20fb
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Smoke test packaging/parse-distrib in a container
id: parse-distrib-smoke
uses: $/packaging/parse-distrib
Expand All @@ -144,3 +160,36 @@ jobs:
DISTRIB_FAMILY_MAJOR: ${{ steps.parse-distrib-smoke.outputs.distrib_family_major }}
run: |
[[ "$PACKAGE_DISTRIB_NAME" == "el9" && "$DISTRIB_FAMILY_MAJOR" == "el9" ]]

- name: Install nfpm
run: |
if command -v apt-get > /dev/null; then
apt-get update
apt-get install --yes --no-install-recommends ca-certificates curl
fi
curl --fail --silent --show-error --location --output /tmp/nfpm.tar.gz \
"https://github.com/goreleaser/nfpm/releases/download/v${NFPM_VERSION}/nfpm_${NFPM_VERSION}_Linux_x86_64.tar.gz"
echo "${NFPM_SHA256} /tmp/nfpm.tar.gz" | sha256sum --check
tar --extract --gzip --file /tmp/nfpm.tar.gz --directory /usr/local/bin nfpm

# a real, unsigned package, cached under a key nothing reads
- name: Smoke test packaging/nfpm in a container
uses: $/packaging/nfpm
with:
nfpm_file_pattern: packaging/tests/smoke/*.yaml
distrib: ${{ matrix.distrib }}
version: "1.0.0"
release: "7"
arch: all
commit_hash: ${{ github.sha }}
allow_unsigned: "true"
cache_key: smoke-test-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.distrib }}

- name: Check the smoke-tested package
env:
PACKAGE: ${{ matrix.package }}
run: |
ls -l
[[ -f "$PACKAGE" ]]
# the signing key file never lands in the workspace
[[ -z "$(find . -name '*.gpg')" ]]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ The repository is a set of **packages**: a package is a top-level directory, ver
and released on its own, that holds one action or several actions built on the same
code. Each package documents its actions in its own `README.md`.

| Package | Actions |
| ------------------------------------------ | ------------------------------------------------------------------- |
| [`pulp`](pulp/README.md) | `pulp/package-delivery`, `pulp/promote-to-stable`, `pulp/setup-cli` |
| [`download-site`](download-site/README.md) | `download-site/sources-delivery`, `download-site/publication` |
| [`packaging`](packaging/README.md) | `packaging/parse-distrib` |
| Package | Actions |
| ------------------------------------------ | --------------------------------------------------------------------------- |
| [`pulp`](pulp/README.md) | `pulp/package-delivery`, `pulp/promote-to-stable`, `pulp/setup-cli` |
| [`download-site`](download-site/README.md) | `download-site/sources-delivery`, `download-site/publication` |
| [`packaging`](packaging/README.md) | `packaging/parse-distrib`, `packaging/nfpm`, `packaging/check-descriptions` |

## Usage

Expand Down
130 changes: 127 additions & 3 deletions packaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

Actions shared by the packaging jobs.

| Action | Purpose |
| ------------------------- | ----------------------------------------------------------------------- |
| `packaging/parse-distrib` | Give the package extension, the naming and the family of a distribution |
| Action | Purpose |
| ------------------------------ | ----------------------------------------------------------------------- |
| `packaging/parse-distrib` | Give the package extension, the naming and the family of a distribution |
| `packaging/nfpm` | Build rpm or deb packages with nfpm, cache them and upload them |
| `packaging/check-descriptions` | Check that every package has its own synopsis and rpm summary |

## Parse distrib

Expand Down Expand Up @@ -56,3 +58,125 @@ caller that needs the former value reads `distrib_family_major`.
Add its line to `parse-distrib.sh`, to this table and to the tests, and to the table of
the `pulp` package (`pulp/lib/parse-distrib.sh`), which keeps its own copy: a test fails
when the two disagree.

## Package with nfpm

```yaml
- name: Package
uses: centreon/github-actions/packaging/nfpm@packaging/v1
with:
nfpm_file_pattern: "packaging/*.yaml"
distrib: ${{ matrix.distrib }}
major_version: ${{ needs.get-environment.outputs.major_version }}
minor_version: ${{ needs.get-environment.outputs.minor_version }}
release: ${{ needs.get-environment.outputs.release }}
arch: all
commit_hash: ${{ github.sha }}
cache_key: ${{ github.run_id }}-${{ github.sha }}-${{ matrix.distrib }}
rpm_gpg_key: ${{ secrets.RPM_GPG_SIGNING_KEY }}
rpm_gpg_signing_key_id: ${{ secrets.RPM_GPG_SIGNING_KEY_ID }}
rpm_gpg_signing_passphrase: ${{ secrets.RPM_GPG_SIGNING_PASSPHRASE }}
```

The action builds one package per nfpm configuration matching `nfpm_file_pattern` (one
or several patterns) into the working directory, saves the packages in the cache under
`cache_key` and, with `upload_artifacts: "true"`, uploads them as an artifact kept one
day. `nfpm` 2.39.0 or later must be installed (the packaging images provide it): it is
the first version reading variables in a description, and an older one fails the step.

This repository is public and holds no key: the signing key is an input, read from the
secrets of the calling repository. It is written outside the workspace and removed when
the step ends. An rpm without `rpm_gpg_key` fails the step, unless `allow_unsigned:
"true"` asks for unsigned packages; a deb is not signed.

### What a configuration can read

nfpm replaces `${NAME}` by the variable `NAME` in most fields of a configuration
(`version`, `release`, `description`, `depends`, the signature...), and in the `src` and
`dst` of a `contents` entry that sets `expand: true`. nfpm runs in the directory of the
configuration: its relative paths start there. The action gives it:

| Variable | Value |
| -------------------------------------------------- | --------------------------------------------------------------------------------- |
| `${VERSION}` | `version`, or `major_version.minor_version` |
| `${RELEASE}` | `release`; for a deb, followed by the distribution (`7+deb12u1`) |
| `${DIST}` | For an rpm, the distribution (`.el9`); empty for a deb |
| `${ARCH}` | `arch` |
| `${COMMIT_HASH}` | `commit_hash` |
| `${MAJOR_VERSION}`, `${NEXT_MAJOR_VERSION}` | `major_version` and the one after it; only when `major_version` is given |
| `${RPM_SIGNING_KEY_FILE}`, `${RPM_SIGNING_KEY_ID}` | The signing key of an rpm; empty otherwise, which is how nfpm skips the signature |
| The variables of the job | As they are: set them with `env:` on the job, or through `$GITHUB_ENV` |

`NEXT_MAJOR_VERSION` follows the versions of Centreon: six months later before 26.10
(`24.04` then `24.10`), the next month since (`26.10` then `26.11`).

```yaml
description: |
Centreon broker.
Commit: ${COMMIT_HASH}
contents:
- src: "./module.so"
dst: "/usr/lib64/lua/${LUA_VERSION}/module.so"
expand: true
file_info:
owner: "@APACHE_USER@"
```

nfpm does not read the owner of a file from the environment. That is the one thing the
action writes in a configuration: `@APACHE_USER@` and `@APACHE_GROUP@` become `apache`
for an rpm and `www-data` for a deb. Any other `@UPPERCASE@` placeholder fails the step,
and nothing is replaced inside the packaged files: a workflow that needs a value in an
installation script writes it there before calling the action.

### Options

| Input | Default | Effect |
| ---------------- | -------------------- | --------------------------------------------------------------------------------------------------- |
| `deb_release` | `release` | Release number of a deb, when it is not the one of an rpm |
| `allow_unsigned` | `false` | Builds unsigned rpm packages when there is no key, instead of failing |
| `deb_copyright` | `false` | Adds `copyright.<license>`, or the `LICENSE.md` of the repository, to a deb as its `copyright` file |
| `artifact_name` | `packages-<distrib>` | Name of the uploaded artifact; the default ends with `-<arch>` when `arch` is given |

### Switching from a local copy

The local `package-nfpm` and `package` actions replaced `@NAME@` placeholders with sed
and differ between repositories. Every repository changes `@COMMIT_HASH@` to
`${COMMIT_HASH}` in its configurations and stops passing `package_extension` and
`stability`. Then:

| Local copy | Inputs | In the repository |
| --------------------------------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| centreon | `deb_copyright: "true"`, `allow_unsigned: "true"` | A step removes the development files, sets `PHP_MIN_VERSION` and `PHP_MAX_VERSION`, and writes the PHP version in the two installation scripts of centreon-web |
| centreon-modules | `deb_copyright: "true"` | Same step, with the four `PHP_*` variables; sourceguardian-loader reads `${PHP_MIN_VERSION}` and `${PHP_MODULE_API}` with `expand: true` |
| centreon-collect | `deb_copyright: "true"` | The Lua version of the `env/.env.<distrib>` files moves to the configuration that reads it |
| centreon-plugins | `version`; `deb_release`: `release` on unstable and canary, `1` otherwise | Nothing else |
| centreon-stream-connector-scripts | `version`; `deb_release` like centreon-plugins where the release is not kept | A step sets `LUA_VERSION`; the configurations read `${LUA_VERSION}` and `${VERSION}` instead of `@luaver@` and `@VERSION@`, with `expand: true` on the entries using them. Its debs take the suffix of the other projects: `1+deb12u1` instead of `1~bookworm` |
| centreon-agent | `version` | Nothing else |

The packaging of centreon-plugin-packs builds one package per pack from a template and
keeps its own action.

## Check package descriptions

```yaml
- name: Check package descriptions
uses: centreon/github-actions/packaging/check-descriptions@packaging/v1
```

A lint step, to run once per pull request after a checkout. It reads every tracked YAML
file that sits under a `packaging` directory and holds `name`, `arch` and `version`: the
nfpm package definitions. The first line of `description` is the synopsis of a deb (`apt
search`, `apt show`), and `rpm.summary` the one of an rpm, the synopsis standing for it
when it is not set. The step fails when:

- a description is empty, or an rpm summary is blank;
- two packages share a synopsis or a summary, whatever the case;
- the synopsis or the summary of a `<package>-debuginfo` package does not name
`<package>`.

`paths` limits the check to the files it lists, and `working_directory` runs it in
another directory. The script needs PyYAML: it uses the one of the runner, and installs
a pinned version in a temporary environment when there is none.

It is the `check-package-descriptions.py` script of centreon, centreon-collect and
centreon-modules, unchanged: a repository replaces its copy with this step.
22 changes: 22 additions & 0 deletions packaging/check-descriptions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Check package descriptions"
description: "Check that every nfpm package of a repository has its own synopsis and rpm summary"
inputs:
paths:
description: "Files to check, separated by spaces or new lines. Default: every tracked YAML file"
required: false
default: ""
working_directory:
description: "Directory of the repository to check"
required: false
default: "."

runs:
using: "composite"
steps:
- name: Check package descriptions
shell: bash
working-directory: ${{ inputs.working_directory }}
env:
PATHS: ${{ inputs.paths }}
# the variable, not the context: only the variable is right in a container job
run: '"${GITHUB_ACTION_PATH}/check.sh"'
99 changes: 99 additions & 0 deletions packaging/check-descriptions/check-descriptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python3
"""Check the synopsis and summary of the nfpm package definitions.

The first line of the nfpm description is the deb synopsis (apt search/show),
rpm.summary is the rpm one. Both must be unique within the repository.
"""

import collections
import subprocess
import sys

import yaml


class Loader(yaml.SafeLoader):
"""SafeLoader ignoring custom tags (gorgone configuration uses !include)."""


Loader.add_multi_constructor("!", lambda loader, suffix, node: None)

DEBUGINFO_SUFFIX = "-debuginfo"


def first_line(text):
lines = [line.strip() for line in str(text or "").splitlines()]
return next((line for line in lines if line), "")


def load_packages(paths):
"""Return {path: nfpm definition} for the nfpm files found in paths."""
packages = {}
for path in paths:
if "packaging" not in path.split("/")[:-1]:
continue
with open(path, encoding="utf-8") as stream:
content = yaml.load(stream, Loader=Loader)
if isinstance(content, dict) and all(key in content for key in ("name", "arch", "version")):
packages[path] = content
return packages


def check(packages):
"""Return a list of (path, message) errors."""
errors = []
seen = {"synopsis": collections.defaultdict(list), "rpm summary": collections.defaultdict(list)}

for path, package in sorted(packages.items()):
name = str(package["name"])
synopsis = first_line(package.get("description"))
# nfpm uses the first description line when rpm.summary is not set
raw_summary = (package.get("rpm") or {}).get("summary")
summary = synopsis if raw_summary in (None, "") else first_line(raw_summary)

if not synopsis:
errors.append((path, f"{name}: the description is empty"))
continue
if not summary:
errors.append((path, f"{name}: the rpm summary is blank"))
continue

fields = {"synopsis": synopsis, "rpm summary": summary}
for field, value in fields.items():
seen[field][value.casefold()].append((path, name))
if name.endswith(DEBUGINFO_SUFFIX):
base_name = name[: -len(DEBUGINFO_SUFFIX)]
if base_name not in value.replace(",", " ").rstrip(".").split():
errors.append((path, f"{name}: the {field} does not mention {base_name}: '{value}'"))

for field, values in seen.items():
for owners in values.values():
if len(owners) < 2:
continue
names = ", ".join(name for _, name in owners)
for path, name in owners:
errors.append((path, f"{name}: the {field} is shared by several packages ({names})"))

return errors


def main():
paths = sys.argv[1:] or subprocess.run(
["git", "ls-files", "*.yaml", "*.yml"], capture_output=True, text=True, check=True
).stdout.splitlines()

packages = load_packages(paths)
if not packages:
print("::error::no nfpm package definition found")
return 1

errors = check(packages)
for path, message in errors:
print(f"::error file={path}::{message}")

print(f"{len(packages)} package definitions checked, {len(errors)} error(s)")
return 1 if errors else 0


if __name__ == "__main__":
sys.exit(main())
Loading
Loading