stages:
    - build
    - test
    - release

default:
    image: registry.gitlab.com/dmoonfire/nix-flake-docker:latest

build:
    stage: build
    script:
        - nix profile install 'nixpkgs#fontconfig'
        - nix develop --command scripts/setup.sh
        - nix develop --command scripts/build.sh
    rules:
        - if: $CI_COMMIT_BRANCH
    artifacts:
        expire_in: 1 week
        paths:
            - "*.pdf"
            - "*.epub"
            - "*.mobi"
            - "*.docx"
            - "*.html"

test:
    stage: test
    script:
        - nix develop --command scripts/setup.sh
        - nix develop --command scripts/test.sh
    rules:
        - if: $CI_COMMIT_BRANCH
        - if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME

release:
    stage: release
    script:
        - nix profile install 'nixpkgs#fontconfig'
        - nix develop --command scripts/setup.sh
        - nix develop --command scripts/release.sh
    rules:
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    artifacts:
        paths:
            - "*.pdf"
            - "*.epub"
            - "*.mobi"
            - "*.docx"
            - "*.html"