> For the complete CircleCI developer hub index, see [llms.txt](https://circleci.com/developer/llms.txt)

# oshimayoan/compare-url

Reconstruct $CIRCLE_COMPARE_URL environment variable. (See https://github.com/iynere/compare-url-orb for full README.)


## Commands

### reconstruct

Reconstruct CIRCLE_COMPARE_URL in a command, output it to an eponymous file (because each step in a CircleCI job receives a fresh shell environment by default, storing it as an environment variable would not typically persist across steps), and persist it to a workspace.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `circle-token` | env_var_name | CIRCLE_TOKEN | Your CircleCI API token, defaults to $CIRCLE_TOKEN |
| `debug` | boolean | false | Additional debugging output for folks developing the orb |
| `project-path` | string | ~/project | Absolute path to your project's base directory, necessary for running git commands
 |
| `when` | enum | always | When should this command run? |

### use

Use the CIRCLE_COMPARE_URL created in the `reconstruct` command (or job) to do some parameterized logic/work. Designed to be run after the `reconstruct` command, or in a job downstream from the `reconstruct` job. Saves CIRCLE_COMPARE_URL value stored in file to a local environment variable and transforms it into a true commit range value (stored as a COMMIT_RANGE environment variable), ready to be utilized as desired.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `attach-workspace` | boolean | false | Attach a workspace for this command to use? Useful when this orb's `reconstruct` job is called upstream in a given workflow
 |
| `custom-logic` | string | echo "What should COMMIT_RANGE ($COMMIT_RANGE) be used for?" | What should be done with the commit information created by the `reconstruct` command/job? For an example, see the following: https://circleci.com/orbs/registry/orb/iynere/compare-url#usage-simple-monorepo-flow-using-command
 |
| `step-name` | string | Evaluate/use CIRCLE_COMPARE_URL | Specify a custom step name for this command, if desired |
| `workspace-root` | string | . | Workspace root path (either an absolute path or a path relative to the working directory), defaults to "." (the working directory)
 |

## Jobs

### reconstruct

Reconstruct CIRCLE_COMPARE_URL in a job,  output it to an eponymous file (because each step in a CircleCI job receives a fresh shell environment by default, storing it as an environment variable would not typically persist across steps), and persist it to a workspace.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `circle-token` | env_var_name | CIRCLE_TOKEN | Your CircleCI API token, defaults to $CIRCLE_TOKEN
 |
| `debug` | boolean | false | Additional debugging output for folks developing the orb
 |
| `project-path` | string | ~/project | Absolute path to your project's base directory, necessary for running git commands
 |
| `resource-class` | enum | medium | Run this job with a smaller resource_class option, if a given project has access to configurable resources.
 |

## Examples

### simple-monorepo-flow-using-command

Execute some action only for modified files from this commit. This example presupposes a monorepo of orbs, of which we only want to publish those with modifications. (See https://discuss.circleci.com/t/does-circleci-2-0-work-with-monorepos for details.)


```yaml
jobs:
  publish:
    docker:
      - image: circleci/circleci-cli
    steps:
      - checkout
      - compare-url/reconstruct
      - compare-url/use:
          custom-logic: |
            for ORB in folder-containing-orb-subdirs/*/; do

              orbname=$(basename $ORB)

              if [[ $(git diff $COMMIT_RANGE --name-status | grep "$orbname") ]]; then

                echo "publishing ${orbname}"

                circleci orb publish ${ORB}/orb.yml namespace/${orbname}@version
              else
                echo "${orbname} not modified; no need to publish"
              fi
            done
          step-name: Publish modified orbs
orbs:
  compare-url: iynere/compare-url@x.y.z
version: 2.1
workflows:
  publish-orbs:
    jobs:
      - publish
```

### simple-monorepo-flow-using-job

Execute some action only for modified files from this commit. This example presupposes a monorepo of orbs, of which we only want to publish those with modifications. (See https://discuss.circleci.com/t/does-circleci-2-0-work-with-monorepos for details.)


```yaml
jobs:
  publish:
    docker:
      - image: circleci/circleci-cli
    steps:
      - checkout
      - compare-url/use:
          attach-workspace: true
          command: |
            for ORB in folder-containing-orb-subdirs/*/; do

              orbname=$(basename $ORB)

              if [[ $(git diff $COMMIT_RANGE --name-status | grep "$orbname") ]]; then

                echo "publishing ${orbname}"

                circleci orb publish ${ORB}/orb.yml namespace/${orbname}@version
              else
                echo "${orbname} not modified; no need to publish"
              fi
            done
          step-name: Publish modified orbs
orbs:
  compare-url: iynere/compare-url@x.y.z
version: 2.1
workflows:
  publish-orbs:
    jobs:
      - compare-url/reconstruct
      - publish:
          requires:
            - compare-url/reconstruct
```