version: 2.1

orbs:
  orb-tools: circleci/orb-tools@10.0
  bats: circleci/bats@1.0
  shellcheck: circleci/shellcheck@2.0

# Pipeline Parameters
## These parameters are used internally by orb-tools. Skip to the Jobs section.
parameters:
  run-integration-tests:
    description: An internal flag to prevent integration test from running before a development version has been created.
    type: boolean
    default: false
  dev-orb-version:
    description: >
      The development version of the orb to test.
      This value is automatically adjusted by the "trigger-integration-tests-workflow" job to correspond with the specific version created by the commit and should not be edited.
      A "dev:alpha" version must exist for the initial pipeline run.
    type: string
    default: "dev:alpha"

jobs:
  integration-test-1:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout
      - backstage-entity-validator/validate

workflows:
  # Prior to producing a development orb (which requires credentials) basic validation, linting, and even unit testing can be performed.
  # This workflow will run on every commit
  test-pack:
    jobs:
      - orb-tools/lint # Lint Yaml files
      - orb-tools/pack # Pack orb source
      - shellcheck/check:
          dir: ./src/scripts
          exclude: SC2148
      # Publish development version(s) of the orb.
      - orb-tools/publish-dev:
          orb-name: roadiehq/backstage-entity-validator
          requires:
            - orb-tools/lint
            - orb-tools/pack
            - shellcheck/check
  publish-orb:
    jobs:
      # Publish a semver version of the orb. relies on
      # the commit subject containing the text "[semver:patch|minor|major|skip]"
      # as that will determine whether a patch, minor or major
      # version will be published or if publishing should
      # be skipped.
      # e.g. [semver:patch] will cause a patch version to be published.
      - orb-tools/dev-promote-prod-from-commit-subject:
          orb-name: roadiehq/backstage-entity-validator
          add-pr-comment: false
          fail-if-semver-not-indicated: true
          publish-version-tag: false
          filters:
            branches:
              only:
                - master
                - main
