-
Notifications
You must be signed in to change notification settings - Fork 664
/
action.yml
92 lines (87 loc) · 3.56 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
name: run-ansible-lint
description: Run Ansible Lint
author: Ansible by Red Hat <[email protected]>
branding:
icon: shield
color: red
inputs:
args:
description: Arguments to be passed to ansible-lint command.
required: false
default: ""
setup_python:
description: If false, this action will not setup python and will instead rely on the already installed python.
required: false
default: true
working_directory:
description: The directory where to run ansible-lint from. Default is `github.workspace`.
required: false
default: ""
requirements_file:
description: Path to the requirements YAML file to install role and collection dependencies.
required: false
default: ""
expected_return_code:
description: Expected return code from ansible-lint. Default is 0. Used for self-testing purposes.
required: false
default: "0"
runs:
using: composite
steps:
- name: Process inputs
id: inputs
shell: bash
run: |
if [[ -n "${{ inputs.working_directory }}" ]]; then
echo "working_directory=${{ inputs.working_directory }}" >> $GITHUB_OUTPUT
else
echo "working_directory=${{ github.workspace }}" >> $GITHUB_OUTPUT
fi
# Due to GHA limitation, caching works only for files within GITHUB_WORKSPACE
# folder, so we are forced to stick this temporary file inside .git, so it
# will not affect the linted repository.
# https://github.com/actions/toolkit/issues/1035
# https://github.com/actions/setup-python/issues/361
- name: Generate .git/ansible-lint-requirements.txt
id: get_reqs
shell: bash
env:
GH_ACTION_REF: ${{ github.action_ref || 'main' }}
working-directory: ${{ steps.inputs.outputs.working_directory }}
run: |
reqs_file=$(git rev-parse --show-toplevel)/.git/ansible-lint-requirements.txt
echo "reqs_file=$reqs_file" >> $GITHUB_OUTPUT
wget --output-document=$reqs_file https://raw.githubusercontent.com/ansible/ansible-lint/$GH_ACTION_REF/.config/requirements-lock.txt
- name: Set up Python
if: inputs.setup_python == 'true'
uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: ${{ steps.get_reqs.outputs.reqs_file }}
python-version: "3.11"
- name: Install ansible-lint
shell: bash
env:
GH_ACTION_REF: ${{ github.action_ref || 'main' }}
# 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' }}
# SETUPTOOLS_SCM_PRETEND_VERSION=${{ github.action_ref || 'main' }}
run: |
cd $GITHUB_ACTION_PATH
pip install "ansible-lint[lock] @ git+https://github.com/ansible/ansible-lint@$GH_ACTION_REF"
ansible-lint --version
- name: Install role and collection dependencies from requirements file
if: inputs.requirements_file != ''
shell: bash
working-directory: ${{ steps.inputs.outputs.working_directory }}
run: ansible-galaxy install -r ${{ inputs.requirements_file }}
- name: Run ansible-lint
shell: bash
working-directory: ${{ steps.inputs.outputs.working_directory }}
run: |
exit_code=0
expected_exit_code=${{ inputs.expected_return_code }}
ansible-lint ${{ inputs.args }} || exit_code=$?
if [ "$exit_code" != "$expected_exit_code" ]; then echo "Command failed: got '$exit_code', expected '$expected_exit_code'"; exit 1; fi