image: docker-registry.schukai.com:443/nixos-ci-devenv:latest

services:
  - docker:dind


variables:
  NIXOS_VERSION: "23.05"
  NIXPKGS_ALLOW_UNFREE: "1"
  NIXPKGS_ALLOW_INSECURE: "1"
  DOCKER_DRIVER: overlay2


stages:
  - tag
  - release


tag-it:
  stage: tag
  script:
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git config user.email "${GITLAB_USER_EMAIL}"
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git config user.name "${GITLAB_USER_NAME:-"Gitlab CI"}"
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git config credential.helper '!f() { echo "username=gitlab-ci-token"; echo "password=${CI_JOB_TOKEN}"; }; f'
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git config pull.rebase true
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git config http.sslVerify "false"
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git remote set-url origin https://pad:${GITLAB_TOKEN}@${CI_REPOSITORY_URL#*@}
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git fetch --all --tags --unshallow
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git reset --hard origin/master
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git checkout $CI_COMMIT_REF_NAME
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git pull origin $CI_COMMIT_REF_NAME
    - /nix/store/55i9ylml0w72j6qy33izic8ch14rslb0-version/bin/version auto --git --verbose 
    - /nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git push origin $CI_COMMIT_REF_NAME
  only:
    ## regex to x.y branches and master
    - master
  except:
    - tags

release:
  stage: release
  image:
    name: goreleaser/goreleaser
    entrypoint: [\'\']
  only:
    - tags
  variables:
    # Disable shallow cloning so that goreleaser  can diff between tags to
    GIT_DEPTH: 0
  script:
    - /nix/store/cgzhkcv3wvcd2zlblv4y0vhjvw479467-goreleaser-1.22.1/bin/goreleaser release --clean

