Skip to content

Commit

Permalink
Add Github Marketplace Action (#3476)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed May 22, 2023
1 parent bc9ae85 commit cd10983
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 7 deletions.
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,38 @@
[![Ansible-lint rules explanation](https://img.shields.io/badge/Ansible--lint-rules-blue.svg)](https://ansible-lint.readthedocs.io/rules/)
[![Discussions](https://img.shields.io/badge/Discussions-gray.svg)](https://github.com/ansible/ansible-lint/discussions)
[![GitHub Actions CI/CD](https://github.com/ansible/ansible-lint/workflows/gh/badge.svg)](https://github.com/ansible/ansible-lint/actions?query=workflow%3Agh+branch%3Amain+event%3Apush)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/ansible/ansible-lint.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ansible-community/ansible-lint/context:python)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

# Ansible-lint

`ansible-lint` checks playbooks for practices and behavior that could
potentially be improved. As a community backed project ansible-lint supports
potentially be improved. As a community-backed project ansible-lint supports
only the last two major versions of Ansible.

[Visit the Ansible Lint docs site](https://ansible-lint.readthedocs.io/)

# Using ansible-lint as a GitHub Action

This action allows you to run `ansible-lint` on your codebase without having to
install it yourself.

```yaml
# .github/workflows/ansible-lint.yml
name: ansible-lint
on:
pull_request:
branches: ["stable", "release/v*"]
jobs:
build:
name: Ansible Lint # Naming the build is important to use it as a status check
runs-on: ubuntu-latest
steps:
- name: Run ansible-lint
uses: ansible/ansible-lint@v6
```

For more details, see [ansible-lint-action].

# Contributing

Please read [Contribution guidelines] if you wish to contribute.
Expand All @@ -22,9 +43,9 @@ Please read [Contribution guidelines] if you wish to contribute.
The ansible-lint project is distributed as [GPLv3] due to use of [GPLv3] runtime
dependencies, like `ansible` and `yamllint`.

For historical reasons, its own code-base remains licensed under a more
liberal [MIT] license and any contributions made are accepted as being made
under original [MIT] license.
For historical reasons, its own code-base remains licensed under a more liberal
[MIT] license and any contributions made are accepted as being made under
original [MIT] license.

# Authors

Expand All @@ -34,6 +55,9 @@ ansible-lint was created by [Will Thames] and is now maintained as part of the
[ansible]: https://ansible.com
[contribution guidelines]: https://ansible-lint.readthedocs.io/contributing
[gplv3]: https://github.com/ansible/ansible-lint/blob/main/COPYING
[mit]: https://github.com/ansible/ansible-lint/blob/main/docs/licenses/LICENSE.mit.txt
[mit]:
https://github.com/ansible/ansible-lint/blob/main/docs/licenses/LICENSE.mit.txt
[red hat]: https://redhat.com
[will thames]: https://github.com/willthames
[ansible-lint-action]:
https://ansible-lint.readthedocs.io/installing/#installing-from-source-code
51 changes: 51 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: ansible-lint
description: Run Ansible Lint
author: Ansible by Red Hat <info@ansible.com>
branding:
icon: shield
color: red
inputs:
path:
description: >
Specific path to lint instead of the default `.`. Multiple arguments are
not supported and you will need to alter linter configuration to
accommodate other use cases.
required: false
# That default is just a placeholder workaround for no arguments use-case
# Feeding "." or empty string to ansible-lint makes it believe it is a role
default: --show-relpath
args:
description: deprecated
deprecationMessage: >
Arbitrary args are no longer accepted, please use path instead and
linter own configuration file to change its behavior.
required: false
default: ""
runs:
using: composite
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # needed by setuptools-scm
submodules: true

- name: Set up Python
uses: actions/setup-python@v4
with:
cache: pip
python-version: "3.11"

- name: Install ansible-lint
shell: bash
# We need to set the version manually because $GITHUB_ACTION_PATH is not
# a git clone and setuptools-scm would not be able to determine the version.
# git+https://github.com/ansible/ansible-lint@${{ github.action_ref || 'main' }}
run: |
cd $GITHUB_ACTION_PATH
SETUPTOOLS_SCM_PRETEND_VERSION=${{ github.action_ref || 'main' }} pip install ".[lock]"
ansible-lint --version
- name: Run ansible-lint
shell: bash
run: ansible-lint ${{ inputs.path }}
33 changes: 33 additions & 0 deletions docs/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,36 @@ pip3 install git+https://github.com/ansible/ansible-lint
[pipx]: https://pypa.github.io/pipx/
[pypa user guide]:
https://packaging.python.org/en/latest/tutorials/installing-packages/#ensure-pip-setuptools-and-wheel-are-up-to-date

## Installing Ansible Lint as a GitHub Action

To use the action simply create a file `.github/workflows/ansible-lint.yml` with
content similar to the example below:

```yaml
# .github/workflows/ansible-lint.yml
name: ansible-lint
on:
pull_request:
branches: ["stable", "release/v*"]
jobs:
build:
name: Ansible Lint # Naming the build is important to use it as a status check
runs-on: ubuntu-latest
steps:
- name: Run ansible-lint
uses: ansible/ansible-lint@v6
```

Due to limitations on how GitHub Actions are processing arguments, we do not
plan to provide extra options. You will have to make use of
[ansible-lint own configuration file](https://ansible-lint.readthedocs.io/configuring/)
for altering its behavior.

To also enable [dependabot][dependabot] automatic updates the newer versions of
ansible-lint action you should create a file similar to
[.github/dependabot.yml][.github/dependabot.yml]

[dependabot]: https://docs.github.com/en/code-security/dependabot
[.github/dependabot.yml]:
https://github.com/ansible/ansible-lint/blob/main/.github/dependabot.yml#L13-L19
2 changes: 1 addition & 1 deletion src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json"
},
"meta": {
"etag": "7b5ac2250a4ae70ef657cd9906e6c13f4941daba71724e3342b7fa7e7239a334",
"etag": "230d2476c1e1f60cd05cba2ac7c42ef658588b1f502e68e85404fd524ef3b3b2",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/meta.json"
},
"meta-runtime": {
Expand Down

0 comments on commit cd10983

Please sign in to comment.