use_compute_credits: true

task:
  name: Test
  alias: test
  persistent_worker:
    labels:
      name: dev-mini
    resources:
      tart-vms: 1
  build_script:
    - swift build
  test_script:
    # Add /usr/sbin to PATH, otherwise testDiskutilInfo() fails to locate "diskutil"
    - export PATH=$PATH:/usr/sbin
    - swift test
  integration_test_script:
    - codesign --sign - --entitlements Resources/tart-dev.entitlements --force .build/debug/tart
    - export PATH=$(pwd)/.build/arm64-apple-macosx/debug:$PATH
    # Run integration tests
    - cd integration-tests
    - python3 -m venv --symlinks venv
    - source venv/bin/activate
    - pip install -r requirements.txt
    - pytest --verbose --junit-xml=pytest-junit.xml
    - go test -v ./...
  pytest_junit_result_artifacts:
    path: "integration-tests/pytest-junit.xml"
    format: junit

task:
  name: Markdown Lint
  only_if: $CIRRUS_BRANCH != 'gh-pages' && changesInclude('**.md')
  container:
    image: node:latest
  install_script: npm install -g markdownlint-cli
  lint_script: markdownlint --config=docs/.markdownlint.yml docs/

task:
  name: Lint
  alias: lint
  macos_instance:
    image: ghcr.io/cirruslabs/macos-runner:tahoe
  lint_script:
    - swift package plugin --allow-writing-to-package-directory swiftformat --cache ignore --lint --report swiftformat.json .
  always:
    swiftformat_report_artifacts:
      path: swiftformat.json
      format: swiftformat

task:
  only_if: $CIRRUS_TAG == ''
  env:
    matrix:
      BUILD_ARCH: arm64
      BUILD_ARCH: x86_64
  name: Build ($BUILD_ARCH)
  alias: build
  macos_instance:
    image: ghcr.io/cirruslabs/macos-runner:tahoe
  build_script: swift build --arch $BUILD_ARCH --product tart
  sign_script: codesign --sign - --entitlements Resources/tart-dev.entitlements --force .build/$BUILD_ARCH-apple-macosx/debug/tart
  binary_artifacts:
    path: .build/$BUILD_ARCH-apple-macosx/debug/tart

task:
  name: Deploy Documentation
  only_if: $CIRRUS_BRANCH == 'main'
  container:
    image: ghcr.io/squidfunk/mkdocs-material:latest
    registry_config: ENCRYPTED[!cf1a0f25325aa75bad3ce6ebc890bc53eb0044c02efa70d8cefb83ba9766275a994b4831706c52630a0692b2fa9cfb9e!]
  env:
    DEPLOY_TOKEN: ENCRYPTED[!45ed45666558902ed1c2400add734ec063103bec31841847e8c8764802fca229bfa6d85c690e16ad159e047574b48793!]
  deploy_script:
    - git config --global user.name "Cirrus CI"
    - git config --global user.name "hello@cirruslabs.org"
    - git remote set-url origin https://$DEPLOY_TOKEN@github.com/cirruslabs/tart/
    - mkdocs --verbose gh-deploy --force --remote-branch gh-pages
