Files
Kamino/.gitea/workflows/build.yml
T
Defame1297andClaude Sonnet 5.5 0bc8d19775 fix(ci): harden the build and image workflows after review
Pass ref and repository values to run steps as environment instead of
interpolating them into the script (a tag name may contain shell
metacharacters). In the image workflow: refuse tags that are not
vMAJOR.MINOR.PATCH[-prerelease] before anything runs, purge exactly the
packages the prepare step added instead of autoremove and fail on any
package or /etc file difference from the base image, send the registry
write probe with an empty body, and remove the registry credential after
the push also when the build fails.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-10-24 21:10:20 +00:00

118 lines
4.4 KiB
YAML

name: Build
# Builds the Collection tarball and checks it. On a v* tag it also checks the release
# invariants of ADR 0004 (annotated tag, tag equals v + galaxy.yml version). Nothing is
# uploaded: the tarball is built in a temporary directory and discarded. Releases are
# consumed by git tag, so there is no publish step. No secrets are used.
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
push:
branches:
- main
tags:
- 'v*'
workflow_dispatch: {}
permissions:
contents: read
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: kamino-docker
timeout-minutes: 30
container:
image: ubuntu:24.04@sha256:68ee22004a9109b44973313b02ff7b1de250f1de0f5ecb628d73f579aaff33ac
env:
DEBIAN_FRONTEND: noninteractive
PIP_DISABLE_PIP_VERSION_CHECK: "1"
steps:
- name: Install OS packages
run: |
apt-get update
apt-get install -y --no-install-recommends \
ca-certificates git python3 python3-venv python3-pip
- name: Checkout the commit under test
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: http.extraheader
GIT_CONFIG_VALUE_0: "AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}"
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
REF: ${{ github.ref }}
# Passed as environment, never interpolated into the script: a tag name may
# contain shell metacharacters.
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
run: |
git clone "$REPO_URL" .
git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; }
# Make sure the tag object itself is present (not only the commit it points at).
if [ "$REF_TYPE" = "tag" ]; then
git fetch origin "+refs/tags/${REF_NAME}:refs/tags/${REF_NAME}"
fi
echo "Checked out $(git rev-parse HEAD)"
- name: Install pinned tooling
run: |
python3 -m venv /opt/venv
/opt/venv/bin/pip install --quiet -r requirements-dev.txt
# ADR 0004, Release process: the tag is annotated and equals v + the galaxy.yml version.
- name: Check the release tag
if: github.ref_type == 'tag'
env:
TAG: ${{ github.ref_name }}
run: |
export PATH="/opt/venv/bin:$PATH"
type="$(git cat-file -t "refs/tags/$TAG")"
if [ "$type" != "tag" ]; then
echo "::error::$TAG is a lightweight tag; releases must be annotated (git tag -a)"
exit 1
fi
version="$(python3 -c 'import sys, yaml; print(yaml.safe_load(open("galaxy.yml"))["version"])')"
if [ "$TAG" != "v$version" ]; then
echo "::error::tag $TAG does not match galaxy.yml version $version (expected v$version)"
exit 1
fi
echo "Tag $TAG is annotated and matches galaxy.yml version $version"
- name: Build the Collection
run: |
export PATH="/opt/venv/bin:$PATH"
mkdir -p /tmp/dist
ansible-galaxy collection build --force --output-path /tmp/dist .
ls -l /tmp/dist
sha256sum /tmp/dist/*.tar.gz
# galaxy-importer without ansible-test and without Docker (ADR 0004, Collection
# repo gates). The importer reads its configuration from this file.
- name: Run galaxy-importer
run: |
export PATH="/opt/venv/bin:$PATH"
cat > /tmp/galaxy-importer.cfg <<'CFG'
[galaxy-importer]
RUN_ANSIBLE_TEST = False
RUN_ANSIBLE_LINT = False
LOCAL_IMAGE_DOCKER = False
CFG
GALAXY_IMPORTER_CONFIG=/tmp/galaxy-importer.cfg \
python3 -m galaxy_importer.main /tmp/dist/mortis-kamino-*.tar.gz
# Sanity tests need the collection at ansible_collections/<namespace>/<name>.
- name: Run ansible-test sanity
run: |
export PATH="/opt/venv/bin:$PATH"
# No --venv: its delegation virtualenv is created inside the content tree and fails
# the shebang and symlinks tests.
mkdir -p /tmp/ac/ansible_collections/mortis
git worktree add --detach /tmp/ac/ansible_collections/mortis/kamino HEAD
cd /tmp/ac/ansible_collections/mortis/kamino
ansible-test sanity --requirements --color no