项目作者: b4b4r07

项目描述 :
Run conftest test command with GitHub Actions
高级语言: Shell
项目地址: git://github.com/b4b4r07/action-conftest.git
创建时间: 2020-02-12T18:02:14Z
项目社区:https://github.com/b4b4r07/action-conftest

开源协议:

下载


action-conftest

Run conftest test command with GitHub Actions

You can use the fixed version from: Releases

Usage

A whole example is here:

  1. name: conftest
  2. on: [pull_request]
  3. jobs:
  4. conftest:
  5. name: conftest test
  6. runs-on: ubuntu-latest
  7. steps:
  8. - name: Checkout
  9. uses: actions/checkout@v1
  10. - name: Get changed objects
  11. uses: b4b4r07/action-changed-objects@master
  12. with:
  13. added: 'true'
  14. deleted: 'false'
  15. modified: 'true'
  16. id: objects
  17. - name: Run conftest test against changed files
  18. uses: b4b4r07/action-conftest@master
  19. if: steps.objects.outputs.changed
  20. with:
  21. files: ${{ steps.objects.outputs.changed }}
  22. matches: '*.yaml'
  23. id: conftest
  24. - name: Post conftest command result to GitHub comment
  25. uses: b4b4r07/action-github-comment@master
  26. if: always() && steps.conftest.outputs.result
  27. with:
  28. body: |
  29. ## conftest test result
  1. ${{ steps.conftest.outputs.result }}
  2. ```
  3. env:
  4. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  5. LOG: trace
  1. If you want to run [conftest](https://github.com/instrumenta/conftest) command against only changed config files, you need to use [b4b4r07/action-changed-objects](https://github.com/b4b4r07/action-changed-objects) to get the changed files in Git commit. It defaults to compare with checkout-ed branch and origin/master branch.
  2. In addition, you can filter the changed files, for example, let's say you want to test only changed JSON and YAML files:
  3. ```yaml
  4. with:
  5. files: ${{ steps.objects.outputs.changed }}
  6. matches: '*.json manifests/*.yaml'

Besides, if you want to post the conftest test command result on your pull requests, you need to set the step Post conftest command result to GitHub comment. The contents of body is the message itself. You can configure it as Markdown. For more details, please see also b4b4r07/action-github-comment.

To put the comment on GitHub even if the previous conftest step is failed, you need to set always() condition like this:

  1. if: always() && steps.conftest.outputs.result

This means the comment will be posted to GitHub regardless of previous build step but at least the output of previous step needs to be not empty.

Customizing

inputs

The following are optional as step.with keys

Name Type Description Default
path String Path to directory where config files are located .
policy String Path to the Rego policy files directory policy
files String A list of config file to be tested by conftest. Separated by a space
matches String A list of cases to be tested (e.g. “.yaml .json”). Separated by a space
namespace String Namespace name running with conftest testing
all_namespaces Boolean Enable —all-namespaces flag false

When providing a path and files at the same time, files will be attempted first, then falling back on path if the files can not be got from.

outputs

The following outputs can be accessed via ${{ steps.<step-id>.outputs }} from this action

Name Type Description
result String Outputs of conftest command

environment variables

The following are as step.env keys

Name Description
n/a n/a

License

MIT