---
include:
  - project: shore/ci-templates
    file: templates/pre-commit.yml

stages:
  - test
  - build

variables:
  VERSION: 0.0.99.1

build:
  stage: build
  image: buildpack-deps:bullseye
  before_script:
    - apt-get update
    - >-
      apt-get install -y
      bash-completion
      cmake
      golang
      go-md2man
      meson
      podman
      shellcheck
      systemd
    - >-
      git clone
      --depth=1
      "--branch=$VERSION"
      https://github.com/containers/toolbox.git
    - cd toolbox
  script:
    - meson -Dprofile_dir=/etc/profile.d builddir
    - ninja -C builddir
  after_script:
    # I would have prefered to use ninja install with a different prefix, but
    # alas the Bash completion doesn't take the prefix into account nor can it
    # be overwritten, so I went for a manual approach.
    - mkdir -p output/usr/local/share/man/man1
    - cp toolbox/builddir/doc/* output/usr/local/share/man/man1/
    - mkdir -p output/usr/local/bin
    - cp toolbox/builddir/src/toolbox output/usr/local/bin/
    - mkdir -p output/usr/share/bash-completion/completions
    # yamllint disable-line rule:line-length
    - cp toolbox/completion/bash/toolbox output/usr/share/bash-completion/completions/
    - tar -C output -czf toolbox.tar.gz ./
  artifacts:
    paths:
      - toolbox/builddir/src/toolbox
      - toolbox/builddir/doc/
      - toolbox/builddir/meson-logs/
      - toolbox/builddir/.ninja_log
      - toolbox/completion/bash/toolbox
      - toolbox.tar.gz
