CircleCI-Public / orb-tools-orb

Various tools for authoring and publishing CircleCI orbs
https://circleci.com/orbs/registry/orb/circleci/orb-tools
MIT License
51 stars 76 forks source link

feat: add source-dir to both lint and review workflows #160

Closed surecloud-meason closed 2 years ago

surecloud-meason commented 2 years ago

Description:

Added ability when using a monorepo structure to set the source directory for orb-tools/review and orb-tools/lint.

Motivation:

Require this to have a mono repo structure for different private orbs

Closes Issues:

orb-publisher commented 2 years ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/orb-tools?version=dev:46784c5d6310de61410674800e538a0679b9073d

KyleTryon commented 2 years ago

Ah ok so we do have a small snag.

The test files themselves refer to the src directory directly.

Example

result=$(yq '.display.source_url' "${REVIEW_TEST_DIR}src/@orb.yml")

This needs to work on CircleCI as well as locally, you should be able to run this command locally to run bats locally. I bet this was likely an accident at first, but this works locally because if REVIEW_TEST_DIR is unset, and you are in the project locally already, the directory becomes relative src/@orb.yml

You actually pointed out to me that two tests are not working due to an extra slash when run locally do to this quirk.

SOURCE_URL=$(yq '.display.source_url' "${REVIEW_TEST_DIR}/src/@orb.yml")

REVIEW_TEST_DIR is set at the top of the tests as ./

Ideally, we could have an accommodation that could easily work in both situations. It may be for users with a non-default directory, they must set an environment variable.

So we could have a new env var at the top of review.bats named ORB_SOURCE_DIR and it could be valued something like this:

ORB_DEFAULT_SRC_DIR="${REVIEW_TEST_DIR}src/"
ORB_SOURCE_DIR=${ORB_PARAM_SOURCE_DIR:-$ORB_DEFAULT_SRC_DIR}

With the above:

  1. If you are local with no env vars set manually the value becomes src/
  2. You can manually set ORB_SOURCE_DIR
surecloud-meason commented 2 years ago

@KyleTryon are the changes made what you expected?

orb-publisher commented 2 years ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/orb-tools?version=dev:f239e1b3ae515e96b72dc465cec8aa916a59e398

KyleTryon commented 2 years ago

@surecloud-meason This looks great thank you! Would you mind resolving the small conflict created, we want to keep both changes. The conflict comes from another PR we just added which adds a new parameter to the job. I can fix it too but given it yelled at me because it is also your master branch I figured I might ask first lol.

surecloud-meason commented 2 years ago

@KyleTryon conflict resolved

orb-publisher commented 2 years ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/orb-tools?version=dev:b35803c6a924a02fc414519114a7068a8f3c5ff1

KyleTryon commented 2 years ago

I made one last tiny fix to your branch, thank you very much @surecloud-meason !

orb-publisher commented 2 years ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/orb-tools?version=dev:88d47a6505f67dcdfba86ecb1fb1c419ba0db6ca

orb-publisher commented 2 years ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/orb-tools?version=dev:88d47a6505f67dcdfba86ecb1fb1c419ba0db6ca

orb-publisher commented 2 years ago

Your orb has been published to the CircleCI Orb Registry. You can view your published orb on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/orb-tools?version=11.3.0