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; the ADR is in the # maintainer's environment repository). 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 org secret is used; the job token (secrets.GITHUB_TOKEN) clones the repository. on: # yamllint disable-line rule:truthy pull_request: branches: - main push: branches: - main tags: - 'v*' workflow_dispatch: {} permissions: contents: read # A newer push to the same pull request cancels the running run; a push to main or a tag # never cancels another run. A tag run has its own group, so it never shares one with the # main run of the same commit. concurrency: group: build-${{ github.event_name == 'pull_request' && github.ref || (github.ref_type == 'tag' && github.ref || github.sha) }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: build: runs-on: kamino-docker timeout-minutes: 30 # The ci image (images/ci, built by image.yml): tag for the release, digest enforced. container: image: git.rkdr.net/mortis/ci:0.2.14@sha256:301bdf3981014664aae2d2b8b283347c722980405b46c792499fcd2796890e87 env: PIP_DISABLE_PIP_VERSION_CHECK: "1" steps: - 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)" # The baked tools match the pin files unless this change touches them; then the # pinned tools are installed for this run, as before the ci image existed. - name: Check the baked tooling against the pins run: | if sha256sum --quiet -c /opt/ci-pins.sha256; then echo "The pin files match the ci image; using the baked tools." else echo "::warning::requirements-dev.txt or .pre-commit-config.yaml differ from the ci image; installing the pinned tools for this run." /opt/venv/bin/pip install --quiet -r requirements-dev.txt fi # 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" # ansible-galaxy dereferences symlinks when it builds, so a symlink in the source tree # reaches the archive as a regular file with the target's content, where # scripts/check_tarball.py cannot see it. Refuse them in the tree instead: this step # is the only guard against a file symlink. The two -prune paths below (./.venv, # ./.git) are skipped only because the build skips them too (galaxy.yml build_ignore, # and ansible-galaxy's own .git exclusion): the two lists must stay in step, and # tests/scripts/test_check_tarball.py fails when a pruned directory is not ignored. - name: Refuse symlinks in the source tree run: | links="$(find . -path ./.git -prune -o -path ./.venv -prune -o -type l -print)" if [ -n "$links" ]; then echo "::error::symlinks in the source tree would be dereferenced into the Collection archive:" echo "$links" exit 1 fi - 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 # The archive is what consumers get: only the allow list of scripts/check_tarball.py. - name: Check the archive contents run: | export PATH="/opt/venv/bin:$PATH" set -- /tmp/dist/mortis-kamino-*.tar.gz if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then echo "::error::expected exactly one tarball in /tmp/dist, found $# match(es): $*" exit 1 fi python3 scripts/check_tarball.py "$1" # 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 set -- /tmp/dist/mortis-kamino-*.tar.gz if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then echo "::error::expected exactly one tarball in /tmp/dist, found $# match(es): $*" exit 1 fi GALAXY_IMPORTER_CONFIG=/tmp/galaxy-importer.cfg \ python3 -m galaxy_importer.main "$1" # Sanity tests need the collection at ansible_collections//. - 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 reads tests/sanity/ignore-.txt and has no wildcard. # The committed ignore-common.txt applies to every core version: it is copied to the # file name of the installed core here, in this throwaway worktree only (plus the # lines of a committed ignore-.txt, for a finding of one version only). core="$(python3 -c 'import ansible.release as r; print(".".join(r.__version__.split(".")[:2]))')" case "$core" in [0-9]*.[0-9]*) ;; *) echo "::error::Cannot read the ansible-core version ($core)"; exit 1 ;; esac ignore="tests/sanity/ignore-${core}.txt" { cat tests/sanity/ignore-common.txt; if [ -f "$ignore" ]; then cat "$ignore"; fi; } > /tmp/ignore.new mv /tmp/ignore.new "$ignore" echo "Sanity ignore list for ansible-core ${core}: $(wc -l < "$ignore") lines" ansible-test sanity --requirements --color no