image: registry.nic.cz/turris/logc

stages:
  - build
  - test
  - coverage
  - release

## Build stage ###################################################################
build:
  stage: build
  script:
    - ./bootstrap
    - ./configure
    - make
  artifacts:
    when: on_failure
    expire_in: 1 week
    paths:
    - config.log

dist:
  stage: build
  script:
    - ./bootstrap
    - ./configure
    - make dist
  artifacts:
    expire_in: 1 month
    paths:
      - logc-*.tar.gz
      - logc-*.tar.xz
      - logc-*.zip

## Test stage ####################################################################
.test:
  stage: test
  needs: [build]
  before_script:
      - ./bootstrap
      - ./configure --enable-tests --enable-valgrind --enable-linters

.test-check:
  extends: .test
  artifacts:
    when: on_failure
    expire_in: 1 week
    paths:
    - 'test-suite*.log'
    - 'tests/*/*.log'
    - 'tests/*/*.trs'

check:
  extends: .test-check
  script:
    - make check

distcheck:
  extends: .test-check
  script:
    - make distcheck

valgrind:
  extends: .test-check
  script:
    - make check-valgrind

lint:
  allow_failure: true
  extends: .test
  script:
    - make lint

## Code Coverage stage ###########################################################
coverage:
  stage: coverage
  needs: [check]
  script:
    - ./bootstrap
    - ./configure --enable-tests --enable-code-coverage
    - make check-code-coverage V=1
    - mv logc-*-coverage logc-coverage
  coverage: '/lines\.\.\.\.\.\.: (\d+.\d+%)/'
  artifacts:
    expire_in: 1 month
    expose_as: 'Code Coverage'
    paths:
    - 'logc-coverage/'

## Release creation ##############################################################
release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  rules:
    - if: '$CI_COMMIT_TAG'
  needs:
    - job: dist
      artifacts: true
  before_script:
    - apk update
    - apk add bash curl
  script:
    - .gitlab-ci/release.sh
