Skip to content

Commit

Permalink
Improve testing of github action
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Sep 19, 2024
1 parent 9d63816 commit 33ab172
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Self test for ansible-lint@${{ github.action_ref || 'main' }}
- name: Self test 1
uses: ./
with:
# basically we only lint linter own configuration, which should be passing.
args: .ansible-lint
- name: Self test 2
uses: ./
with:
# basically we only lint linter own configuration, which should be passing.
args: .ansible-lint
working_directory: .
- name: Self test 3
uses: ./
with:
# basically we only lint linter own configuration, which should be passing.
args: .ansible-lint
working_directory: docs
expected_return_code: "2" # expected to fail because the given argument does not exist in this folder
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
Expand Down
17 changes: 14 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
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:
Expand All @@ -41,19 +45,22 @@ runs:
# 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: |
wget --output-document=${{ steps.inputs.outputs.working_directory }}/.git/ansible-lint-requirements.txt https://raw.githubusercontent.com/ansible/ansible-lint/$GH_ACTION_REF/.config/requirements-lock.txt
reqs_file=$(git rev-parse --show-toplevel/.git/ansible-lint-requirements.txt)
echo "reqs_file=$reqs_file\n" >> $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.inputs.outputs.working_directory }}/.git/ansible-lint-requirements.txt
cache-dependency-path: ${{ steps.get_reqs.outputs.reqs_file }}
python-version: "3.11"

- name: Install ansible-lint
Expand All @@ -78,4 +85,8 @@ runs:
- name: Run ansible-lint
shell: bash
working-directory: ${{ steps.inputs.outputs.working_directory }}
run: ansible-lint ${{ inputs.args }}
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
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": "fdff861b226b13b711dd7f94301ed5becd6dc5d8d4e872f909d4a3d8133d600a",
"etag": "57fd2147c4c70dfd7dea6b3960bb8ed910c01c693de168cc7ac2b8cf527a1166",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/meta.json"
},
"meta-runtime": {
Expand Down

0 comments on commit 33ab172

Please sign in to comment.