Skip to content

Commit

Permalink
Allow ansible-lint action to be used from composite workflows (#4481)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
3 people authored Jan 20, 2025
1 parent 971d330 commit 1746028
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
description: Expected return code from ansible-lint. Default is 0. Used for self-testing purposes.
required: false
default: "0"
gh_action_ref:
description: The branch, tag, or commit to use for ansible-lint.
default: ""
required: false
runs:
using: composite
steps:
Expand All @@ -39,6 +43,17 @@ runs:
echo "working_directory=${{ github.workspace }}" >> $GITHUB_OUTPUT
fi
# If this action is imported as part of another composite action, the value of github.action_ref is the branch/commit/tag of the source action, not this one.
# This allows a user to override it using the input variable
- name: Determine github action ref
shell: bash
run: |
action_ref="${{ inputs.gh_action_ref }}"
if [[ -z "${{ inputs.gh_action_ref }}" ]]; then
action_ref="${{ github.action_ref || 'main' }}"
fi
echo "ACTION_REF=${action_ref}" >> "$GITHUB_ENV"
# 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.
Expand All @@ -48,7 +63,7 @@ runs:
id: get_reqs
shell: bash
env:
GH_ACTION_REF: ${{ github.action_ref || 'main' }}
GH_ACTION_REF: ${{ env.ACTION_REF }}
working-directory: ${{ steps.inputs.outputs.working_directory }}
run: |
reqs_file=$(git rev-parse --show-toplevel)/.git/ansible-lint-requirements.txt
Expand All @@ -66,7 +81,7 @@ runs:
- name: Install ansible-lint
shell: bash
env:
GH_ACTION_REF: ${{ github.action_ref || 'main' }}
GH_ACTION_REF: ${{ env.ACTION_REF }}
# 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' }}
Expand Down

0 comments on commit 1746028

Please sign in to comment.