Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CICD Docs (Github/Gitlab) #743

Merged
merged 9 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,30 +152,9 @@ Documentation: https://docs.styra.com/regal/rules/style/prefer-snake-case
> will likely generate a lot of violations. You can do this by passing the `--disable-category style` flag to
> `regal lint`.

### GitHub Actions
### Using Regal in your build pipeline!

If you'd like to run Regal in GitHub actions, please consider using [`setup-regal`](https://github.com/StyraInc/setup-regal).
A simple `.github/workflows/lint.yml` to run regal on PRs could look like this, where `policy` contains Rego files:

```yaml
name: Regal Lint
on:
pull_request:
jobs:
lint-rego:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: StyraInc/setup-regal@v1
with:
# For production workflows, use a specific version, like v0.16.0
version: latest

- name: Lint
run: regal lint --format=github ./policy
```

Please see [`setup-regal`](https://github.com/StyraInc/setup-regal) for more information.
To ensure Regal's rules are enforced consistently in your project or organization, we've made it easy to run Regal as part of your builds. See the docs on [Using Regal in your build pipeline](./docs/cicd.md) to learn more about how to set up Regal to lint your policies on every commit or pull request.

## Rules

Expand Down
49 changes: 49 additions & 0 deletions docs/cicd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Using Regal in your build pipeline

Its possible to use Regal to lint your Rego policies in your CI/CD pipeline(s)!

This document will guide you on how to do so.

## GitHub Actions

If you'd like to run Regal in GitHub actions, please consider using [`setup-regal`](https://github.com/StyraInc/setup-regal).
A simple `.github/workflows/lint.yml` to run regal on PRs could look like this, where `policy` contains Rego files:

```yaml
name: Regal Lint
on:
pull_request:
jobs:
lint-rego:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: StyraInc/setup-regal@v1
with:
# For production workflows, use a specific version, like v0.22.0
version: latest

- name: Lint
run: regal lint --format=github ./policy
```

Please see [`setup-regal`](https://github.com/StyraInc/setup-regal) for more information.

## GitLab CICD

To use Regal in GitLab CI/CD, you could for example use the following stage in your `.gitlab-ci.yml`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably obvious to someone who uses GitLab, but the GH example above specifically mentions running Regal on PRs, while this sentence says nothing about when/how this is triggered. Could you add that? 🙂


```yaml
regal_lint_policies:
stage: regal-lint
image:
# For production workflows, use a specific version, like v0.22.0
name: ghcr.io/styrainc/regal:latest
entrypoint: ['/bin/sh', '-c']
script:
- regal lint ./policy
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
```

The above will run Regal on the `policy` directory when a merge request is created or updated.
Loading