Skip to content

Commit

Permalink
Rename filter with auto_discovery in kustomize action (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Pedro Rodrigues <hpedrorodrigues@users.noreply.github.com>
  • Loading branch information
hpedrorodrigues and hpedrorodrigues authored Jul 18, 2024
1 parent 2f233ef commit 01ef762
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
8 changes: 4 additions & 4 deletions envsubst/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ inputs:
required: false
default: ''
branding:
icon: 'file-text'
color: 'gray-dark'
icon: file-text
color: gray-dark
runs:
using: 'docker'
image: 'Dockerfile'
using: docker
image: Dockerfile
20 changes: 10 additions & 10 deletions kustomize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ An action to validate kustomization files and outputs using [Kustomize].
with:
# Strategy to use for detecting kustomization directories.
# Possible values
# - none: use all kustomization directories found in the repository.
# - modified: use kustomization directories found based on the modified files.
# - all: use all kustomization directories found in the repository.
# - modified: use kustomization directories found based on the modified files (git).
# - static: use the provided paths to kustomization directories.
filter: ''
auto_discovery: ''

# Paths to kustomization directories to validate (separated by space).
# This is only used when filter is set to "static".
# This is only used when `auto_discovery` is set to "static".
path: ''

# Log level to use for the validation.
Expand Down Expand Up @@ -44,7 +44,7 @@ An action to validate kustomization files and outputs using [Kustomize].
# or
- uses: hpedrorodrigues/actions/kustomize@v1.0.2
with:
filter: 'none'
auto_discovery: 'all'
```
### Validate modified kustomization directories
Expand All @@ -55,15 +55,15 @@ An action to validate kustomization files and outputs using [Kustomize].
fetch-depth: 0 # This is required to allow this action to detect modified files.
- uses: hpedrorodrigues/actions/kustomize@v1.0.2
with:
filter: 'modified'
auto_discovery: 'modified'
```
### Validate specific kustomization directories
```yaml
- uses: hpedrorodrigues/actions/kustomize@v1.0.2
with:
filter: 'static'
auto_discovery: 'static'
path: 'kustomize/base kustomize/overlays/production'
```
Expand All @@ -72,7 +72,7 @@ An action to validate kustomization files and outputs using [Kustomize].
```yaml
- uses: hpedrorodrigues/actions/kustomize@v1.0.2
with:
filter: 'none'
auto_discovery: 'all'
log_level: 'verbose'
```
Expand All @@ -81,7 +81,7 @@ An action to validate kustomization files and outputs using [Kustomize].
```yaml
- uses: hpedrorodrigues/actions/kustomize@v1.0.2
with:
filter: 'none'
auto_discovery: 'all'
flags: '--load-restrictor=LoadRestrictionsNone --enable-alpha-plugins'
```
Expand All @@ -94,7 +94,7 @@ An action to validate kustomization files and outputs using [Kustomize].
kustomize: latest
- uses: hpedrorodrigues/actions/kustomize@v1.0.2
with:
filter: 'none'
auto_discovery: 'all'
```
[Kustomize]: https://kustomize.io
14 changes: 7 additions & 7 deletions kustomize/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ name: kustomize
author: Pedro Rodrigues
description: Validate kustomization files and outputs.
inputs:
filter:
auto_discovery:
description: Strategy to use for filtering kustomization directories.
required: false
default: 'none'
default: all
path:
description: Paths to kustomization directories.
required: false
default: ''
log_level:
description: Log level to use.
required: false
default: 'quiet'
default: quiet
flags:
description: Extra flags to pass to kustomize.
required: false
default: ''
branding:
icon: 'wind'
color: 'blue'
icon: wind
color: blue
runs:
using: 'composite'
using: composite
steps:
- run: echo "${{ github.action_path }}" >> "${GITHUB_PATH}"
shell: sh
- run: entrypoint.sh
shell: sh
env:
INPUT_FILTER: ${{ inputs.filter }}
INPUT_AUTO_DISCOVERY: ${{ inputs.auto_discovery }}
INPUT_PATH: ${{ inputs.path }}
INPUT_LOG_LEVEL: ${{ inputs.log_level }}
INPUT_FLAGS: ${{ inputs.flags }}
26 changes: 13 additions & 13 deletions kustomize/entrypoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ main() {
sh "${BATS_TEST_DIRNAME}/entrypoint.sh"
}

@test 'Should validate all kustomization files when filter is set to none' {
export INPUT_FILTER='none'
@test 'Should validate all kustomization files when auto_discovery is set to all' {
export INPUT_AUTO_DISCOVERY='all'
export INPUT_PATH=''
export INPUT_LOG_LEVEL='quiet'

Expand All @@ -34,8 +34,8 @@ main() {
[[ "${output}" == *'PASS: ./.github/extra/kustomize/simple'* ]]
}

@test 'Should validate all paths provided when filter is set to static' {
export INPUT_FILTER='static'
@test 'Should validate all paths provided when auto_discovery is set to static' {
export INPUT_AUTO_DISCOVERY='static'
export INPUT_PATH="${SIMPLE} ${VARIANT_PRD}"
export INPUT_LOG_LEVEL='quiet'

Expand All @@ -47,18 +47,18 @@ main() {
[ "${lines[3]}" = "PASS: ${VARIANT_PRD}" ]
}

@test 'Should fail when an invalid value is given for filter' {
export INPUT_FILTER="invalid-${RANDOM}"
@test 'Should fail when an invalid value is given for auto_discovery' {
export INPUT_AUTO_DISCOVERY="invalid-${RANDOM}"
export INPUT_PATH=''
export INPUT_LOG_LEVEL='quiet'

run main
[ "${status}" -eq 1 ]
[ "${output}" = "Error: invalid value provided for filter: \"${INPUT_FILTER}\"." ]
[ "${output}" = "Error: invalid value provided for auto_discovery: \"${INPUT_AUTO_DISCOVERY}\"." ]
}

@test 'Should fail when an invalid value is given for log level' {
export INPUT_FILTER='none'
export INPUT_AUTO_DISCOVERY='all'
export INPUT_PATH=''
export INPUT_LOG_LEVEL="invalid-${RANDOM}"

Expand All @@ -68,18 +68,18 @@ main() {
[ "${lines[1]}" = 'Accepted values are "verbose" or "quiet".' ]
}

@test 'Should fail when no path is given and filter is set to static' {
export INPUT_FILTER='static'
@test 'Should fail when no path is given and auto_discovery is set to static' {
export INPUT_AUTO_DISCOVERY='static'
export INPUT_PATH=''
export INPUT_LOG_LEVEL='quiet'

run main
[ "${status}" -eq 1 ]
[ "${lines[0]}" = 'Error: `static` filter requires a value for input `path`.' ]
[ "${lines[0]}" = 'Error: `static` mode requires a value for input `path`.' ]
}

@test 'Should print no changes when no kustomizations are detected and filter is set to none' {
export INPUT_FILTER='none'
@test 'Should print no changes when no kustomizations are detected and auto_discovery is set to all' {
export INPUT_AUTO_DISCOVERY='all'
export INPUT_PATH=''
export INPUT_LOG_LEVEL='quiet'

Expand Down
10 changes: 5 additions & 5 deletions kustomize/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if ${VERBOSE:-false}; then
set -o xtrace
fi

readonly filter="${INPUT_FILTER:-}"
readonly auto_discovery="${INPUT_AUTO_DISCOVERY:-}"
readonly path="${INPUT_PATH:-}"
readonly log_level="${INPUT_LOG_LEVEL:-}"
readonly flags="${INPUT_FLAGS:-}"
Expand All @@ -17,8 +17,8 @@ if [ "${log_level}" != 'quiet' ] && [ "${log_level}" != 'verbose' ]; then
exit 1
fi

case "${filter}" in
none)
case "${auto_discovery}" in
all)
readonly kustomization_directories="$(
find . -type f \( -name kustomization.yml -o -name kustomization.yaml \) \
| xargs -I {} dirname {}
Expand All @@ -44,14 +44,14 @@ case "${filter}" in
;;
static)
if [ -z "${path}" ]; then
>&2 echo 'Error: `static` filter requires a value for input `path`.'
>&2 echo 'Error: `static` mode requires a value for input `path`.'
exit 1
fi

readonly kustomization_directories="${path}"
;;
*)
>&2 echo "Error: invalid value provided for filter: \"${filter}\"."
>&2 echo "Error: invalid value provided for auto_discovery: \"${auto_discovery}\"."
exit 1
;;
esac
Expand Down
6 changes: 3 additions & 3 deletions setup-sphynx/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Setup Sphynx
author: Pedro Rodrigues
description: Set up Sphynx CLI.
branding:
icon: 'award'
color: 'gray-dark'
icon: award
color: gray-dark
runs:
using: 'composite'
using: composite
steps:
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
Expand Down

0 comments on commit 01ef762

Please sign in to comment.