Skip to content

Commit

Permalink
feat: add support for validate-inputs subcomand (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Frantz <andrew.frantz@stjude.org>
  • Loading branch information
adthrasher and a-frantz authored Feb 4, 2025
1 parent 320d7ea commit ae50c53
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 62 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
FROM rust:1.82
FROM ghcr.io/stjude-rust-labs/sprocket:v0.10.1
WORKDIR /app

COPY . .

RUN cargo install sprocket

ENTRYPOINT ["sprocket"]
CMD ["--help"]
68 changes: 58 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,88 @@

# Sprocket GitHub Action

This action uses [Sprocket](https://github.com/stjude-rust-labs/sprocket) to validate and optionally lint WDL documents.
This action provides select functionality of the [Sprocket](https://github.com/stjude-rust-labs/sprocket) command line tool for use in CI/CD pipelines.

## Inputs
## `check` | `lint`

### `lint`
The `check` and `lint` subcommands perform static analysis on WDL documents. The `lint: true` option additionally enables linting rules. The `lint` subcommand is an alias for `check` with linting enabled.

**Optional** Whether to run linting in addition to validation. Boolean, valid choices: ["true", "false"]
### Inputs

### `exclude-patterns`
#### `lint`

**Optional** Whether to run linting in addition to validation. Boolean, valid choices: ["true", "false"].

#### `exclude-patterns`

**Optional** Comma separated list of patterns to exclude when searching for WDL files.

### `deny-warnings`
#### `deny-warnings`

**Optional** If specified, Sprocket `check` will fail if any `warnings` are produced.

### `deny-notes`
#### `deny-notes`

**Optional** If specified, Sprocket `check` will fail if any `notes` are produced.

### `except`
#### `except`

**Optional** If specified, then the listed rules will be excepted from all `sprocket check` reports. Multiple rules can be specified as a comma-separated list, e.g. `CallInputSpacing,CommandSectionMixedIndentation`. Valid options can be found at: [analysis rules](https://github.com/stjude-rust-labs/wdl/blob/main/wdl-analysis/RULES.md) and [lint rules](https://github.com/stjude-rust-labs/wdl/blob/main/wdl-lint/RULES.md).

## Example usage
### Example usage

```
```yaml
uses: stjude-rust-labs/sprocket-action@main
with:
action: check
lint: true
exclude-patterns: template,test
except: TrailingComma,ContainerValue
```
The action `lint` can be specified and is equivalent to specifying `action: check` and `lint: true`.

```yaml
uses: stjude-rust-labs/sprocket-action@main
with:
action: lint
exclude-patterns: template,test
except: TrailingComma,ContainerValue
```

## `validate-inputs`

Validates an input JSON against a task or workflow input schema.

### Inputs

#### wdl_files

A comma-separated list of WDL documents containing a task or workflow for which to check inputs.

#### inputs_files

A matching comma-separated list of JSON format inputs file for the task(s)/workflow(s). Ordering must match `wdl_files` as no checking will be performed.

### Example usage

```yaml
uses: stjude-rust-labs/sprocket-action@main
with:
action: validate-inputs
wdl_files: "tools/bwa.wdl"
inputs_files: "inputs/bwa.json"
```

Multiple files can be specified as well.
```yaml
uses: stjude-rust-labs/sprocket-action@main
with:
action: validate-inputs
wdl_files: "tools/bwa.wdl,tools/star.wdl"
inputs_files: "inputs/bwa.json,inputs/star.wdl"
```

## License and Legal

This project is licensed as either [Apache 2.0][license-apache] or
Expand Down
15 changes: 14 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ branding:
icon: 'check-circle'
color: 'blue'
inputs:
# General options
action:
description: "Sprocket subcommand to run."
required: true
default: 'check'
# Options for `check` and `lint` subcommands
lint:
description: "Whether to lint the WDL document"
description: "Whether to lint WDL documents."
required: false
default: 'false'
exclude-patterns:
Expand All @@ -25,6 +31,13 @@ inputs:
description: 'Comma separated list of rules to exclude from Sprocket check.'
required: false
default: ''
# Options for `validate-inputs` subcommand
wdl_files:
description: "Path to the WDL document for which to validate inputs."
required: false
inputs_files:
description: "Path to the JSON file containing inputs to validate."
required: false
outputs:
status:
description: "The status of the check"
Expand Down
133 changes: 85 additions & 48 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,107 @@
set -euo pipefail

echo "===configuration==="
echo "action: $INPUT_ACTION"
echo "lint: $INPUT_LINT"
echo "exceptions: $INPUT_EXCEPT"
echo "warnings: $INPUT_WARNINGS"
echo "notes: $INPUT_NOTES"
echo "patterns: $INPUT_PATTERNS"
echo "wdl_files: $INPUT_WDL_FILES"
echo "inputs_files: $INPUT_INPUTS_FILES"

lint=""
exceptions=""
if [ $INPUT_ACTION = "check" ] || [ $INPUT_ACTION = "lint" ]; then
echo "Checking WDL files."
lint=""
exceptions=""
if [ $INPUT_LINT = "true" ] || [ $INPUT_ACTION = "lint" ]; then
lint="--lint"
fi

if [ $INPUT_LINT = "true" ]; then
lint="--lint"
fi
if [ -n "$INPUT_EXCEPT" ]; then
echo "Excepted rule(s) provided."
for exception in $(echo $INPUT_EXCEPT | sed 's/,/ /')
do
exceptions="$exceptions --except $exception"
done
fi

if [ -n "$INPUT_EXCEPT" ]; then
echo "Excepted rule(s) provided."
for exception in $(echo $INPUT_EXCEPT | sed 's/,/ /')
do
exceptions="$exceptions --except $exception"
done
fi
warnings=""

warnings=""
if [ ${INPUT_WARNINGS} = "true" ]; then
warnings="--deny-warnings"
fi

if [ ${INPUT_WARNINGS} = "true" ]; then
warnings="--deny-warnings"
fi
notes=""

if [ ${INPUT_NOTES} = "true" ]; then
notes="--deny-notes"
fi

notes=""
exclusions=${INPUT_PATTERNS}

if [ ${INPUT_NOTES} = "true" ]; then
notes="--deny-notes"
fi
if [ -n "$exclusions" ]; then
echo "Exclusions provided. Writing to .sprocket.yml."
echo -n "" > .sprocket.yml
for exclusion in $(echo $exclusions | sed 's/,/ /g')
do
echo "$exclusion" >> .sprocket.yml
done

echo " [***] Exclusions [***]"
cat .sprocket.yml
fi

exclusions=${INPUT_PATTERNS}
EXITCODE=0

if [ -n "$exclusions" ]; then
echo "Exclusions provided. Writing to .sprocket.yml."
echo -n "" > .sprocket.yml
for exclusion in $(echo $exclusions | sed 's/,/ /g')
echo "Checking WDL files using \`sprocket check\`."
for file in $(find $GITHUB_WORKSPACE -name "*.wdl")
do
echo "$exclusion" >> .sprocket.yml
if [ -e ".sprocket.yml" ]
then
if [ $(echo $file | grep -cvf .sprocket.yml) -eq 0 ]
then
echo " [***] Excluding $file [***]"
continue
fi
fi
echo " [***] $file [***]"
echo "sprocket check --single-document $lint $warnings $notes $exceptions $file"
sprocket check --single-document $lint $warnings $notes $exceptions $file || EXITCODE=$(($? || EXITCODE))
done

echo " [***] Exclusions [***]"
cat .sprocket.yml
fi

EXITCODE=0
echo "status=$EXITCODE" >> $GITHUB_OUTPUT
exit $EXITCODE
elif [ $INPUT_ACTION = "validate-inputs" ]; then
echo "Validating inputs"

echo "Checking WDL files using \`sprocket check\`."
for file in $(find $GITHUB_WORKSPACE -name "*.wdl")
do
if [ -e ".sprocket.yml" ]
then
if [ $(echo $file | grep -cvf .sprocket.yml) -eq 0 ]
then
echo " [***] Excluding $file [***]"
continue
fi
fi
echo " [***] $file [***]"
echo "sprocket check --single-document $lint $warnings $notes $exceptions $file"
sprocket check --single-document $lint $warnings $notes $exceptions $file || EXITCODE=$(($? || EXITCODE))
done
EXITCODE=0

# Split the input variables on "," to get the list of files.
# IFS treats each character as a delimiter.
IFS=',' read -r -a input_files <<< "$INPUT_INPUTS_FILES"
IFS=',' read -r -a wdl_files <<< "$INPUT_WDL_FILES"

# Note: this depends on the user to get the pairing correct upfront.
for index in "${!input_files[@]}"
do
echo "sprocket validate-inputs --inputs ${input_files[index]} ${wdl_files[index]}"
sprocket validate-inputs --inputs "${input_files[index]}" "${wdl_files[index]}" || EXITCODE=$(($? || EXITCODE))
done

echo "status=$EXITCODE" >> $GITHUB_OUTPUT
exit $EXITCODE
elif [ $INPUT_ACTION = "format" ]; then
echo "Format is currently unsupported."
exit 1
elif [ $INPUT_ACTION = "analyzer" ]; then
echo "Action `analyzer` is unsupported."
exit 1
elif [ $INPUT_ACTION = "explain" ]; then
echo "Action `explain` is unsupported."
exit 1
else
echo "Invalid action. Exiting."
exit 1
fi

echo "status=$EXITCODE" >> $GITHUB_OUTPUT
exit $EXITCODE

0 comments on commit ae50c53

Please sign in to comment.