queue_workers 0.5.1

A Redis-backed job queue system for Rust applications
Documentation
version: 2.1

orbs:
  rust: circleci/rust@1

jobs:
  code-quality:
    docker:
      - image: cimg/rust:1.86.0
    resource_class: medium
    environment:
      DISABLE_TEST_LOGGING: 1
    steps:
      - checkout
      - restore_cache:
          keys:
            - cargo-cache-v1-{{ arch }}-{{ checksum "Cargo.lock" }}
            - cargo-cache-v1-{{ arch }}-
      - run:
          name: Install Rust components
          command: |
            rustup component add rustfmt clippy
      - run:
          name: Check formatting
          command: cargo fmt -- --check
      - run:
          name: Run clippy
          command: cargo clippy -- -D warnings
      - save_cache:
          key: cargo-cache-v1-{{ arch }}-{{ checksum "Cargo.lock" }}
          paths:
            - ~/.cargo/registry
            - ~/.cargo/git
            - target

  test:
    docker:
      - image: cimg/rust:1.86.0
    resource_class: medium
    environment:
      DISABLE_TEST_LOGGING: 1
    steps:
      - checkout
      - setup_remote_docker:
          docker_layer_caching: true
      - restore_cache:
          keys:
            - docker-compose-v1-{{ checksum "docker-compose.yml" }}
            - docker-compose-v1-
      - run:
          name: Install Docker Compose
          command: |
            if ! command -v docker-compose &> /dev/null; then
              sudo curl -SL "https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
              sudo chmod +x /usr/local/bin/docker-compose
            fi
      - run:
          name: Build and run tests
          command: |
            DOCKER_BUILDKIT=1 docker-compose build test
            docker-compose run --rm test
      - save_cache:
          key: docker-compose-v1-{{ checksum "docker-compose.yml" }}
          paths:
            - /usr/local/bin/docker-compose

  publish:
    docker:
      - image: cimg/rust:1.86.0
    resource_class: medium
    environment:
      DISABLE_TEST_LOGGING: 1
    steps:
      - checkout
      - restore_cache:
          keys:
            - cargo-cache-v1-{{ arch }}-{{ checksum "Cargo.lock" }}
            - cargo-cache-v1-{{ arch }}-
      - restore_cache:
          keys:
            - cargo-audit-v1-{{ arch }}
      - run:
          name: Install and run cargo-audit
          command: |
            if ! command -v cargo-audit &> /dev/null; then
              cargo install cargo-audit --no-default-features
            fi
            cargo audit
      - run:
          name: Build documentation
          command: cargo doc --no-deps
      - run:
          name: Package verification
          command: |
            cargo package --list
            cargo package
      - run:
          name: Publish package
          command: |
            VERSION="v$(grep -oP '^version = "\K[^"]+' Cargo.toml)"
            echo "Publishing version ${VERSION}"
            cargo publish --token ${CRATES_IO_TOKEN}

      - run:
          name: Create git tag
          command: |
            VERSION="v$(grep -oP '^version = "\K[^"]+' Cargo.toml)"
            git config user.email "armhamos@gmail.com"
            git config user.name "arm-cci"
            git tag -a "${VERSION}" -m "Release ${VERSION}"
            git push origin "${VERSION}"
      - save_cache:
          key: cargo-cache-v1-{{ arch }}-{{ checksum "Cargo.lock" }}
          paths:
            - ~/.cargo/registry
            - ~/.cargo/git
            - target
      - save_cache:
          key: cargo-audit-v1-{{ arch }}
          paths:
            - ~/.cargo/bin/cargo-audit

workflows:
  version: 2
  build_test_publish:
    jobs:
      - code-quality
      - test:
          requires:
            - code-quality
      - publish:
          context: crates-io-publish-context
          requires:
            - test
          filters:
            branches:
              only: master