image: docker.nix-community.org/nixpkgs/nix-flakes:nixos-23.11

definitions:
  steps:
   -  step: &build-and-checks
        name: Build and Checks
        script:
         -  ./.ci/bin/runner ./.ci/bin/build-and-check
        caches:
         -  cargo-home
         -  cargo-target-workaround
         -  nix-store

   -  step: &build-windows
        name: Build for Windows
        script:
         -  ./.ci/bin/nix-build fundamentum-edge-windows
        caches:
         -  cargo-home
         -  cargo-target-workaround
         -  nix-store
          
   -  step: &publish
        name: Publish to Crates.io
        script:
         -  ./.ci/bin/runner ./.ci/bin/publish
        # Note that other caches won't be needed as using artifacts from
        # `build-and-checks`.
        caches:
         -  cargo-home

  caches:
    cargo-home:
      key:
        files:
         -  Cargo.lock
         -  Cargo.toml
      path: $HOME/.cargo
    cargo-target-workaround: 
      path: .ci/.cache/cargo-target
    nix-store: 
      path: .ci/.cache/nix-store

pipelines:
  tags:
    '*':
     -  step:
          <<: *build-and-checks
          artifacts:
            - .ci/.cache/**
     -  step:
          <<: *publish
          trigger: manual

  branches:
    master:
     -  parallel:
         -  step: *build-and-checks
         -  step: *build-windows

  pull-requests:
    '**':
     -  parallel:
         -  step: *build-and-checks
         -  step: *build-windows