# Bitbucket Pipelines

Source: https://apigenie.pl/docs/ci/bitbucket-pipelines

A `bitbucket-pipelines.yml` that lints, checks the formatting of and compares an OpenAPI file in
every pull request, as three parallel steps: each has its own status on the pipeline, and the lint
report feeds the Tests tab. [Any CI system](/docs/ci) explains the pieces: the commands, the
reports, the installation and the comparison with the destination branch.

**Unchecked.** The file follows the Bitbucket Pipelines documentation and has not run on a
repository on Bitbucket. A run on one, passed or failed, reported in an
[issue](https://github.com/mykulyak/api-genie/issues), makes it checked.

## The pipeline

```yaml
# bitbucket-pipelines.yml
image: node:22

pipelines:
  pull-requests:
    '**':
      - parallel:
          - step:
              name: Lint
              script:
                - npm install -g @mykulyak/api-genie
                - mkdir -p test-results
                - apigenie lint --formatter junit api/openapi.yaml > test-results/lint.xml
          - step:
              name: Check formatting
              script:
                - npm install -g @mykulyak/api-genie
                - apigenie format --check api/openapi.yaml
          - step:
              name: Breaking changes
              script:
                - npm install -g @mykulyak/api-genie
                - git fetch --depth=1 origin "$BITBUCKET_PR_DESTINATION_BRANCH"
                - git show FETCH_HEAD:api/openapi.yaml > base.yaml
                - apigenie diff base.yaml api/openapi.yaml
```

`pull-requests` runs the pipeline for every pull request, where `BITBUCKET_PR_DESTINATION_BRANCH`
names the destination branch. Bitbucket finds JUnit reports on its own, in a `test-results` or
`test-reports` directory at the root of the clone or up to three levels below, with no declaration
in the file. The install repeats in each step, because the steps run in parallel in their own
containers.

## What the pull request shows

- The status of the pipeline on the pull request, with the three steps and their status. A failed
  pipeline blocks the merge once the merge checks of the repository require a successful build.
- The Tests tab of the pipeline, from the JUnit report: a failed test per lint issue, named
  `apigenie.<rule>`, with the message; warnings are failed tests too, on a step that passed.
- The logs of the steps: the files that would change, and the changes with their severity.

Annotations on the lines of the pull request, Code Insights, take a call to the Reports API from the
step, which the file does not make.
